refactor(ui): refactor emails state using zustand store

This commit is contained in:
Fu Diwei
2024-12-11 16:42:23 +08:00
parent 83ba3d4450
commit b744363736
21 changed files with 141 additions and 166 deletions

View File

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

View File

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