From 182c5f6e3d6a5935c519a2b7b1f68925cbfb78d5 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:53:55 -0700 Subject: [PATCH] Open New Block and Delete Files (#76) This implements the behavior for the context menu recently added to the directories. Open New Block simply opens the file in a preview in a new block. Delete files will delete the selected file, but it does not trigger a rerender at this time. To see the change, you must navigate to a different directory and then return. This will be fixed in a future update. --- frontend/app/store/services.ts | 3 +++ frontend/app/view/directorypreview.tsx | 17 ++++++++++++----- frontend/types/gotypes.d.ts | 4 ++-- pkg/service/fileservice/fileservice.go | 5 +++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/app/store/services.ts b/frontend/app/store/services.ts index 8098d9f24..cd40fb50d 100644 --- a/frontend/app/store/services.ts +++ b/frontend/app/store/services.ts @@ -51,6 +51,9 @@ class FileServiceType { AddWidget(arg1: WidgetsConfigType): Promise { return WOS.callBackendService("file", "AddWidget", Array.from(arguments)) } + DeleteFile(arg1: string): Promise { + return WOS.callBackendService("file", "DeleteFile", Array.from(arguments)) + } GetSettingsConfig(): Promise { return WOS.callBackendService("file", "GetSettingsConfig", Array.from(arguments)) } diff --git a/frontend/app/view/directorypreview.tsx b/frontend/app/view/directorypreview.tsx index 59dfca2b5..ddc1e7f5d 100644 --- a/frontend/app/view/directorypreview.tsx +++ b/frontend/app/view/directorypreview.tsx @@ -1,6 +1,7 @@ // Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import * as services from "@/store/services"; import * as util from "@/util/util"; import { Table, @@ -14,7 +15,7 @@ import clsx from "clsx"; import * as jotai from "jotai"; import React from "react"; import { ContextMenuModel } from "../store/contextmenu"; -import { atoms } from "../store/global"; +import { atoms, createBlock } from "../store/global"; import "./directorypreview.less"; @@ -121,14 +122,18 @@ function handleFileContextMenu(e: React.MouseEvent, path: string let menu: ContextMenuItem[] = []; menu.push({ label: "Open in New Block", - click: () => { - alert("Not Implemented"); + click: async () => { + const blockDef = { + view: "preview", + meta: { file: path }, + }; + await createBlock(blockDef); }, }); menu.push({ label: "Delete File", - click: () => { - alert("Not Implemented"); + click: async () => { + await services.FileService.DeleteFile(path).catch((e) => console.log(e)); //todo these errors need a popup }, }); ContextMenuModel.showContextMenu(menu, e); @@ -262,6 +267,8 @@ interface TableBodyProps { } function TableBody({ table, cwd, setFileName }: TableBodyProps) { + let [refresh, setRefresh] = React.useState(false); + return (
{table.getRowModel().rows.map((row) => ( diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 7d9ea4772..fc1d1b09e 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -288,8 +288,8 @@ declare global { data64: string; }; - // eventbus.WSLayoutAction - type WSLayoutAction = { + // eventbus.WSLayoutActionData + type WSLayoutActionData = { tabid: string; actiontype: string; blockid: string; diff --git a/pkg/service/fileservice/fileservice.go b/pkg/service/fileservice/fileservice.go index 6caaaa75a..a887d4386 100644 --- a/pkg/service/fileservice/fileservice.go +++ b/pkg/service/fileservice/fileservice.go @@ -131,6 +131,11 @@ func (fs *FileService) GetWaveFile(id string, path string) (any, error) { return file, nil } +func (fs *FileService) DeleteFile(path string) error { + cleanedPath := filepath.Clean(wavebase.ExpandHomeDir(path)) + return os.Remove(cleanedPath) +} + func (fs *FileService) GetSettingsConfig() interface{} { watcher := wconfig.GetWatcher() return watcher.GetSettingsConfig()