Files
fnx_web/svelte/src/filesystem/Toolbar.svelte

234 lines
5.0 KiB
Svelte
Raw Normal View History

<script>
import { createEventDispatcher } from "svelte";
2023-11-15 16:40:55 +01:00
import { generate_share_url } from "./Sharebar.svelte";
import { copy_text } from "../util/Util.svelte";
2023-05-19 21:45:42 +02:00
import FileStats from "./FileStats.svelte";
let dispatch = createEventDispatcher()
2023-05-17 22:46:27 +02:00
export let fs_navigator
export let state = {
base: {
type: "",
path: "",
},
children: [],
shuffle: false
}
2023-05-25 17:06:17 +02:00
export let view = "file"
export let details_visible = false
export let edit_window
export let edit_visible = false
export let file_viewer
$: share_url = generate_share_url(state.path)
let link_copied = false
2023-11-16 12:17:36 +01:00
export const copy_link = () => {
if (share_url === "") {
2024-02-16 21:07:01 +01:00
edit_window.edit(state.base, true, "share")
return
}
copy_text(share_url)
link_copied = true
setTimeout(() => {link_copied = false}, 60000)
}
2023-05-17 22:46:27 +02:00
let share = async () => {
if (share_url === "") {
2023-05-29 22:15:46 +02:00
edit_window.edit(state.base, true, "share")
return
}
2023-05-25 14:47:36 +02:00
if (navigator.share) {
2023-05-17 22:46:27 +02:00
await navigator.share({
title: state.base.name,
text: "I would like to share '" + state.base.name + "' with you",
url: share_url
})
2023-05-25 14:47:36 +02:00
} else {
2023-11-15 16:40:55 +01:00
alert("Navigator does not support sharing, use copy link button to copy the link instead")
}
}
2023-11-15 16:40:55 +01:00
let fullscreen = false
const toggle_fullscreen = () => {
if (fullscreen || document.fullscreenElement) {
try {
document.exitFullscreen()
} catch (err) {
console.debug("Failed to exit fullscreen", err)
}
fullscreen = false
} else {
file_viewer.requestFullscreen()
fullscreen = true
}
}
2023-11-15 16:40:55 +01:00
let expanded = false
let expand = e => {
e.preventDefault()
e.stopPropagation()
expanded = !expanded
}
</script>
2023-11-15 16:40:55 +01:00
<div class="toolbar" class:expanded>
<div class="separator hidden_horizontal" style="margin-top: 0;"></div>
2023-11-15 16:40:55 +01:00
<div class="stats_container" on:click={expand} on:keypress={expand} role="button" tabindex="0">
<button class="button_expand hidden_vertical" on:click={expand}>
2023-11-15 16:40:55 +01:00
{#if expanded}
<i class="icon">expand_more</i>
{:else}
<i class="icon">expand_less</i>
{/if}
</button>
<FileStats state={state}/>
</div>
<div class="separator"></div>
<div class="grid">
<div class="button_row">
<button on:click={() => {fs_navigator.open_sibling(-1)}}>
<i class="icon">skip_previous</i>
</button>
<button on:click={() => {state.shuffle = !state.shuffle}} class:button_highlight={state.shuffle}>
<i class="icon">shuffle</i>
</button>
<button on:click={() => {fs_navigator.open_sibling(1)}}>
<i class="icon">skip_next</i>
</button>
</div>
{#if state.path[0].id === "me"}
2023-11-16 12:17:36 +01:00
<button on:click={() => dispatch("search")} class:button_highlight={view === "search"}>
<i class="icon">search</i>
<span>Search</span>
</button>
{/if}
<div class="separator hidden_horizontal"></div>
<button on:click={() => dispatch("download")}>
<i class="icon">save</i>
<span>Download</span>
</button>
{#if share_url !== ""}
2023-11-16 12:17:36 +01:00
<button on:click={copy_link} class:button_highlight={link_copied}>
<i class="icon">content_copy</i>
<span><u>C</u>opy Link</span>
</button>
{/if}
2024-02-16 14:50:34 +01:00
{#if state.base.id !== "me"}
<button on:click={share}>
<i class="icon">share</i>
<span>Share</span>
</button>
{/if}
<button
class="toolbar_button"
on:click={toggle_fullscreen}
class:button_highlight={fullscreen}
title="Open page in full screen mode">
{#if fullscreen}
<i class="icon">fullscreen_exit</i>
{:else}
<i class="icon">fullscreen</i>
{/if}
<span>Fullscreen</span>
</button>
<div class="separator hidden_horizontal"></div>
2023-11-16 12:17:36 +01:00
<button on:click={() => details_visible = !details_visible} class:button_highlight={details_visible}>
<i class="icon">help</i>
<span>Deta<u>i</u>ls</span>
</button>
2024-02-16 11:49:38 +01:00
{#if state.base.id !== "me" && state.permissions.update === true}
2024-02-16 21:07:01 +01:00
<button on:click={() => edit_window.edit(state.base, true, "file")} class:button_highlight={edit_visible}>
2023-11-16 12:17:36 +01:00
<i class="icon">edit</i>
<span><u>E</u>dit</span>
</button>
{/if}
</div>
</div>
<style>
.toolbar {
flex: 0 0 auto;
overflow-x: hidden;
overflow-y: scroll;
2023-11-15 16:40:55 +01:00
transition: max-height 0.3s;
background-color: var(--shaded_background);
}
.grid {
display: grid;
2024-04-10 18:35:51 +02:00
grid-template-columns: repeat(auto-fit, minmax(7.5em, 1fr));
}
.separator {
height: 1px;
margin: 2px 0;
width: 100%;
background-color: var(--separator);
}
.button_row {
display: flex;
flex-direction: row;
}
.button_row > * {
flex: 1 1 auto;
2023-11-16 12:17:36 +01:00
justify-content: center;
}
2023-11-15 16:40:55 +01:00
.stats_container {
display: flex;
flex-direction: column;
}
.button_expand {
2024-04-11 22:18:55 +02:00
line-height: 1em;
2023-11-15 16:40:55 +01:00
}
2024-02-16 21:07:01 +01:00
.hidden_vertical {
display: none;
}
.hidden_horizontal {
display: block;
}
2024-02-16 21:07:01 +01:00
/* This max-width needs to be synced with the .viewer_area max-width in
Toolbar.svelte and the .label max-width in FileStats.svelte */
2024-03-15 13:58:27 +01:00
@media (max-width: 800px) {
2023-11-15 16:40:55 +01:00
.toolbar {
overflow-y: hidden;
2024-04-11 22:18:55 +02:00
max-height: 2.1em;
2023-11-15 16:40:55 +01:00
}
.toolbar.expanded {
overflow-y: scroll;
max-height: 30vh;
2023-11-15 16:40:55 +01:00
}
.stats_container {
flex-direction: row;
}
.separator {
margin: 2px 0;
}
.hidden_vertical {
display: block;
}
.hidden_horizontal {
display: none;
2023-11-15 16:40:55 +01:00
}
}
</style>