diff --git a/src/app.d.ts b/src/app.d.ts index b660ebc8..9ef481b2 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,5 +1,6 @@ // See https://kit.svelte.dev/docs/types#app +import type { Action } from '$lib/components/ui/navbar/commands/actions' import type { ComponentType, SvelteComponent } from 'svelte' // for information about these interfaces @@ -16,6 +17,9 @@ declare global { props?: any } } + contextual?: { + actions?: Action[] + } } interface PageState { openImage: url diff --git a/src/lib/components/ui/navbar/commands/Commands.svelte b/src/lib/components/ui/navbar/commands/Commands.svelte index 786731a1..3e286188 100644 --- a/src/lib/components/ui/navbar/commands/Commands.svelte +++ b/src/lib/components/ui/navbar/commands/Commands.svelte @@ -10,6 +10,7 @@ import { profile, profileData } from '$lib/auth' import { getGroups, type Action, type Group } from './actions' import { themeData } from '$lib/ui/colors' + import { page } from '$app/stores' export let open = false $: if (open) search = '' @@ -20,7 +21,8 @@ $resumables, $profile, $profileData.profiles, - $themeData + $themeData, + $page.data.contextual?.actions ) let search = '' diff --git a/src/lib/components/ui/navbar/commands/actions.ts b/src/lib/components/ui/navbar/commands/actions.ts index 980e9f6e..d47151fe 100644 --- a/src/lib/components/ui/navbar/commands/actions.ts +++ b/src/lib/components/ui/navbar/commands/actions.ts @@ -43,6 +43,7 @@ import { ChatBubbleOvalLeftEllipsis, ChatBubbleLeftRight, Swatch, + Plus, } from 'svelte-hero-icons' import { get } from 'svelte/store' @@ -66,7 +67,8 @@ export function getGroups( resumables: ResumableItem[], profile: Profile, profiles: Profile[], - td: ThemeData + td: ThemeData, + contextual?: Action[] ) { return [ { @@ -77,6 +79,10 @@ export function getGroups( href: r.url, })), }, + { + name: t.get('nav.commands.contextual'), + actions: contextual ?? [], + }, { name: t.get('nav.commands.main'), actions: [ @@ -254,6 +260,26 @@ export function getGroups( name: t.get('account.accounts'), icon: UserGroup, }, + { + href: '/login', + name: t.get('account.login'), + icon: ArrowRightOnRectangle, + }, + { + href: '/signup', + name: t.get('account.signup'), + icon: Identification, + }, + { + href: '/login/guest', + name: t.get('account.addGuest'), + icon: Plus, + }, + { + href: '/accounts', + name: t.get('account.accounts'), + icon: UserGroup, + }, ] : [ { @@ -266,6 +292,11 @@ export function getGroups( name: t.get('account.signup'), icon: Identification, }, + { + href: '/login/guest', + name: t.get('account.addGuest'), + icon: Plus, + }, { href: '/accounts', name: t.get('account.accounts'), diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index c89d8fa2..6c76f2df 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -46,7 +46,8 @@ "feeds": "Feeds", "downloading": "Downloading actions", "setTheme": "Set theme", - "setThemeTo": "Set theme to {{default}}" + "setThemeTo": "Set theme to {{default}}", + "contextual": "On this page" } }, "account": { diff --git a/src/routes/+page.ts b/src/routes/+page.ts index d7c36589..51ef45cc 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -6,6 +6,8 @@ import { error } from '@sveltejs/kit' import { browser } from '$app/environment' import { instance } from '$lib/instance' import { postFeed, postFeeds, shouldReload } from '$lib/lemmy/postfeed.js' +import { t } from '$lib/translations.js' +import { ChevronDoubleUp } from 'svelte-hero-icons' export async function load({ url, fetch }) { const cursor = url.searchParams.get('cursor') as string | undefined @@ -18,16 +20,27 @@ export async function load({ url, fetch }) { const listingType: ListingType = (url.searchParams.get('type') as ListingType) || settings.defaultSort.feed - return await postFeed({ - id: 'main', - request: { - page_cursor: cursor, - sort: sort, - type_: listingType, - limit: 20, - show_hidden: settings.posts.showHidden, + return { + ...(await postFeed({ + id: 'main', + request: { + page_cursor: cursor, + sort: sort, + type_: listingType, + limit: 20, + show_hidden: settings.posts.showHidden, + }, + url: url, + fetch: fetch, + })), + contextual: { + actions: [ + { + name: t.get('routes.post.scrollToTop'), + handle: () => window?.scrollTo({ top: 0, behavior: 'instant' }), + icon: ChevronDoubleUp, + }, + ], }, - url: url, - fetch: fetch, - }) + } } diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index 3374a6ca..81b8c861 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -1,7 +1,7 @@ - {post.post_view.post.name} - - + {data.post.post_view.post.name} + + - {#if isImage(post.post_view.post.url)} - - - {:else if post.post_view.post.thumbnail_url} - - + {#if isImage(data.post.post_view.post.url)} + + + {:else if data.post.post_view.post.thumbnail_url} + + {/if} - {#if post.post_view.post.body} + {#if data.post.post_view.post.body} {/if} @@ -188,24 +244,24 @@

- +

- {#if post.post_view.post.body} + {#if data.post.post_view.post.body}
- +
{/if}
toast({ content: 'The post was edited successfully.', @@ -238,22 +294,22 @@ {type} />
- {#if post.cross_posts?.length > 0} + {#if data.post.cross_posts?.length > 0}
- {post.cross_posts.length} + {data.post.cross_posts.length} {$t('routes.post.crosspostCount')}
- {#each post.cross_posts as crosspost} + {#each data.post.cross_posts as crosspost} {/each}
@@ -294,7 +350,7 @@
- + {$t('routes.post.commentCount')}
@@ -339,13 +395,13 @@ {:else} (comments.comments = [ comment.detail.comment_view, ...comments.comments, ])} - locked={(post.post_view.post.locked && + locked={(data.post.post_view.post.locked && !( $profile?.user?.local_user_view.local_user.admin || $profile?.user?.moderates @@ -381,7 +437,7 @@ {/if} {/if} {/await} - {#if post.post_view.counts.comments > 5} + {#if data.post.post_view.counts.comments > 5} - {post.post_view.counts.comments} + {data.post.post_view.counts.comments} {$t('routes.post.commentCount')}