diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 1bcd0c9..390f5e2 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -21,6 +21,23 @@ storedTitle.set('') + + function handleTagClick(tag) { + if (tags.includes(tag)) { + tags = tags.filter(tagName => tagName !== tag); + } else { + tags = [...tags, tag]; + } + scrollToRecentFeed(); + } + + function scrollToRecentFeed() { + const recentFeedSection = document.getElementById('recent-feed'); + if (recentFeedSection) { + recentFeedSection.scrollIntoView({ behavior: 'smooth' }); + } + } + $: storedPosts.subscribe(storedPosts => (allPosts = storedPosts.filter(post => !post.flags?.includes('unlisted')))) $: storedTags.subscribe(storedTags => (allTags = storedTags as string[])) @@ -29,13 +46,9 @@ $: if (tags) { posts = !tags ? allPosts : allPosts.filter(post => tags.every(tag => post.tags?.includes(tag))) - if (browser) { - const newUrl = tags.length > 0 ? `/?tags=${tags.toString()}#recent-feed` : '/#recent-feed'; + if (loaded && browser) { + const newUrl = `/?tags=${tags.toString()}`; history.pushState(null, '', newUrl); - const recentFeedSection = document.getElementById('recent-feed'); - if (recentFeedSection) { - recentFeedSection.scrollIntoView({ behavior: 'smooth' }); - } } } @@ -79,17 +92,7 @@ {#each allTags as tag}