refactor(ui): refactor accesses state using zustand store

This commit is contained in:
Fu Diwei
2024-12-11 19:55:50 +08:00
parent b744363736
commit bb3009a124
48 changed files with 359 additions and 404 deletions

View File

@@ -1,13 +1,13 @@
import { ReactNode, useContext, createContext, useEffect, useReducer, useCallback } from "react";
import { NotifyChannel, NotifyChannels, Settings } from "@/domain/settings";
import { NotifyChannel, NotifyChannels, SettingsModel } from "@/domain/settings";
import { get } from "@/repository/settings";
import { notifyReducer } from "./reducer";
export type NotifyContext = {
config: Settings<NotifyChannels>;
config: SettingsModel<NotifyChannels>;
setChannel: (data: { channel: string; data: NotifyChannel }) => void;
setChannels: (data: Settings<NotifyChannels>) => void;
setChannels: (data: SettingsModel<NotifyChannels>) => void;
initChannels: () => void;
};
@@ -45,7 +45,7 @@ export const NotifyProvider = ({ children }: NotifyProviderProps) => {
});
}, []);
const setChannels = useCallback((setting: Settings<NotifyChannels>) => {
const setChannels = useCallback((setting: SettingsModel<NotifyChannels>) => {
dispatchNotify({
type: "SET_CHANNELS",
payload: setting,

View File

@@ -1,4 +1,4 @@
import { NotifyChannel, NotifyChannels, Settings } from "@/domain/settings";
import { NotifyChannel, NotifyChannels, SettingsModel } from "@/domain/settings";
type Action =
| {
@@ -10,10 +10,10 @@ type Action =
}
| {
type: "SET_CHANNELS";
payload: Settings<NotifyChannels>;
payload: SettingsModel<NotifyChannels>;
};
export const notifyReducer = (state: Settings<NotifyChannels>, action: Action) => {
export const notifyReducer = (state: SettingsModel<NotifyChannels>, action: Action) => {
switch (action.type) {
case "SET_CHANNEL": {
const channel = action.payload.channel;