Browse Source

Unbreak pagination

master
Nuša Pukšič 6 months ago committed by buttercat1791
parent
commit
e667cbd3cb
  1. 38
      src/lib/components/Notifications.svelte
  2. 5
      src/lib/components/ZettelEditor.svelte
  3. 32
      src/lib/components/publications/Publication.svelte
  4. 2
      src/lib/components/util/ArticleNav.svelte
  5. 4
      src/routes/new/compose/+page.svelte
  6. 2
      src/routes/profile/notifications/+page.svelte

38
src/lib/components/Notifications.svelte

@ -70,7 +70,7 @@
let allFromMeNotifications = $state<NDKEvent[]>([]); // All fetched "from-me" notifications let allFromMeNotifications = $state<NDKEvent[]>([]); // All fetched "from-me" notifications
let allPublicMessages = $state<NDKEvent[]>([]); // All fetched public messages let allPublicMessages = $state<NDKEvent[]>([]); // All fetched public messages
let currentPage = $state(1); let currentPage = $state(1);
let itemsPerPage = 20; // Show 20 items per page let itemsPerPage = 10; // Show 20 items per page
let hasFetchedToMe = $state(false); // Track if we've already fetched "to-me" data let hasFetchedToMe = $state(false); // Track if we've already fetched "to-me" data
let hasFetchedFromMe = $state(false); // Track if we've already fetched "from-me" data let hasFetchedFromMe = $state(false); // Track if we've already fetched "from-me" data
let hasFetchedPublic = $state(false); // Track if we've already fetched public messages let hasFetchedPublic = $state(false); // Track if we've already fetched public messages
@ -650,27 +650,13 @@
} }
} }
// AI-NOTE: Pagination navigation functions // Pagination navigation
function nextPage() { $effect (() => {
if (hasNextPage) { console.log(`[Pagination] Mode: ${notificationMode}, Current Page: ${currentPage}, Total Pages: ${totalPages}`);
currentPage++;
updateDisplayedItems(); updateDisplayedItems();
} // scroll to top
} window.scrollTo({ top: 0, behavior: 'smooth' });
});
function previousPage() {
if (hasPreviousPage) {
currentPage--;
updateDisplayedItems();
}
}
function goToPage(page: number) {
if (page >= 1 && page <= totalPages) {
currentPage = page;
updateDisplayedItems();
}
}
// AI-NOTE: Update displayed items based on current page // AI-NOTE: Update displayed items based on current page
function updateDisplayedItems() { function updateDisplayedItems() {
@ -845,8 +831,6 @@
</script> </script>
{#if isOwnProfile && $userStore.signedIn} {#if isOwnProfile && $userStore.signedIn}
<div class="mb-6 w-full">
<div class="flex items-center justify-between mb-4">
<Heading tag="h3" class="h-leather">Notifications</Heading> <Heading tag="h3" class="h-leather">Notifications</Heading>
<div class="flex flex-row items-center gap-3"> <div class="flex flex-row items-center gap-3">
@ -873,7 +857,6 @@
{/each} {/each}
</div> </div>
</div> </div>
</div>
{#if loading} {#if loading}
<div class="flex items-center justify-center py-8 min-h-96"> <div class="flex items-center justify-center py-8 min-h-96">
@ -1038,11 +1021,11 @@
{/if} {/if}
{:else} {:else}
{#if notifications.length === 0} {#if notifications.length === 0}
<div class="p-4 bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 rounded-lg"> <AAlert color="blue">
<P>No notifications {notificationMode === "to-me" ? "received" : "sent"} found.</P> <P>No notifications {notificationMode === "to-me" ? "received" : "sent"} found.</P>
</div> </AAlert>
{:else} {:else}
<div class="max-h-[72rem] overflow-y-auto overflow-x-hidden space-y-4"> <div class="space-y-4">
{#each notifications.slice(0, 100) as notification} {#each notifications.slice(0, 100) as notification}
{@const authorProfile = authorProfiles.get(notification.pubkey)} {@const authorProfile = authorProfiles.get(notification.pubkey)}
<div class="message-container p-4 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm"> <div class="message-container p-4 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm">
@ -1147,7 +1130,6 @@
</div> </div>
{/if} {/if}
{/if} {/if}
</div>
<!-- New Message Modal --> <!-- New Message Modal -->
<Modal bind:open={showNewMessageModal} size="lg" class="w-full"> <Modal bind:open={showNewMessageModal} size="lg" class="w-full">

5
src/lib/components/ZettelEditor.svelte

@ -53,7 +53,8 @@
ta.selectionStart = ta.selectionEnd = pos; ta.selectionStart = ta.selectionEnd = pos;
}); });
} }
const newNoteTemplate = `\n== Note Title\n:author: \n:version: 1.0\n:published_on: 2024-01-01\n:published_by: Alexandria\n:summary: \n:tags: \n:image: \n\nNote content here...\n`; const today = new Date().toISOString().split('T')[0];
const newNoteTemplate = `\n== Note Title\n:author: \n:version: 1.0\n:published_on: ${today}\n:published_by: Alexandria\n:summary: \n:tags: \n:image: \n\nNote content here...\n`;
function insertNoteTemplate() { function insertNoteTemplate() {
const ta = getTextarea(); const ta = getTextarea();
if (!ta || ta.disabled) return; if (!ta || ta.disabled) return;
@ -191,7 +192,7 @@
</div> </div>
{:else} {:else}
<!-- Informative text about ZettelEditor purpose --> <!-- Informative text about ZettelEditor purpose -->
<AAlert color="blue" classes="max-w-lg self-center"> <AAlert color="blue" classes="w-full self-center">
{#snippet title()}Note-Taking Tool{/snippet} {#snippet title()}Note-Taking Tool{/snippet}
<p class="text-sm mb-3"> <p class="text-sm mb-3">
This editor is for creating individual notes (30041 events) only. Each section becomes a separate note event. This editor is for creating individual notes (30041 events) only. Each section becomes a separate note event.

32
src/lib/components/publications/Publication.svelte

@ -23,6 +23,7 @@
import type { SveltePublicationTree } from "./svelte_publication_tree.svelte"; import type { SveltePublicationTree } from "./svelte_publication_tree.svelte";
import TableOfContents from "./TableOfContents.svelte"; import TableOfContents from "./TableOfContents.svelte";
import type { TableOfContents as TocType } from "./table_of_contents.svelte"; import type { TableOfContents as TocType } from "./table_of_contents.svelte";
import ArticleNav from "$components/util/ArticleNav.svelte";
let { rootAddress, publicationType, indexEvent, publicationTree, toc } = $props<{ let { rootAddress, publicationType, indexEvent, publicationTree, toc } = $props<{
rootAddress: string; rootAddress: string;
@ -252,25 +253,29 @@
</script> </script>
<!-- Add gap & items-start so sticky sidebars size correctly --> <!-- Add gap & items-start so sticky sidebars size correctly -->
<div class="grid grid-cols-[1fr_3fr_1fr] gap-4 items-start"> <div class="grid gap-4 items-start grid-cols-[1fr_3fr_1fr] grid-rows-[auto_1fr]">
<!-- Full-width ArticleNav row -->
<ArticleNav
publicationType={publicationType}
rootId={indexEvent.id}
indexEvent={indexEvent}
/>
<!-- Three-column row -->
<div class="contents">
<!-- Table of contents --> <!-- Table of contents -->
{#if publicationType !== "blog" && !isLeaf} {#if publicationType !== "blog" && !isLeaf}
<Sidebar <Sidebar
class="z-10 ml-4 bg-transparent sticky top-24 max-h-[calc(100vh-6rem)] overflow-y-auto class="z-10 ml-4 bg-transparent sticky top-[162px] h-[calc(100vh-165px)] overflow-y-auto
border border-s-4 rounded border-primary-200 dark:border-primary-800 border border-s-4 rounded border-primary-200 dark:border-primary-800
dark:bg-primary-1000" dark:bg-primary-1000"
position="static"
activeUrl={`#${activeAddress ?? ""}`} activeUrl={`#${activeAddress ?? ""}`}
classes={{ classes={{
div: 'bg-transparent', /* inner wrapper neutral */ div: 'bg-transparent',
active: 'bg-primary-100 dark:bg-primary-800 p-2 rounded-lg', active: 'bg-primary-100 dark:bg-primary-800 p-2 rounded-lg',
nonactive: 'bg-primary-50 dark:bg-primary-800', nonactive: 'bg-primary-50 dark:bg-primary-800',
}} }}
> >
<CloseButton <SidebarWrapper>
onclick={closeTocSidebar}
class="btn-leather hover:bg-primary-50 dark:hover:bg-primary-800"
/>
<TableOfContents <TableOfContents
{rootAddress} {rootAddress}
{toc} {toc}
@ -282,10 +287,11 @@
} }
}} }}
/> />
</SidebarWrapper>
</Sidebar> </Sidebar>
{/if} {/if}
<div> <div class="mt-[70px]">
<!-- Default publications --> <!-- Default publications -->
{#if $publicationColumnVisibility.main} {#if $publicationColumnVisibility.main}
<!-- Remove overflow-auto so page scroll drives it --> <!-- Remove overflow-auto so page scroll drives it -->
@ -365,9 +371,9 @@
{#if $publicationColumnVisibility.discussion} {#if $publicationColumnVisibility.discussion}
<Sidebar <Sidebar
position="static" class="z-10 ml-4 bg-transparent sticky top-[162px] h-[calc(100vh-165px)] overflow-y-auto
class="sticky top-24 max-h-[calc(100vh-6rem)] overflow-y-auto bg-primary-50 dark:bg-primary-1000 border border-s-4 rounded border-primary-200 dark:border-primary-800
border border-primary-200 dark:border-primary-800 rounded" dark:bg-primary-1000"
> >
<SidebarWrapper> <SidebarWrapper>
<SidebarGroup> <SidebarGroup>
@ -411,5 +417,5 @@
</SidebarWrapper> </SidebarWrapper>
</Sidebar> </Sidebar>
{/if} {/if}
</div>
</div> </div>

2
src/lib/components/util/ArticleNav.svelte

@ -152,7 +152,7 @@
</script> </script>
<nav <nav
class="Navbar navbar-leather flex fixed top-[100px] sm:top-[92px] w-full min-h-[70px] px-2 sm:px-4 py-2.5 z-10 transition-transform duration-300 {isVisible class="Navbar navbar-leather col-span-3 flex fixed top-[100px] sm:top-[92px] w-full min-h-[70px] px-2 sm:px-4 py-2.5 z-10 transition-transform duration-300 {isVisible
? 'translate-y-0' ? 'translate-y-0'
: '-translate-y-full'}" : '-translate-y-full'}"
> >

4
src/routes/new/compose/+page.svelte

@ -130,8 +130,8 @@
<title>Compose Note - Alexandria</title> <title>Compose Note - Alexandria</title>
</svelte:head> </svelte:head>
<!-- Main container with 75% width and centered --> <!-- Main container with max 1024px width and centered -->
<div class="flex flex-col self-center items-center w-full px-2 space-y-4"> <div class="flex flex-col self-center items-center w-full max-w-[1024px] mx-auto px-2 space-y-4">
<Heading <Heading
tag="h1" class="h-leather mb-2"> tag="h1" class="h-leather mb-2">
Compose Notes Compose Notes

2
src/routes/profile/notifications/+page.svelte

@ -4,7 +4,7 @@ import { AAlert } from "$lib/a";
import { userStore } from "$lib/stores/userStore"; import { userStore } from "$lib/stores/userStore";
</script> </script>
<div class="w-full max-w-3xl mx-auto mt-10 px-4"> <div class="flex flex-col w-full max-w-3xl mx-auto px-2 items-center gap-4">
{#if $userStore?.signedIn} {#if $userStore?.signedIn}
<Notifications /> <Notifications />
{:else} {:else}

Loading…
Cancel
Save