Skip to content

Commit

Permalink
refactor(frontend): App index route (mainly file explorer) (#5287)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape authored Nov 27, 2024
1 parent 9a96e9f commit 5d36612
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { renderWithProviders } from "test-utils";
import { describe, it, expect, vi, Mock, afterEach } from "vitest";
import toast from "#/utils/toast";
import AgentState from "#/types/agent-state";
import FileExplorer from "#/components/file-explorer/file-explorer";
import { FileExplorer } from "#/routes/_oh.app._index/file-explorer/file-explorer";
import OpenHands from "#/api/open-hands";

const toastSpy = vi.spyOn(toast, "error");
Expand Down
307 changes: 0 additions & 307 deletions frontend/src/components/file-explorer/file-explorer.tsx

This file was deleted.

43 changes: 43 additions & 0 deletions frontend/src/hooks/query/use-vscode-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useQuery } from "@tanstack/react-query";
import React from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import toast from "#/utils/toast";
import { addAssistantMessage } from "#/state/chat-slice";
import { I18nKey } from "#/i18n/declaration";
import OpenHands from "#/api/open-hands";

export const useVSCodeUrl = () => {
const { t } = useTranslation();
const dispatch = useDispatch();

const data = useQuery({
queryKey: ["vscode_url"],
queryFn: OpenHands.getVSCodeUrl,
enabled: false,
});

const { data: vscodeUrlObject, isFetching } = data;

React.useEffect(() => {
if (isFetching) return;

if (vscodeUrlObject?.vscode_url) {
dispatch(
addAssistantMessage(
"You opened VS Code. Please inform the agent of any changes you made to the workspace or environment. To avoid conflicts, it's best to pause the agent before making any changes.",
),
);
window.open(vscodeUrlObject.vscode_url, "_blank");
} else if (vscodeUrlObject?.error) {
toast.error(
`open-vscode-error-${new Date().getTime()}`,
t(I18nKey.EXPLORER$VSCODE_SWITCHING_ERROR_MESSAGE, {
error: vscodeUrlObject.error,
}),
);
}
}, [vscodeUrlObject, isFetching]);

return data;
};
11 changes: 11 additions & 0 deletions frontend/src/routes/_oh.app._index/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const ASSET_FILE_TYPES = [
".png",
".jpg",
".jpeg",
".bmp",
".gif",
".pdf",
".mp4",
".webm",
".ogg",
];
Loading

0 comments on commit 5d36612

Please sign in to comment.