server rendering improvements
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import { afterNavigate, goto } from "$app/navigation";
|
import { afterNavigate, goto } from "$app/navigation";
|
||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import LogoText from "$lib/components/logo/logo_text.svelte";
|
import LogoText from "$lib/components/logo/logo_text.svelte";
|
||||||
|
import { pb } from "$lib/pocketbase";
|
||||||
import { theme, toggleTheme } from "$lib/stores/theme_store";
|
import { theme, toggleTheme } from "$lib/stores/theme_store";
|
||||||
import { currentUser, logout } from "$lib/stores/user_store";
|
import { currentUser, logout } from "$lib/stores/user_store";
|
||||||
import { getFileURL } from "$lib/util/file_util";
|
import { getFileURL } from "$lib/util/file_util";
|
||||||
@@ -121,27 +122,30 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr class="my-6 border-input-border" />
|
<hr class="my-6 border-input-border" />
|
||||||
<div class="flex flex-col basis-full">
|
<div class="flex flex-col basis-full">
|
||||||
{#if $currentUser}
|
{#if pb.authStore.model}
|
||||||
<a
|
<a
|
||||||
class="btn-primary btn-large text-center mx-4"
|
class="btn-primary text-center mx-4"
|
||||||
href="/trail/edit/new"
|
href="/trail/edit/new"
|
||||||
><i class="fa fa-plus mr-2"></i>{$_("new-trail")}</a
|
><i class="fa fa-plus mr-2"></i>{$_("new-trail")}</a
|
||||||
>
|
>
|
||||||
<div class="basis-full"></div>
|
<div class="basis-full"></div>
|
||||||
<hr class="border-input-border" />
|
<hr class="border-input-border" />
|
||||||
<div class="flex gap-4 items-center justify-between m-4">
|
<div class="flex gap-4 items-center justify-between m-4">
|
||||||
<a href="/profile/{$currentUser.id}">
|
<a href="/profile/{pb.authStore.model.id}">
|
||||||
<img
|
<img
|
||||||
class="rounded-full w-10 aspect-square"
|
class="rounded-full w-10 aspect-square"
|
||||||
src={getFileURL($currentUser, $currentUser.avatar) ||
|
src={getFileURL(
|
||||||
`https://api.dicebear.com/7.x/initials/svg?seed=${$currentUser.username}&backgroundType=gradientLinear`}
|
pb.authStore.model,
|
||||||
|
pb.authStore.model.avatar,
|
||||||
|
) ||
|
||||||
|
`https://api.dicebear.com/7.x/initials/svg?seed=${pb.authStore.model.username}&backgroundType=gradientLinear`}
|
||||||
alt="avatar"
|
alt="avatar"
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
<a href="/profile/{$currentUser.id}">
|
<a href="/profile/{pb.authStore.model.id}">
|
||||||
<p class="text-sm">{$currentUser.username}</p>
|
<p class="text-sm">{pb.authStore.model.username}</p>
|
||||||
<p class="text-sm text-gray-500">
|
<p class="text-sm text-gray-500">
|
||||||
{$currentUser.email}
|
{pb.authStore.model.email}
|
||||||
</p>
|
</p>
|
||||||
</a>
|
</a>
|
||||||
<button
|
<button
|
||||||
@@ -182,7 +186,7 @@
|
|||||||
data-sveltekit-preload-data="off">{item.text}</a
|
data-sveltekit-preload-data="off">{item.text}</a
|
||||||
>
|
>
|
||||||
{/each}
|
{/each}
|
||||||
{#if $currentUser}
|
{#if pb.authStore.model}
|
||||||
<a
|
<a
|
||||||
class="font-semibold z-10"
|
class="font-semibold z-10"
|
||||||
href="/lists"
|
href="/lists"
|
||||||
@@ -191,7 +195,7 @@
|
|||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
</menu>
|
</menu>
|
||||||
{#if $currentUser}
|
{#if pb.authStore.model}
|
||||||
<div class="hidden lg:flex gap-6 items-center">
|
<div class="hidden lg:flex gap-6 items-center">
|
||||||
<button
|
<button
|
||||||
class="btn-icon fa-regular fa-{$theme === 'light'
|
class="btn-icon fa-regular fa-{$theme === 'light'
|
||||||
@@ -218,10 +222,10 @@
|
|||||||
<img
|
<img
|
||||||
class="rounded-full w-full h-full"
|
class="rounded-full w-full h-full"
|
||||||
src={getFileURL(
|
src={getFileURL(
|
||||||
$currentUser,
|
pb.authStore.model,
|
||||||
$currentUser.avatar,
|
pb.authStore.model.avatar,
|
||||||
) ||
|
) ||
|
||||||
`https://api.dicebear.com/7.x/initials/svg?seed=${$currentUser.username}&backgroundType=gradientLinear`}
|
`https://api.dicebear.com/7.x/initials/svg?seed=${pb.authStore.model.username}&backgroundType=gradientLinear`}
|
||||||
alt="avatar"
|
alt="avatar"
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
import EmptyStatePhotos from "../empty_states/empty_state_photos.svelte";
|
import EmptyStatePhotos from "../empty_states/empty_state_photos.svelte";
|
||||||
import EmptyStateWaypoint from "../empty_states/empty_state_waypoint.svelte";
|
import EmptyStateWaypoint from "../empty_states/empty_state_waypoint.svelte";
|
||||||
import EmptyStateDescription from "../empty_states/empty_state_description.svelte";
|
import EmptyStateDescription from "../empty_states/empty_state_description.svelte";
|
||||||
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
export let trail: Trail;
|
export let trail: Trail;
|
||||||
export let mode: "overview" | "map" | "list" = "map";
|
export let mode: "overview" | "map" | "list" = "map";
|
||||||
@@ -53,7 +54,7 @@
|
|||||||
$_("waypoints", { values: { n: 2 } }),
|
$_("waypoints", { values: { n: 2 } }),
|
||||||
$_("photos"),
|
$_("photos"),
|
||||||
$_("summit-book"),
|
$_("summit-book"),
|
||||||
...($currentUser ? [$_("comment", { values: { n: 2 } })] : []),
|
...(pb.authStore.model ? [$_("comment", { values: { n: 2 } })] : []),
|
||||||
];
|
];
|
||||||
|
|
||||||
const trailIsShared =
|
const trailIsShared =
|
||||||
@@ -69,11 +70,11 @@
|
|||||||
|
|
||||||
let newComment: Comment = new Comment("", 0, "", trail.id ?? "");
|
let newComment: Comment = new Comment("", 0, "", trail.id ?? "");
|
||||||
|
|
||||||
let commentsLoading: boolean = false;
|
let commentsLoading: boolean = activeTab == 4;
|
||||||
let commentCreateLoading: boolean = false;
|
let commentCreateLoading: boolean = false;
|
||||||
let commentDeleteLoading: boolean = false;
|
let commentDeleteLoading: boolean = false;
|
||||||
|
|
||||||
$: if (activeTab == 4) {
|
$: if (browser && activeTab == 4) {
|
||||||
fetchComments();
|
fetchComments();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +403,9 @@
|
|||||||
></SkeletonNotificationCard>
|
></SkeletonNotificationCard>
|
||||||
{/each}
|
{/each}
|
||||||
{:else if $comments.length == 0}
|
{:else if $comments.length == 0}
|
||||||
<div class="my-4"><EmptyStateComment></EmptyStateComment></div>
|
<div class="my-4">
|
||||||
|
<EmptyStateComment></EmptyStateComment>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<ul class="space-y-4">
|
<ul class="space-y-4">
|
||||||
{#each $comments ?? [] as comment}
|
{#each $comments ?? [] as comment}
|
||||||
|
|||||||
@@ -3,7 +3,22 @@ import { get, writable, type Writable } from "svelte/store";
|
|||||||
|
|
||||||
type Theme = "dark" | "light"
|
type Theme = "dark" | "light"
|
||||||
|
|
||||||
export const theme: Writable<Theme> = writable(browser && localStorage.getItem("theme") as Theme || "light" );
|
export const theme: Writable<Theme> = writable(getDefaultTheme());
|
||||||
|
|
||||||
|
function getDefaultTheme(): Theme {
|
||||||
|
if (browser) {
|
||||||
|
if (localStorage.getItem("theme")) {
|
||||||
|
return localStorage.getItem("theme") as Theme;
|
||||||
|
} else if (document.documentElement.classList.contains("light")) {
|
||||||
|
return "light"
|
||||||
|
} else if (document.documentElement.classList.contains("dark")) {
|
||||||
|
return "dark";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "light";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export function toggleTheme() {
|
export function toggleTheme() {
|
||||||
const currentTheme = get(theme);
|
const currentTheme = get(theme);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import '$lib/i18n'
|
|||||||
import { waitLocale } from 'svelte-i18n'
|
import { waitLocale } from 'svelte-i18n'
|
||||||
import type { LayoutLoad } from './$types'
|
import type { LayoutLoad } from './$types'
|
||||||
|
|
||||||
export const load: LayoutLoad = async () => {
|
export const load: LayoutLoad = async ({ data }) => {
|
||||||
await waitLocale()
|
await waitLocale()
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
const MIN_ZOOM = 6;
|
const MIN_ZOOM = 6;
|
||||||
|
|
||||||
let loading: boolean = false;
|
let loading: boolean = true;
|
||||||
|
|
||||||
onMount(async () => {});
|
onMount(async () => {});
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
let filterExpanded: boolean = true;
|
let filterExpanded: boolean = true;
|
||||||
|
|
||||||
let loading: boolean = false;
|
let loading: boolean = true;
|
||||||
|
|
||||||
const filter: TrailFilter = $page.data.filter;
|
const filter: TrailFilter = $page.data.filter;
|
||||||
const pagination: { page: number; totalPages: number } = {
|
const pagination: { page: number; totalPages: number } = {
|
||||||
|
|||||||
Reference in New Issue
Block a user