Add lazy thumbnail loading, restore scroll position when navigating to directory
This commit is contained in:
@@ -28,7 +28,7 @@ let {
|
|||||||
class:node_selected={child.fm_selected}
|
class:node_selected={child.fm_selected}
|
||||||
class:hidden={child.name.startsWith(".") && !show_hidden}
|
class:hidden={child.name.startsWith(".") && !show_hidden}
|
||||||
>
|
>
|
||||||
<img src={fs_node_icon(child, 64, 64)} class="node_icon" class:large_icons alt="icon"/>
|
<img src={fs_node_icon(child, 64, 64)} class="node_icon" class:large_icons loading="lazy" alt="icon"/>
|
||||||
<div class="node_name">
|
<div class="node_name">
|
||||||
{child.name}
|
{child.name}
|
||||||
</div>
|
</div>
|
||||||
@@ -69,6 +69,8 @@ let {
|
|||||||
/* backdrop-filter: blur(4px); */
|
/* backdrop-filter: blur(4px); */
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
|
content-visibility: auto;
|
||||||
|
contain-intrinsic-size: auto 2.4em;
|
||||||
}
|
}
|
||||||
.node:hover:not(.node_selected) {
|
.node:hover:not(.node_selected) {
|
||||||
background: var(--input_hover_background);
|
background: var(--input_hover_background);
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
<script lang="ts" module>
|
||||||
|
// Scroll offset per directory path. The file manager is destroyed when a file
|
||||||
|
// is opened, so the positions are kept here to survive the remount
|
||||||
|
const scroll_positions = new Map<string, number>()
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fs_rename, fs_trash, FSNode } from "lib/FilesystemAPI.svelte"
|
import { fs_rename, fs_trash, FSNode } from "lib/FilesystemAPI.svelte"
|
||||||
import { onMount } from "svelte"
|
|
||||||
import CreateDirectory from "./CreateDirectory.svelte"
|
import CreateDirectory from "./CreateDirectory.svelte"
|
||||||
import ListView from "./ListView.svelte"
|
import ListView from "./ListView.svelte"
|
||||||
import GalleryView from "./GalleryView.svelte"
|
import GalleryView from "./GalleryView.svelte"
|
||||||
@@ -22,7 +27,7 @@ let {
|
|||||||
upload_widget,
|
upload_widget,
|
||||||
edit_window = $bindable(),
|
edit_window = $bindable(),
|
||||||
search_bar = $bindable(),
|
search_bar = $bindable(),
|
||||||
directory_view = $bindable(""),
|
directory_view = $bindable(localStorage.getItem("directory_view") || "list"),
|
||||||
children
|
children
|
||||||
}: {
|
}: {
|
||||||
nav: FSNavigator;
|
nav: FSNavigator;
|
||||||
@@ -33,12 +38,15 @@ let {
|
|||||||
children?: import('svelte').Snippet;
|
children?: import('svelte').Snippet;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let large_icons = $state(false)
|
let large_icons = $state(localStorage.getItem("large_icons") === "true")
|
||||||
let uploader!: FsUploadWidget
|
let uploader!: FsUploadWidget
|
||||||
let mode = $state("viewing")
|
let mode = $state("viewing")
|
||||||
let creating_dir = $state(false)
|
let creating_dir = $state(false)
|
||||||
let show_hidden = $state(false)
|
let show_hidden = $state(false)
|
||||||
let file_menu!: FileMenu
|
let file_menu!: FileMenu
|
||||||
|
$effect(() => {
|
||||||
|
window.scrollTo(0, scroll_positions.get($nav.base.path) ?? 0)
|
||||||
|
})
|
||||||
|
|
||||||
export const upload = (files: File[]) => {
|
export const upload = (files: File[]) => {
|
||||||
return uploader.upload_files(files)
|
return uploader.upload_files(files)
|
||||||
@@ -270,18 +278,13 @@ const move_here = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
if(typeof Storage !== "undefined") {
|
|
||||||
directory_view = localStorage.getItem("directory_view")
|
|
||||||
large_icons = localStorage.getItem("large_icons") === "true"
|
|
||||||
}
|
|
||||||
if (directory_view === "" || directory_view === null) {
|
|
||||||
directory_view = "list"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window onkeydown={keypress} onkeyup={keypress} />
|
<svelte:window
|
||||||
|
onkeydown={keypress}
|
||||||
|
onkeyup={keypress}
|
||||||
|
onscroll={() => scroll_positions.set(nav.base.path, window.scrollY)}
|
||||||
|
/>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="container"
|
class="container"
|
||||||
@@ -407,9 +410,8 @@ onMount(() => {
|
|||||||
<style>
|
<style>
|
||||||
.container {
|
.container {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: auto;
|
|
||||||
display: block;
|
display: block;
|
||||||
height: 100%; /* Used for drop target */
|
min-height: 100%; /* Used for drop target */
|
||||||
}
|
}
|
||||||
.width_container {
|
.width_container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
|||||||
@@ -27,11 +27,13 @@ let {
|
|||||||
class:large_icons
|
class:large_icons
|
||||||
title={child.name}
|
title={child.name}
|
||||||
>
|
>
|
||||||
<div
|
<img
|
||||||
class="node_icon"
|
class="node_icon"
|
||||||
class:cover={fs_node_type(child) === "image" || fs_node_type(child) === "video"}
|
class:cover={fs_node_type(child) === "image" || fs_node_type(child) === "video"}
|
||||||
style='background-image: url("{fs_node_icon(child, 256, 256)}");'>
|
src={fs_node_icon(child, 256, 256)}
|
||||||
</div>
|
loading="lazy"
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
<div class="node_name">
|
<div class="node_name">
|
||||||
{child.name}
|
{child.name}
|
||||||
</div>
|
</div>
|
||||||
@@ -51,6 +53,10 @@ let {
|
|||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
width: 150px;
|
width: 150px;
|
||||||
height: 150px;
|
height: 150px;
|
||||||
|
/* Skips style, layout and paint for nodes which are off-screen. The
|
||||||
|
intrinsic size keeps the scrollbar accurate while they're skipped */
|
||||||
|
content-visibility: auto;
|
||||||
|
contain-intrinsic-size: auto 150px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: var(--body_background);
|
background: var(--body_background);
|
||||||
/* backdrop-filter: blur(4px); */
|
/* backdrop-filter: blur(4px); */
|
||||||
@@ -65,6 +71,7 @@ let {
|
|||||||
.file.large_icons {
|
.file.large_icons {
|
||||||
width: 200px;
|
width: 200px;
|
||||||
height: 200px;
|
height: 200px;
|
||||||
|
contain-intrinsic-size: auto 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On very small screens we switch to grid layout */
|
/* On very small screens we switch to grid layout */
|
||||||
@@ -93,13 +100,13 @@ let {
|
|||||||
}
|
}
|
||||||
.node_icon {
|
.node_icon {
|
||||||
flex: 1 1 0;
|
flex: 1 1 0;
|
||||||
|
min-height: 0;
|
||||||
|
width: 100%;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
background-position: center;
|
object-fit: contain;
|
||||||
background-size: contain;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
}
|
||||||
.node_icon.cover {
|
.node_icon.cover {
|
||||||
background-size: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
.node_name {
|
.node_name {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ onMount(load_settings)
|
|||||||
class:hidden={child.name.startsWith(".") && !show_hidden}
|
class:hidden={child.name.startsWith(".") && !show_hidden}
|
||||||
>
|
>
|
||||||
<td>
|
<td>
|
||||||
<img src={fs_node_icon(child, 64, 64)} class="node_icon" class:large_icons alt="icon"/>
|
<img src={fs_node_icon(child, 64, 64)} class="node_icon" class:large_icons loading="lazy" alt="icon"/>
|
||||||
</td>
|
</td>
|
||||||
<td class="node_name">
|
<td class="node_name">
|
||||||
<a class="title_link" href={"/d"+fs_encode_path(child.path)}>
|
<a class="title_link" href={"/d"+fs_encode_path(child.path)}>
|
||||||
@@ -133,7 +133,7 @@ onMount(load_settings)
|
|||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td class="node_size hide_small" class:hidden={!config.id}>
|
<td class="node_size hide_small" class:hidden={!config.id}>
|
||||||
<CopyButton text={$nav.base.id} onclick={prevent} />
|
<CopyButton text={child.id} onclick={prevent} />
|
||||||
<a href="/d/{child.id}" onclick={prevent}>{child.id}</a>
|
<a href="/d/{child.id}" onclick={prevent}>{child.id}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="node_icons">
|
<td class="node_icons">
|
||||||
@@ -187,7 +187,6 @@ onMount(load_settings)
|
|||||||
background: var(--body_background);
|
background: var(--body_background);
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
backdrop-filter: blur(4px);
|
backdrop-filter: blur(4px);
|
||||||
max-width: 1200px;
|
|
||||||
margin: auto; /* center */
|
margin: auto; /* center */
|
||||||
}
|
}
|
||||||
td {
|
td {
|
||||||
|
|||||||
@@ -171,7 +171,6 @@ export const logout_user = async (redirect_path: string) => {
|
|||||||
{ method: "DELETE" },
|
{ method: "DELETE" },
|
||||||
))
|
))
|
||||||
|
|
||||||
// document.cookie = "pd_auth_key=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
||||||
window.location.pathname = redirect_path
|
window.location.pathname = redirect_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user