-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cbf5dd
commit 485bd03
Showing
21 changed files
with
245 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import { View } from "react-native"; | ||
|
||
import { Text } from "@/components/ui/Text"; | ||
import { ActionList } from "@/hooks/useAction"; | ||
import { ActionList } from "@/hooks/actions"; | ||
|
||
export function CommandTray({ input }: { input: string }) { | ||
if (!input.startsWith("/")) return null; | ||
return ( | ||
<View className="flex flex-row items-center justify-between w-full py-2 pl-2 pr-2 web:pr-10"> | ||
<CommandList input={input} /> | ||
</View> | ||
); | ||
if (!input.startsWith("/")) return null; | ||
return ( | ||
<View className="flex flex-row items-center justify-between w-full py-2 pl-2 pr-2 web:pr-10"> | ||
<CommandList input={input} /> | ||
</View> | ||
); | ||
} | ||
|
||
function CommandList({ input }: { input: string }) { | ||
const command = input.slice(1); | ||
const possibleCommands = command | ||
? ActionList.filter((c) => c.startsWith(command)) | ||
: ActionList; | ||
const command = input.slice(1); | ||
const possibleCommands = command | ||
? ActionList.filter((c) => c.startsWith(command)) | ||
: ActionList; | ||
|
||
return ( | ||
<View> | ||
{possibleCommands.map((command) => ( | ||
<CommandItem key={command} command={command} /> | ||
))} | ||
</View> | ||
); | ||
return ( | ||
<View> | ||
{possibleCommands.map((command) => ( | ||
<CommandItem key={command} command={command} /> | ||
))} | ||
</View> | ||
); | ||
} | ||
|
||
function CommandItem({ command }: { command: string }) { | ||
return <Text>{command}</Text>; | ||
return <Text>{command}</Text>; | ||
} |
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,31 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { fetcher } from "@/lib/fetcher"; | ||
import { useUserData } from "../stores/useUserData"; | ||
import { useDeleteThreadMutation } from "../fetchers/Thread/useDeleteThreadMutation"; | ||
import { useDeleteAllThreadsMutation } from "../fetchers/Thread/useDeleteAllThreadsMutation"; | ||
|
||
export function useDeleteActiveThread() { | ||
const { mutateAsync } = useDeleteThreadMutation(); | ||
const action = async (threadId: string) => mutateAsync(threadId); | ||
return { action }; | ||
} | ||
|
||
export function useDeleteAllThreads() { | ||
const { mutateAsync } = useDeleteAllThreadsMutation(); | ||
const action = async () => mutateAsync(); | ||
return { action }; | ||
} | ||
|
||
/** Reset the Server DB to empty. */ | ||
export function useResetDb() { | ||
const queryClient = useQueryClient(); | ||
const apiKey = useUserData((s) => s.apiKey); | ||
|
||
const action = async () => { | ||
await fetcher("/reset", { apiKey }); | ||
queryClient.invalidateQueries(); | ||
}; | ||
|
||
return { action }; | ||
} |
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,10 @@ | ||
import * as actionFunctions from "./actions"; | ||
export * from "./actions"; | ||
|
||
const Actions = actionFunctions; | ||
|
||
export type ActionMap = typeof Actions; | ||
export type Command = keyof ActionMap; | ||
export type UIAction = ReturnType<ActionMap[keyof ActionMap]>; | ||
|
||
export const ActionList: Command[] = Object.keys(Actions) as Command[]; |
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
42 changes: 42 additions & 0 deletions
42
client/src/hooks/fetchers/Thread/useDeleteAllThreadsMutation.ts
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,42 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
|
||
import { fetcher } from "@/lib/fetcher"; | ||
import { threadListQueryOptions } from "./useThreadListQuery"; | ||
import { useUserData } from "../../stores/useUserData"; | ||
import { useConfigStore } from "@/hooks/stores/configStore"; | ||
|
||
const deleteThread = (apiKey: string) => | ||
fetcher(`/threads/`, { | ||
apiKey, | ||
method: "DELETE", | ||
stream: true, | ||
}); | ||
|
||
export function useDeleteAllThreadsMutation() { | ||
const apiKey = useUserData.use.apiKey(); | ||
const setThreadId = useConfigStore.use.setThreadId(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ["deleteAllThreads"], | ||
mutationFn: () => deleteThread(apiKey), | ||
onMutate: async () => { | ||
const listQuery = threadListQueryOptions(apiKey); | ||
setThreadId(null); | ||
await queryClient.cancelQueries(); | ||
const cached = queryClient.getQueryData(listQuery.queryKey); | ||
|
||
queryClient.setQueryData(listQuery.queryKey, []); | ||
return { cached }; | ||
}, | ||
onSuccess: async () => queryClient.invalidateQueries(), | ||
onError: async (error, _, ctx) => { | ||
console.error("Failed to delete threads: " + error); | ||
queryClient.setQueryData( | ||
threadListQueryOptions(apiKey).queryKey, | ||
ctx?.cached | ||
); | ||
await queryClient.invalidateQueries(); | ||
}, | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.