2023-10-26 00:43:44 +01:00
|
|
|
<template>
|
2023-11-07 00:44:55 +00:00
|
|
|
<nav class="headermain">
|
2023-11-04 00:21:35 +00:00
|
|
|
<div class="buttons">
|
2023-11-07 18:01:34 +00:00
|
|
|
<template v-if="documentStore.error">
|
|
|
|
<div class="error-message" @click="documentStore.error = ''">{{ documentStore.error }}</div>
|
|
|
|
<div class="smallgap"></div>
|
|
|
|
</template>
|
2023-10-26 00:43:44 +01:00
|
|
|
<UploadButton />
|
2023-11-04 20:54:14 +00:00
|
|
|
<SvgButton
|
|
|
|
name="create-folder"
|
2023-11-06 15:33:43 +00:00
|
|
|
data-tooltip="New folder"
|
2023-11-04 20:54:14 +00:00
|
|
|
@click="() => documentStore.fileExplorer.newFolder()"
|
|
|
|
/>
|
|
|
|
<slot></slot>
|
2023-11-06 18:51:51 +00:00
|
|
|
<div class="spacer smallgap"></div>
|
2023-10-27 16:32:21 +01:00
|
|
|
<template v-if="showSearchInput">
|
2023-11-04 00:21:35 +00:00
|
|
|
<input
|
|
|
|
ref="search"
|
|
|
|
type="search"
|
2023-11-06 21:50:29 +00:00
|
|
|
v-model="documentStore.search"
|
2023-11-07 01:26:41 +00:00
|
|
|
placeholder="Search words"
|
2023-11-04 00:21:35 +00:00
|
|
|
class="margin-input"
|
2023-11-07 14:48:48 +00:00
|
|
|
@keyup.escape="closeSearch"
|
2023-11-04 00:21:35 +00:00
|
|
|
/>
|
2023-10-27 16:32:21 +01:00
|
|
|
</template>
|
2023-11-07 14:48:48 +00:00
|
|
|
<SvgButton ref="searchButton" name="find" @click.prevent="toggleSearchInput" />
|
2023-11-07 16:10:56 +00:00
|
|
|
<SvgButton name="cog" @click="settingsMenu" />
|
2023-10-26 00:43:44 +01:00
|
|
|
</div>
|
2023-11-04 00:21:35 +00:00
|
|
|
</nav>
|
2023-10-26 00:43:44 +01:00
|
|
|
</template>
|
|
|
|
|
2023-11-07 14:48:48 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useDocumentStore } from '@/stores/documents'
|
|
|
|
import { ref, nextTick } from 'vue'
|
2023-11-07 16:10:56 +00:00
|
|
|
import ContextMenu from '@imengyu/vue3-context-menu'
|
2023-11-07 14:48:48 +00:00
|
|
|
|
|
|
|
const documentStore = useDocumentStore()
|
|
|
|
const showSearchInput = ref<boolean>(false)
|
|
|
|
const search = ref<HTMLInputElement | null>()
|
|
|
|
const searchButton = ref<HTMLButtonElement | null>()
|
|
|
|
|
|
|
|
const closeSearch = () => {
|
|
|
|
if (!showSearchInput.value) return // Already closing
|
|
|
|
showSearchInput.value = false
|
|
|
|
documentStore.search = ''
|
|
|
|
const breadcrumb = document.querySelector('.breadcrumb') as HTMLElement
|
|
|
|
breadcrumb.focus()
|
|
|
|
}
|
|
|
|
const toggleSearchInput = () => {
|
|
|
|
showSearchInput.value = !showSearchInput.value
|
|
|
|
if (!showSearchInput.value) return closeSearch()
|
|
|
|
nextTick(() => {
|
|
|
|
const input = search.value
|
|
|
|
if (input) input.focus()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-07 16:10:56 +00:00
|
|
|
const settingsMenu = (e: Event) => {
|
|
|
|
// show the context menu
|
2023-11-07 18:01:34 +00:00
|
|
|
const items = []
|
|
|
|
if (documentStore.user.isLoggedIn) {
|
|
|
|
items.push({ label: `Logout ${documentStore.user.username ?? ''}`, onClick: () => documentStore.logout() })
|
|
|
|
} else {
|
|
|
|
items.push({ label: 'Login', onClick: () => documentStore.loginDialog() })
|
|
|
|
}
|
2023-11-07 16:10:56 +00:00
|
|
|
ContextMenu.showContextMenu({
|
|
|
|
// @ts-ignore
|
|
|
|
x: e.target.getBoundingClientRect().right, y: e.target.getBoundingClientRect().bottom,
|
2023-11-07 18:01:34 +00:00
|
|
|
items,
|
2023-11-07 16:10:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-07 14:48:48 +00:00
|
|
|
defineExpose({
|
|
|
|
toggleSearchInput,
|
|
|
|
closeSearch,
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2023-11-04 00:21:35 +00:00
|
|
|
<style scoped>
|
|
|
|
.buttons {
|
2023-11-06 15:33:43 +00:00
|
|
|
padding: 0;
|
2023-10-26 00:43:44 +01:00
|
|
|
display: flex;
|
2023-11-04 00:21:35 +00:00
|
|
|
align-items: center;
|
2023-11-06 16:51:10 +00:00
|
|
|
height: 3.5em;
|
2023-11-06 15:33:43 +00:00
|
|
|
z-index: 10;
|
2023-10-26 00:43:44 +01:00
|
|
|
}
|
2023-11-04 19:50:05 +00:00
|
|
|
.buttons > * {
|
|
|
|
flex-shrink: 1;
|
|
|
|
}
|
2023-11-04 00:21:35 +00:00
|
|
|
input[type='search'] {
|
2023-11-07 19:05:21 +00:00
|
|
|
background: var(--input-background);
|
|
|
|
color: var(--input-color);
|
2023-11-04 00:21:35 +00:00
|
|
|
border: 0;
|
2023-11-06 16:51:10 +00:00
|
|
|
border-radius: 0.1em;
|
|
|
|
padding: 0.5em;
|
2023-11-04 00:21:35 +00:00
|
|
|
outline: none;
|
2023-11-06 16:51:10 +00:00
|
|
|
font-size: 1.5em;
|
2023-11-04 19:50:05 +00:00
|
|
|
max-width: 30vw;
|
2023-11-03 16:15:37 +00:00
|
|
|
}
|
2023-10-26 00:43:44 +01:00
|
|
|
</style>
|