27
package-lock.json
generated
27
package-lock.json
generated
@@ -32,6 +32,7 @@
|
|||||||
"@rollup/plugin-commonjs": "^28.0.3",
|
"@rollup/plugin-commonjs": "^28.0.3",
|
||||||
"@tailwindcss/typography": "^0.5.16",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
"@tailwindcss/vite": "^4.1.3",
|
"@tailwindcss/vite": "^4.1.3",
|
||||||
|
"@tanstack/react-query": "^5.75.5",
|
||||||
"@tanstack/react-router": "^1.114.34",
|
"@tanstack/react-router": "^1.114.34",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
@@ -5361,6 +5362,32 @@
|
|||||||
"url": "https://github.com/sponsors/tannerlinsley"
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tanstack/query-core": {
|
||||||
|
"version": "5.75.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.75.5.tgz",
|
||||||
|
"integrity": "sha512-kPDOxtoMn2Ycycb76Givx2fi+2pzo98F9ifHL/NFiahEDpDwSVW6o12PRuQ0lQnBOunhRG5etatAhQij91M3MQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tanstack/react-query": {
|
||||||
|
"version": "5.75.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.75.5.tgz",
|
||||||
|
"integrity": "sha512-QrLCJe40BgBVlWdAdf2ZEVJ0cISOuEy/HKupId1aTKU6gPJZVhSvZpH+Si7csRflCJphzlQ77Yx6gUxGW9o0XQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@tanstack/query-core": "5.75.5"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^18 || ^19"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@tanstack/react-router": {
|
"node_modules/@tanstack/react-router": {
|
||||||
"version": "1.119.0",
|
"version": "1.119.0",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/react-router/-/react-router-1.119.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/react-router/-/react-router-1.119.0.tgz",
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
"@rollup/plugin-commonjs": "^28.0.3",
|
"@rollup/plugin-commonjs": "^28.0.3",
|
||||||
"@tailwindcss/typography": "^0.5.16",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
"@tailwindcss/vite": "^4.1.3",
|
"@tailwindcss/vite": "^4.1.3",
|
||||||
|
"@tanstack/react-query": "^5.75.5",
|
||||||
"@tanstack/react-router": "^1.114.34",
|
"@tanstack/react-router": "^1.114.34",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
|
|||||||
@@ -21,17 +21,20 @@ export function VersionPane({ isVisible, onClose }: VersionPaneProps) {
|
|||||||
selectedVersionIdAtom,
|
selectedVersionIdAtom,
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
async function updateVersions() {
|
||||||
// Refresh versions in case the user updated versions outside of the app
|
// Refresh versions in case the user updated versions outside of the app
|
||||||
// (e.g. manually using git).
|
// (e.g. manually using git).
|
||||||
// Avoid loading state which causes brief flash of loading state.
|
// Avoid loading state which causes brief flash of loading state.
|
||||||
refreshVersions();
|
|
||||||
if (!isVisible && selectedVersionId) {
|
if (!isVisible && selectedVersionId) {
|
||||||
setSelectedVersionId(null);
|
setSelectedVersionId(null);
|
||||||
IpcClient.getInstance().checkoutVersion({
|
await IpcClient.getInstance().checkoutVersion({
|
||||||
appId: appId!,
|
appId: appId!,
|
||||||
versionId: "main",
|
versionId: "main",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
refreshVersions();
|
||||||
|
}
|
||||||
|
updateVersions();
|
||||||
}, [isVisible, refreshVersions]);
|
}, [isVisible, refreshVersions]);
|
||||||
if (!isVisible) {
|
if (!isVisible) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,78 +1,79 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
import { useAtom, useAtomValue } from "jotai";
|
import { useAtom, useAtomValue } from "jotai";
|
||||||
import { versionsListAtom } from "@/atoms/appAtoms";
|
import { versionsListAtom } from "@/atoms/appAtoms";
|
||||||
import { IpcClient } from "@/ipc/ipc_client";
|
import { IpcClient } from "@/ipc/ipc_client";
|
||||||
import { showError } from "@/lib/toast";
|
import { showError } from "@/lib/toast";
|
||||||
import { chatMessagesAtom, selectedChatIdAtom } from "@/atoms/chatAtoms";
|
import { chatMessagesAtom, selectedChatIdAtom } from "@/atoms/chatAtoms";
|
||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { Version } from "@/ipc/ipc_types";
|
||||||
|
|
||||||
export function useVersions(appId: number | null) {
|
export function useVersions(appId: number | null) {
|
||||||
const [versions, setVersions] = useAtom(versionsListAtom);
|
const [, setVersionsAtom] = useAtom(versionsListAtom);
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState<Error | null>(null);
|
|
||||||
const selectedChatId = useAtomValue(selectedChatIdAtom);
|
const selectedChatId = useAtomValue(selectedChatIdAtom);
|
||||||
const [, setMessages] = useAtom(chatMessagesAtom);
|
const [, setMessages] = useAtom(chatMessagesAtom);
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: versions,
|
||||||
|
isLoading: loading,
|
||||||
|
error,
|
||||||
|
refetch: refreshVersions,
|
||||||
|
} = useQuery<Version[], Error>({
|
||||||
|
queryKey: ["versions", appId],
|
||||||
|
queryFn: async (): Promise<Version[]> => {
|
||||||
|
if (appId === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const ipcClient = IpcClient.getInstance();
|
||||||
|
return ipcClient.listVersions({ appId });
|
||||||
|
},
|
||||||
|
enabled: appId !== null,
|
||||||
|
initialData: [],
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadVersions = async () => {
|
if (versions) {
|
||||||
// If no app is selected, clear versions and return
|
setVersionsAtom(versions);
|
||||||
|
}
|
||||||
|
}, [versions, setVersionsAtom]);
|
||||||
|
|
||||||
|
const revertVersionMutation = useMutation<void, Error, { versionId: string }>(
|
||||||
|
{
|
||||||
|
mutationFn: async ({ versionId }: { versionId: string }) => {
|
||||||
if (appId === null) {
|
if (appId === null) {
|
||||||
setVersions([]);
|
throw new Error("App ID is null");
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const ipcClient = IpcClient.getInstance();
|
const ipcClient = IpcClient.getInstance();
|
||||||
const versionsList = await ipcClient.listVersions({ appId });
|
await ipcClient.revertVersion({ appId, previousVersionId: versionId });
|
||||||
|
},
|
||||||
setVersions(versionsList);
|
onSuccess: async () => {
|
||||||
setError(null);
|
await queryClient.invalidateQueries({ queryKey: ["versions", appId] });
|
||||||
} catch (error) {
|
if (selectedChatId) {
|
||||||
console.error("Error loading versions:", error);
|
const chat = await IpcClient.getInstance().getChat(selectedChatId);
|
||||||
setError(error instanceof Error ? error : new Error(String(error)));
|
setMessages(chat.messages);
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
onError: (e: Error) => {
|
||||||
loadVersions();
|
showError(e);
|
||||||
}, [appId, setVersions]);
|
},
|
||||||
|
},
|
||||||
const refreshVersions = useCallback(async () => {
|
);
|
||||||
if (appId === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const ipcClient = IpcClient.getInstance();
|
|
||||||
const versionsList = await ipcClient.listVersions({ appId });
|
|
||||||
setVersions(versionsList);
|
|
||||||
setError(null);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error refreshing versions:", error);
|
|
||||||
setError(error instanceof Error ? error : new Error(String(error)));
|
|
||||||
}
|
|
||||||
}, [appId, setVersions, setError]);
|
|
||||||
|
|
||||||
const revertVersion = useCallback(
|
const revertVersion = useCallback(
|
||||||
async ({ versionId }: { versionId: string }) => {
|
async ({ versionId }: { versionId: string }) => {
|
||||||
if (appId === null) {
|
if (appId === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await revertVersionMutation.mutateAsync({ versionId });
|
||||||
try {
|
|
||||||
const ipcClient = IpcClient.getInstance();
|
|
||||||
await ipcClient.revertVersion({ appId, previousVersionId: versionId });
|
|
||||||
await refreshVersions();
|
|
||||||
if (selectedChatId) {
|
|
||||||
const chat = await IpcClient.getInstance().getChat(selectedChatId);
|
|
||||||
setMessages(chat.messages);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
showError(error);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[appId, setVersions, setError, selectedChatId, setMessages],
|
[appId, revertVersionMutation],
|
||||||
);
|
);
|
||||||
|
|
||||||
return { versions, loading, error, refreshVersions, revertVersion };
|
return {
|
||||||
|
versions: versions || [],
|
||||||
|
loading,
|
||||||
|
error,
|
||||||
|
refreshVersions,
|
||||||
|
revertVersion,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,13 @@ import { RouterProvider } from "@tanstack/react-router";
|
|||||||
import { PostHogProvider } from "posthog-js/react";
|
import { PostHogProvider } from "posthog-js/react";
|
||||||
import posthog from "posthog-js";
|
import posthog from "posthog-js";
|
||||||
import { getTelemetryUserId, isTelemetryOptedIn } from "./hooks/useSettings";
|
import { getTelemetryUserId, isTelemetryOptedIn } from "./hooks/useSettings";
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
console.log("Running in mode:", import.meta.env.MODE);
|
console.log("Running in mode:", import.meta.env.MODE);
|
||||||
|
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
const posthogClient = posthog.init(
|
const posthogClient = posthog.init(
|
||||||
"phc_5Vxx0XT8Ug3eWROhP6mm4D6D2DgIIKT232q4AKxC2ab",
|
"phc_5Vxx0XT8Ug3eWROhP6mm4D6D2DgIIKT232q4AKxC2ab",
|
||||||
{
|
{
|
||||||
@@ -71,8 +74,10 @@ function App() {
|
|||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
<PostHogProvider client={posthogClient}>
|
<PostHogProvider client={posthogClient}>
|
||||||
<App />
|
<App />
|
||||||
</PostHogProvider>
|
</PostHogProvider>
|
||||||
|
</QueryClientProvider>
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user