gts support

This commit is contained in:
yoan
2024-10-23 13:22:17 +08:00
parent bff18a7be7
commit 8bec234fe8
9 changed files with 447 additions and 167 deletions

View File

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

View File

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