Frontend created and rewritten a few times, with some backend fixes #1
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<main>
|
<main>
|
||||||
<table v-if="props.documents.length">
|
<button @click="newFolder">New Folder</button>
|
||||||
|
<table v-if="props.documents.length || editing">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="selection">
|
<th class="selection">
|
||||||
|
@ -34,6 +35,14 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr v-if="editing?.key === 'new'" class="folder">
|
||||||
|
<td class="selection"></td>
|
||||||
|
<td class="name">
|
||||||
|
<FileRenameInput :doc="editing" :rename="mkdir" :exit="() => { editing = null }"/>
|
||||||
|
</td>
|
||||||
|
<td class="right">{{editing.modified}}</td>
|
||||||
|
<td class="right">{{editing.sizedisp}}</td>
|
||||||
|
</tr>
|
||||||
<tr
|
<tr
|
||||||
v-for="doc of sorted(props.documents as FolderDocument[])"
|
v-for="doc of sorted(props.documents as FolderDocument[])"
|
||||||
:key="doc.key"
|
:key="doc.key"
|
||||||
|
@ -79,6 +88,7 @@ import { useDocumentStore } from '@/stores/documents'
|
||||||
import type { Document, FolderDocument } from '@/repositories/Document'
|
import type { Document, FolderDocument } from '@/repositories/Document'
|
||||||
import FileRenameInput from './FileRenameInput.vue'
|
import FileRenameInput from './FileRenameInput.vue'
|
||||||
import createWebSocket from '@/repositories/WS'
|
import createWebSocket from '@/repositories/WS'
|
||||||
|
import { formatSize, formatUnixDate } from '@/utils'
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -122,6 +132,38 @@ const rename = (doc: FolderDocument, newName: string) => {
|
||||||
}
|
}
|
||||||
doc.name = newName // We should get an update from watch but this is quicker
|
doc.name = newName // We should get an update from watch but this is quicker
|
||||||
}
|
}
|
||||||
|
const newFolder = () => {
|
||||||
|
const now = Date.now() / 1000
|
||||||
|
editing.value = {
|
||||||
|
key: 'new',
|
||||||
|
name: 'New Folder',
|
||||||
|
type: 'folder',
|
||||||
|
mtime: now,
|
||||||
|
size: 0,
|
||||||
|
sizedisp: formatSize(0),
|
||||||
|
modified: formatUnixDate(now)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const mkdir = (doc: FolderDocument, name: string) => {
|
||||||
|
const control = createWebSocket('/api/control', (ev: MessageEvent) => {
|
||||||
|
const msg = JSON.parse(ev.data)
|
||||||
|
if ('error' in msg) {
|
||||||
|
console.error('Mkdir failed', msg.error.message, msg.error)
|
||||||
|
doc.name = oldName
|
||||||
|
} else {
|
||||||
|
console.log('mkdir', msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
control.onopen = () => {
|
||||||
|
control.send(
|
||||||
|
JSON.stringify({
|
||||||
|
op: 'mkdir',
|
||||||
|
path: `${linkBasePath.value}/${name}`,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
doc.name = name // We should get an update from watch but this is quicker
|
||||||
|
}
|
||||||
|
|
||||||
// Column sort
|
// Column sort
|
||||||
const toggleSort = (name: string) => {
|
const toggleSort = (name: string) => {
|
||||||
|
|
|
@ -30,7 +30,7 @@ const props = defineProps<{
|
||||||
const apply = () => {
|
const apply = () => {
|
||||||
const name = input.value!.value
|
const name = input.value!.value
|
||||||
props.exit()
|
props.exit()
|
||||||
if (name === props.doc.name || name.length === 0) return
|
if (props.doc.key !== 'new' && (name === props.doc.name || name.length === 0)) return
|
||||||
props.rename(props.doc, name)
|
props.rename(props.doc, name)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user