Skip to content

Commit d0917da

Browse files
committed
Fix file explorer
1 parent 33c4c2a commit d0917da

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

src/main/SessionProxy.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ export default class SessionProxy {
4343
return this.#remoteExtension.getPermissions();
4444
}
4545

46+
getDirectoryContents(path: string) {
47+
return this.#remoteSession.getDirectoryContents(path);
48+
}
49+
50+
changeFileSystemCursor(selectedPath: string, key: KeyboardEvent["key"]) {
51+
return this.#remoteSession.changeFileSystemCursor(selectedPath, key);
52+
}
53+
4654
async dispose() {
4755
this.#remoteSession.free();
4856
this.#remoteSession[releaseProxy]();
57+
this.#remoteExtension[releaseProxy]();
4958
}
5059
}

src/main/ui/file-explorer/FileExplorer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { FunctionComponent } from "preact";
22
import type { FSNodeDTO } from "../../../extension/FileSystem";
3+
import type SessionProxy from "../../SessionProxy";
34

45
import { useState } from "preact/hooks";
56

@@ -11,10 +12,10 @@ import "./file-explorer.css";
1112
import SelectedFSNodeContext from "../contexts/SelectedFSNodeContext";
1213

1314
type ExplorerProps = {
14-
extensionId: string;
15+
session: SessionProxy;
1516
};
1617

17-
const FileExplorer: FunctionComponent<ExplorerProps> = ({ extensionId }) => {
18+
const FileExplorer: FunctionComponent<ExplorerProps> = ({ session }) => {
1819
const [previewFile, setPreviewFile] = useState<FileNodeDTO | undefined>(undefined);
1920
const [selectedFSNode, setSelectedFSNode] = useState<string | undefined>(undefined);
2021

@@ -24,7 +25,7 @@ const FileExplorer: FunctionComponent<ExplorerProps> = ({ extensionId }) => {
2425
};
2526

2627
return (
27-
<SessionContext.Provider value={extensionId}>
28+
<SessionContext.Provider value={session}>
2829
<SelectedFSNodeContext.Provider value={selectedFSNode}>
2930
<div class="file-explorer">
3031
<FolderContentView

src/main/ui/file-explorer/FolderContentView.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ const FolderContentView: FunctionComponent<FCVProps> = ({
2121
showFilePreview,
2222
selectFSNode
2323
}) => {
24-
const extId = useContext(SessionContext)!;
24+
const session = useContext(SessionContext)!;
2525
const selectedPath = useContext(SelectedFSNodeContext);
2626
const [contents, setContents] = useState<FSNodeDTO[] | undefined>(undefined);
2727
const ulRef = useRef<HTMLUListElement>(null);
2828

2929
const isRoot = path === "/" || path === "";
3030

3131
useEffect(() => {
32-
wrappedWorker.getDirectoryContents(extId, path).then(setContents, (e) => console.error(e));
33-
}, [extId, path]);
32+
session.getDirectoryContents(path).then(setContents, (e) => console.error(e));
33+
}, [session, path]);
3434

3535
if (contents === undefined) {
3636
return <span class="folder-content">...</span>;
@@ -47,7 +47,7 @@ const FolderContentView: FunctionComponent<FCVProps> = ({
4747
return;
4848
}
4949
e.preventDefault();
50-
const next = await wrappedWorker.changeFileSystemCursor(extId, selectedPath, e.key);
50+
const next = await session.changeFileSystemCursor(selectedPath, e.key);
5151
selectFSNode(next);
5252
};
5353

@@ -103,7 +103,7 @@ const FileView: FunctionComponent<{ node: FileDTO }> = ({ node }) => {
103103
document.getElementById(labelId)!.focus();
104104
scrollIntoViewIfNeeded(liRef.current!);
105105
}
106-
}, [selected, liRef.current, labelId]);
106+
}, [selected, labelId]);
107107

108108
return (
109109
<li
@@ -141,7 +141,7 @@ const FolderView: FunctionComponent<{ node: FolderDTO; selectFSNode?: FSNodeSele
141141
liRef.current!.querySelector("summary")!.focus();
142142
scrollIntoViewIfNeeded(liRef.current!);
143143
}
144-
}, [selected, liRef.current]);
144+
}, [selected]);
145145

146146
useEffect(() => {
147147
if (expanded || !selectedPath || !selectFSNode) {

src/main/ui/tiles/FilesTile.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { FunctionComponent } from "preact";
2-
import type { ExtensionData } from "../../../extension/types/ExtensionData";
2+
import type { ExtensionSummary } from "../../../extension/types/ExtensionSummary";
3+
import type SessionProxy from "../../SessionProxy";
34

45
import DonutChart from "../common/DonutChart";
56
import FileExplorer from "../file-explorer/FileExplorer";
@@ -16,7 +17,7 @@ const mappings: Record<FileType, { label: string; color: string }> = {
1617
// WASM: rgb(101, 78, 240)
1718
};
1819

19-
const FilesTile: FunctionComponent<ExtensionData["files"]> = (data) => {
20+
const FilesTile: FunctionComponent<ExtensionSummary["files"]> = (data) => {
2021
const chartData = Object.entries(mappings).map(([key, props]) => ({
2122
amount: data[key as FileType],
2223
color: props.color
@@ -46,11 +47,11 @@ const FilesTile: FunctionComponent<ExtensionData["files"]> = (data) => {
4647

4748
export default FilesTile;
4849

49-
function createFileExplorerPopupOptions(extensionId: string) {
50+
function createFileExplorerPopupOptions(session: SessionProxy) {
5051
return {
5152
title: "File Explorer",
5253
icon: "file-explorer",
53-
content: <FileExplorer extensionId={extensionId} />,
54+
content: <FileExplorer session={session} />,
5455
initialWidth: 700,
5556
initialHeight: 500
5657
};
@@ -60,4 +61,4 @@ const ChartColorIndicator: FunctionComponent<{ color: string }> = ({ color }) =>
6061
<span class="chart-color-indicator" style={`background-color: ${color}`} />
6162
);
6263

63-
type FileType = keyof ExtensionData["files"];
64+
type FileType = keyof ExtensionSummary["files"];

0 commit comments

Comments
 (0)