diff --git a/cista-front/src/App.vue b/cista-front/src/App.vue index b4b7c64..80939d8 100644 --- a/cista-front/src/App.vue +++ b/cista-front/src/App.vue @@ -15,14 +15,8 @@ import { RouterView } from 'vue-router' import type { ComputedRef } from 'vue' import type HeaderMain from '@/components/HeaderMain.vue' -import { onMounted, onUnmounted, ref, watchEffect } from 'vue' -import createWebSocket from '@/repositories/WS' -import { - url_document_watch_ws, - url_document_upload_ws, - DocumentHandler, - DocumentUploadHandler -} from '@/repositories/Document' +import { onMounted, onUnmounted, ref } from 'vue' +import { watchConnect, watchDisconnect } from '@/repositories/WS' import { useDocumentStore } from '@/stores/documents' import { computed } from 'vue' @@ -41,23 +35,10 @@ const path: ComputedRef = computed(() => { pathList } }) +onMounted(watchConnect) +onUnmounted(watchDisconnect) // Update human-readable x seconds ago messages from mtimes setInterval(documentStore.updateModified, 1000) -watchEffect(() => { - const documentHandler = new DocumentHandler() - const documentUploadHandler = new DocumentUploadHandler() - const wsWatch = createWebSocket( - url_document_watch_ws, - documentHandler.handleWebSocketMessage - ) - const wsUpload = createWebSocket( - url_document_upload_ws, - documentUploadHandler.handleWebSocketMessage - ) - - documentStore.wsWatch = wsWatch - documentStore.wsUpload = wsUpload -}) const headerMain = ref(null) let vert = 0 let timer: any = null diff --git a/cista-front/src/assets/main.css b/cista-front/src/assets/main.css index 98a2a24..60ead97 100644 --- a/cista-front/src/assets/main.css +++ b/cista-front/src/assets/main.css @@ -197,6 +197,9 @@ main { padding-bottom: 3em; /* convenience space on the bottom */ overflow-y: scroll; } +.spacer { flex-grow: 1 } +.smallgap { margin-left: 2em } + [data-tooltip]:hover:after { z-index: 101; content: attr(data-tooltip); @@ -206,7 +209,7 @@ main { padding: .5rem 1rem; border-radius: 3rem 0 3rem 0; box-shadow: 0 0 1rem var(--accent-color); - transform: translate(calc(1rem + -50%), 100%); + transform: translate(calc(1rem + -50%), 150%); background-color: var(--accent-color); color: var(--primary-color); white-space: pre; diff --git a/cista-front/src/components/FileExplorer.vue b/cista-front/src/components/FileExplorer.vue index 2e56b71..c430a94 100644 --- a/cista-front/src/components/FileExplorer.vue +++ b/cista-front/src/components/FileExplorer.vue @@ -59,17 +59,13 @@ - - {{props.documents.length}} items shown: - {{ formatSize(props.documents.reduce((a, b) => a + b.size, 0)) }} - - + + {{props.documents.length}} items shown: + {{ formatSize(props.documents.reduce((a, b) => a + b.size, 0)) }} + +
Nothing to see here
@@ -148,7 +144,7 @@ import { ref, computed, watchEffect, onBeforeUpdate } from 'vue' import { useDocumentStore } from '@/stores/documents' import type { Document } from '@/repositories/Document' import FileRenameInput from './FileRenameInput.vue' -import createWebSocket from '@/repositories/WS' +import { connect, controlUrl } from '@/repositories/WS' import { collator, formatSize, formatUnixDate } from '@/utils' import { useRouter } from 'vue-router' @@ -163,20 +159,22 @@ const documentStore = useDocumentStore() const router = useRouter() const url_for = (doc: Document) => { const p = doc.loc ? `${doc.loc}/${doc.name}` : doc.name - return doc.type === 'folder' ? `#/${p}/` : `/files/${p}` + return doc.dir ? `#/${p}/` : `/files/${p}` } const cursor = ref(null) // File rename const editing = ref(null) const rename = (doc: Document, newName: string) => { const oldName = doc.name - const control = createWebSocket('/api/control', (ev: MessageEvent) => { - const msg = JSON.parse(ev.data) - if ('error' in msg) { - console.error('Rename failed', msg.error.message, msg.error) - doc.name = oldName - } else { - console.log('Rename succeeded', msg) + const control = connect(controlUrl, { + message(ev: MessageEvent) { + const msg = JSON.parse(ev.data) + if ('error' in msg) { + console.error('Rename failed', msg.error.message, msg.error) + doc.name = oldName + } else { + console.log('Rename succeeded', msg) + } } }) control.onopen = () => { @@ -204,6 +202,7 @@ defineExpose({ modified: formatUnixDate(now), haystack: '', } + console.log("New") }, toggleSelectAll() { console.log('Select') @@ -289,24 +288,26 @@ watchEffect(() => { } }) const mkdir = (doc: Document, 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) - editing.value = null - } else { - console.log('mkdir', msg) - router.push(`/${doc.loc}/${name}/`) + const control = connect(controlUrl, { + open() { + control.send( + JSON.stringify({ + op: 'mkdir', + path: `${doc.loc}/${name}` + }) + ) + }, + message(ev: MessageEvent) { + const msg = JSON.parse(ev.data) + if ('error' in msg) { + console.error('Mkdir failed', msg.error.message, msg.error) + editing.value = null + } else { + console.log('mkdir', msg) + router.push(`/${doc.loc}/${name}/`) + } } }) - control.onopen = () => { - control.send( - JSON.stringify({ - op: 'mkdir', - path: `${doc.loc}/${name}` - }) - ) - } doc.name = name // We should get an update from watch but this is quicker } @@ -499,6 +500,9 @@ tbody .selection input { font-size: 3rem; color: var(--accent-color); } +.folder-change { + margin-left: -.5rem; +} .loc { color: #888; } diff --git a/cista-front/src/components/HeaderMain.vue b/cista-front/src/components/HeaderMain.vue index 47ce362..fb6f3b8 100644 --- a/cista-front/src/components/HeaderMain.vue +++ b/cista-front/src/components/HeaderMain.vue @@ -1,26 +1,3 @@ - - - + + +