-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Multiple send message method
- Loading branch information
1 parent
272f9d4
commit 59a2686
Showing
13 changed files
with
264 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as React from "react"; | ||
import { create } from "zustand"; | ||
|
||
export interface IConfigStoreState { | ||
sendMessageType: "Enter" | "CommandEnter"; | ||
} | ||
|
||
interface IConfigStoreAction { | ||
update: (args: SaveConfig) => void; | ||
} | ||
|
||
type SaveConfig = | ||
| IConfigStoreState | ||
| ((prev: IConfigStoreState) => IConfigStoreState); | ||
|
||
type UseConfigReturn = [IConfigStoreState, (args: SaveConfig) => void]; | ||
|
||
const useStore = create<IConfigStoreState & IConfigStoreAction>((set) => ({ | ||
sendMessageType: "Enter", | ||
|
||
update: (args: SaveConfig) => { | ||
if (typeof args === "function") { | ||
set((state) => { | ||
const newState = JSON.parse(JSON.stringify(state)); | ||
const { sendMessageType } = args(newState); | ||
localStorage.setItem("sendMessageType", sendMessageType); | ||
return newState; | ||
}); | ||
} else { | ||
const { sendMessageType } = args; | ||
localStorage.setItem("sendMessageType", sendMessageType); | ||
set(() => ({ sendMessageType })); | ||
} | ||
}, | ||
})); | ||
|
||
export const useConfig = (): UseConfigReturn => { | ||
const { sendMessageType } = useStore(); | ||
|
||
const update = useStore((state) => state.update); | ||
|
||
React.useEffect(() => { | ||
const localSendMessageType = | ||
localStorage.getItem("sendMessageType") || "Enter"; | ||
|
||
update({ | ||
sendMessageType: | ||
localSendMessageType as IConfigStoreState["sendMessageType"], | ||
}); | ||
}, []); | ||
|
||
return [{ sendMessageType }, update]; | ||
}; |
Oops, something went wrong.
59a2686
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
l-gpt – ./
l-gpt.vercel.app
l-gpt-peek-a-booo-s-team.vercel.app
gpt.ltopx.com
l-gpt-git-main-peek-a-booo-s-team.vercel.app