fix site scrolling
This commit is contained in:
parent
b0b463bea6
commit
f90270bc24
|
@ -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}
|
||||
<button
|
||||
id={tag}
|
||||
on:click|preventDefault={() => {
|
||||
if (tags.includes(tag)) {
|
||||
tags = tags.filter(tagName => tagName != tag);
|
||||
} else {
|
||||
tags = [...tags, tag];
|
||||
}
|
||||
const recentFeedSection = document.getElementById('recent-feed');
|
||||
if (recentFeedSection) {
|
||||
recentFeedSection.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}}
|
||||
on:click={() => handleTagClick(tag)}
|
||||
class:!btn-secondary={tags.includes(tag)}
|
||||
class:shadow-lg={tags.includes(tag)}
|
||||
class="btn btn-sm btn-ghost normal-case border-dotted border-base-content/20 border-2 mt-4 mb-8 xl:m-0 whitespace-nowrap">
|
||||
|
|
Loading…
Reference in New Issue