feat: remember UI state
This commit is contained in:
Vendored
+4
@@ -34,6 +34,10 @@ const tables = [
|
||||
storeName: "server",
|
||||
description: "store server data",
|
||||
},
|
||||
{
|
||||
storeName: "ui",
|
||||
description: "store UI state",
|
||||
},
|
||||
// {
|
||||
// storeName: "message",
|
||||
// description: "store message with key-val full data",
|
||||
|
||||
Vendored
+6
@@ -9,6 +9,7 @@ import { fullfillUserMsg } from "../slices/message.user";
|
||||
import { fullfillChannels } from "../slices/channels";
|
||||
import { fullfillContacts } from "../slices/contacts";
|
||||
import { fullfillFootprint } from "../slices/footprint";
|
||||
import { fullfillUI } from "../slices/ui";
|
||||
const useRehydrate = () => {
|
||||
const [iterated, setIterated] = useState(false);
|
||||
const dispatch = useDispatch();
|
||||
@@ -21,6 +22,7 @@ const useRehydrate = () => {
|
||||
reactionMessage: {},
|
||||
message: { replying: {} },
|
||||
footprint: {},
|
||||
ui: {},
|
||||
server: {},
|
||||
};
|
||||
const tables = Object.keys(window.CACHE);
|
||||
@@ -42,6 +44,9 @@ const useRehydrate = () => {
|
||||
case "footprint":
|
||||
rehydrateData.footprint[key] = data;
|
||||
break;
|
||||
case "ui":
|
||||
rehydrateData.ui[key] = data;
|
||||
break;
|
||||
case "messageChannel":
|
||||
rehydrateData.channelMessage[key] = data;
|
||||
break;
|
||||
@@ -73,6 +78,7 @@ const useRehydrate = () => {
|
||||
dispatch(fullfillUserMsg(rehydrateData.userMessage));
|
||||
dispatch(fullfillMessage(rehydrateData.message));
|
||||
dispatch(fullfillFootprint(rehydrateData.footprint));
|
||||
dispatch(fullfillUI(rehydrateData.ui));
|
||||
dispatch(fullfillReactionMessage(rehydrateData.reactionMessage));
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import clearTable from "./clear.handler";
|
||||
export default async function handler({ operation, data = {} }) {
|
||||
const table = window.CACHE["ui"];
|
||||
if (operation.startsWith("reset")) {
|
||||
clearTable("ui");
|
||||
return;
|
||||
}
|
||||
switch (operation) {
|
||||
case "toggleMenuExpand":
|
||||
{
|
||||
console.log("cache the toggleMenuExpand");
|
||||
await table.setItem("menuExpand", data.menuExpand);
|
||||
}
|
||||
break;
|
||||
case "updateInputMode":
|
||||
{
|
||||
await table.setItem("inputMode", data.inputMode);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import dmMsgHandler from "./handler.dm.msg";
|
||||
import serverHandler from "./handler.server";
|
||||
import messageHandler from "./handler.message";
|
||||
import reactionHandler from "./handler.reaction";
|
||||
import UIHandler from "./handler.ui";
|
||||
import footprintHandler from "./handler.footprint";
|
||||
const operations = [
|
||||
"__rtkq",
|
||||
@@ -16,6 +17,7 @@ const operations = [
|
||||
"userMessage",
|
||||
"reactionMessage",
|
||||
"message",
|
||||
"ui",
|
||||
"footprint",
|
||||
"server",
|
||||
];
|
||||
@@ -114,6 +116,15 @@ listenerMiddleware.startListening({
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "ui":
|
||||
{
|
||||
await UIHandler({
|
||||
operation,
|
||||
payload,
|
||||
data: state,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "server":
|
||||
{
|
||||
await serverHandler({
|
||||
|
||||
@@ -18,6 +18,18 @@ export const onMessageSendStarted = async (
|
||||
) => {
|
||||
// id: who send to ,from_uid: who sent
|
||||
const ts = properties.local_id || new Date().getTime();
|
||||
// let imageData = null;
|
||||
// if (type == "image") {
|
||||
// if (typeof content == "string" && content.startsWith("data:image")) {
|
||||
// // base64
|
||||
// // const resp = await fetch(content);
|
||||
// // const blob = await resp.blob();
|
||||
// // imageData = new File([blob], "tmp.png", { type: "image/png" });
|
||||
// imageData = content;
|
||||
// } else {
|
||||
// imageData = URL.createObjectURL(content);
|
||||
// }
|
||||
// }
|
||||
const tmpMsg = {
|
||||
content: type == "image" ? URL.createObjectURL(content) : content,
|
||||
content_type: ContentTypes[type],
|
||||
|
||||
@@ -38,6 +38,26 @@ export const messageApi = createApi({
|
||||
method: "DELETE",
|
||||
}),
|
||||
}),
|
||||
prepareUploadFile: builder.mutation({
|
||||
query: () => ({
|
||||
url: `/resource/file/prepare`,
|
||||
method: "POST",
|
||||
}),
|
||||
}),
|
||||
uploadFile: builder.mutation({
|
||||
query: (formData) => ({
|
||||
// headers: {
|
||||
// "content-type": ContentTypes.formData,
|
||||
// },
|
||||
url: `/resource/file/upload`,
|
||||
method: "POST",
|
||||
body: formData,
|
||||
}),
|
||||
transformResponse: (data) => {
|
||||
console.log("upload file response", data);
|
||||
return data ? data : {};
|
||||
},
|
||||
}),
|
||||
uploadImage: builder.mutation({
|
||||
query: (image) => ({
|
||||
headers: {
|
||||
@@ -102,6 +122,8 @@ export const messageApi = createApi({
|
||||
});
|
||||
|
||||
export const {
|
||||
usePrepareUploadFileMutation,
|
||||
useUploadFileMutation,
|
||||
useUploadImageMutation,
|
||||
useEditMessageMutation,
|
||||
useReactMessageMutation,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createSlice } from "@reduxjs/toolkit";
|
||||
const initialState = {
|
||||
online: true,
|
||||
ready: false,
|
||||
inputMode: "text",
|
||||
menuExpand: false,
|
||||
setting: false,
|
||||
channelSetting: null,
|
||||
@@ -11,6 +12,9 @@ const uiSlice = createSlice({
|
||||
name: "ui",
|
||||
initialState,
|
||||
reducers: {
|
||||
fullfillUI(state, action) {
|
||||
return { ...initialState, ...action.payload };
|
||||
},
|
||||
setReady(state) {
|
||||
state.ready = true;
|
||||
},
|
||||
@@ -20,6 +24,9 @@ const uiSlice = createSlice({
|
||||
toggleMenuExpand(state) {
|
||||
state.menuExpand = !state.menuExpand;
|
||||
},
|
||||
updateInputMode(state, action) {
|
||||
state.inputMode = action.payload;
|
||||
},
|
||||
toggleSetting(state) {
|
||||
state.setting = !state.setting;
|
||||
},
|
||||
@@ -31,8 +38,10 @@ const uiSlice = createSlice({
|
||||
},
|
||||
});
|
||||
export const {
|
||||
fullfillUI,
|
||||
setReady,
|
||||
updateOnline,
|
||||
updateInputMode,
|
||||
toggleSetting,
|
||||
toggleMenuExpand,
|
||||
toggleChannelSetting,
|
||||
|
||||
Reference in New Issue
Block a user