Replace event dispatcher with a callback in filemanager
This commit is contained in:
@@ -4,7 +4,8 @@ import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import Button from "layout/Button.svelte";
|
||||
import Dialog from "layout/Dialog.svelte";
|
||||
import { bookmark_add, bookmark_del, bookmarks_store, is_bookmark } from "lib/Bookmarks";
|
||||
import { fs_download, type FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_delete, fs_download, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
import { tick } from "svelte";
|
||||
|
||||
let {
|
||||
@@ -20,10 +21,26 @@ let node: FSNode = $state(null)
|
||||
|
||||
export const open = async (n: FSNode, target: EventTarget) => {
|
||||
node = n
|
||||
let el: HTMLElement = (target as Element).closest("button")
|
||||
if (el === null) {
|
||||
el = (target as Element).closest("a")
|
||||
}
|
||||
|
||||
// Wait for the view to update, so the dialog gets the proper measurements
|
||||
await tick()
|
||||
dialog.open((target as Element).closest("button").getBoundingClientRect())
|
||||
dialog.open(el.getBoundingClientRect())
|
||||
}
|
||||
|
||||
const delete_node = async () => {
|
||||
try {
|
||||
loading_start()
|
||||
await fs_delete(node.path)
|
||||
nav.reload()
|
||||
} catch (err) {
|
||||
alert(JSON.stringify(err))
|
||||
} finally {
|
||||
loading_finish()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -36,6 +53,7 @@ export const open = async (n: FSNode, target: EventTarget) => {
|
||||
<Button click={() => {dialog.close(); bookmark_add(node)}} icon="bookmark_add" label="Add bookmark"/>
|
||||
{/if}
|
||||
{#if $nav.permissions.write}
|
||||
<Button click={() => {dialog.close(); delete_node()}} icon="delete" label="Delete"/>
|
||||
<Button click={() => {dialog.close(); edit_window.edit(node, false, "file")}} icon="edit" label="Edit"/>
|
||||
<Button click={() => {dialog.close(); edit_window.edit(node, false, "share")}} icon="share" label="Share"/>
|
||||
<Button click={() => {dialog.close(); edit_window.edit(node, false, "branding")}} icon="palette" label="Branding"/>
|
||||
|
Reference in New Issue
Block a user