Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/components/icons/icons.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script module lang="ts">
import ArrowLeft from '@lucide/svelte/icons/arrow-left';
import ArrowUp from '@lucide/svelte/icons/arrow-up';
import Box from '@lucide/svelte/icons/box';
import ChevronDown from '@lucide/svelte/icons/chevron-down';
import ChevronRight from '@lucide/svelte/icons/chevron-right';
Expand Down Expand Up @@ -34,6 +35,7 @@

export const Icons = {
arrowLeft: ArrowLeft,
arrowUp: ArrowUp,
chevronRight: ChevronRight,
chevronDown: ChevronDown,
external: ExternalLink,
Expand Down
28 changes: 28 additions & 0 deletions src/lib/features/feed/components/article.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@
import { formatDate } from '$lib/utils/date.js';
import { isSafeUrl, sanitizeHtml } from '$lib/utils/sanitize';

const SCROLL_THRESHOLD = 500;

type ArticleProps = {
article: Article;
};

let { article }: ArticleProps = $props();

let showBackToTop = $state(hasScrolled());

function hasScrolled() {
return window.scrollY > SCROLL_THRESHOLD;
}

function handleScroll() {
showBackToTop = hasScrolled();
}

function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
</script>

<svelte:window on:scroll={handleScroll} />

<article class="mx-auto max-w-3xl space-y-8 px-4 py-8">
<a href={resolve('/')} class="btn mb-8">
<Icons.arrowLeft class="mr-1" />
Expand Down Expand Up @@ -65,4 +83,14 @@
<Text>Original article link is unavailable.</Text>
{/if}
</div>

{#if showBackToTop}
<button
class="btn fixed right-2 bottom-2 z-50 btn-square shadow-lg btn-xl btn-primary sm:right-6 sm:bottom-6"
onclick={scrollToTop}
aria-label="Back to top"
>
<Icons.arrowUp />
</button>
{/if}
</article>
Loading