refactor: add typescript support to project
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import localforage from "localforage";
|
||||
import useRehydrate from "./useRehydrate";
|
||||
import { KEY_UID, CACHE_VERSION } from "../config";
|
||||
|
||||
const tables = [
|
||||
{
|
||||
storeName: "channels",
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { useDispatch, batch } from "react-redux";
|
||||
import { fullfillReactionMessage } from "../slices/message.reaction";
|
||||
import { fullfillServer } from "../slices/server";
|
||||
@@ -11,6 +10,7 @@ import { fullfillContacts } from "../slices/contacts";
|
||||
import { fullfillFootprint } from "../slices/footprint";
|
||||
import { fullfillFileMessage } from "../slices/message.file";
|
||||
import { fullfillUI } from "../slices/ui";
|
||||
|
||||
const useRehydrate = () => {
|
||||
const [iterated, setIterated] = useState(false);
|
||||
const dispatch = useDispatch();
|
||||
@@ -94,4 +94,5 @@ const useRehydrate = () => {
|
||||
};
|
||||
return { rehydrate, rehydrated: iterated };
|
||||
};
|
||||
|
||||
export default useRehydrate;
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
const clearTable = async (table) => {
|
||||
const clearTable = async (table: string) => {
|
||||
const t = window.CACHE[table];
|
||||
if (!t) return;
|
||||
|
||||
@@ -6,4 +6,5 @@ const clearTable = async (table) => {
|
||||
t.removeItem(key);
|
||||
});
|
||||
};
|
||||
|
||||
export default clearTable;
|
||||
+11
-1
@@ -1,5 +1,15 @@
|
||||
import clearTable from "./clear.handler";
|
||||
export default async function handler({ operation, data = {}, payload }) {
|
||||
|
||||
// todo
|
||||
export type BaseOperation = "add" | "remove" | "reset";
|
||||
|
||||
export interface Params {
|
||||
operation: string;
|
||||
data: {};
|
||||
payload: {};
|
||||
}
|
||||
|
||||
export default async function handler({ operation, data = {}, payload }: Params) {
|
||||
const table = window.CACHE["messageChannel"];
|
||||
if (operation.startsWith("reset")) {
|
||||
clearTable("messageChannel");
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data, payload }) {
|
||||
const table = window.CACHE["channels"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data, payload }) {
|
||||
const table = window.CACHE["contacts"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data = {}, payload }) {
|
||||
const table = window.CACHE["messageDM"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data = {} }) {
|
||||
const table = window.CACHE["messageFile"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data = {}, payload }) {
|
||||
const table = window.CACHE["footprint"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data = {}, payload }) {
|
||||
const table = window.CACHE["message"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data = {}, payload }) {
|
||||
const table = window.CACHE["messageReaction"];
|
||||
if (operation.startsWith("reset")) {
|
||||
+8
-2
@@ -1,6 +1,12 @@
|
||||
// import clearTable from "./clear.handler";
|
||||
import { updateOnline } from "../slices/ui";
|
||||
export default async function handler({ dispatch, operation }) {
|
||||
import { AppDispatch } from "../store";
|
||||
|
||||
interface Params {
|
||||
dispatch: AppDispatch;
|
||||
operation: string;
|
||||
}
|
||||
|
||||
export default async function handler({ dispatch, operation }: Params) {
|
||||
switch (operation) {
|
||||
case "offline":
|
||||
{
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, payload }) {
|
||||
const table = window.CACHE["server"];
|
||||
if (operation.startsWith("reset")) {
|
||||
@@ -1,4 +1,5 @@
|
||||
import clearTable from "./clear.handler";
|
||||
|
||||
export default async function handler({ operation, data = {} }) {
|
||||
const table = window.CACHE["ui"];
|
||||
if (operation.startsWith("reset")) {
|
||||
@@ -10,6 +10,7 @@ import fileMessageHandler from "./handler.file.msg";
|
||||
import reactionHandler from "./handler.reaction";
|
||||
import UIHandler from "./handler.ui";
|
||||
import footprintHandler from "./handler.footprint";
|
||||
|
||||
const operations = [
|
||||
"__rtkq",
|
||||
"channels",
|
||||
@@ -4,6 +4,7 @@ import { ContentTypes } from "../config";
|
||||
import { addChannelMsg, removeChannelMsg } from "../slices/message.channel";
|
||||
import { addUserMsg, removeUserMsg } from "../slices/message.user";
|
||||
import { addMessage, removeMessage } from "../slices/message";
|
||||
|
||||
export const onMessageSendStarted = async (
|
||||
{
|
||||
ignoreLocal = false,
|
||||
@@ -2,7 +2,9 @@ import { createApi } from "@reduxjs/toolkit/query/react";
|
||||
import BASE_URL from "../config";
|
||||
import { updateInfo } from "../slices/server";
|
||||
import baseQuery from "./base.query";
|
||||
|
||||
const defaultExpireDuration = 7 * 24 * 60 * 60;
|
||||
|
||||
export const serverApi = createApi({
|
||||
reducerPath: "serverApi",
|
||||
baseQuery,
|
||||
Reference in New Issue
Block a user