From f25fe61f38fc13d8b9bc745f67b9526027b6a382 Mon Sep 17 00:00:00 2001 From: "Sakith B." Date: Mon, 18 Aug 2025 14:33:31 +0530 Subject: [PATCH 01/38] ui --- .../src/routes/app/(reader)/+layout.svelte | 106 +++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/app/(reader)/+layout.svelte b/frontend/src/routes/app/(reader)/+layout.svelte index 9e2b077..acc9dcd 100644 --- a/frontend/src/routes/app/(reader)/+layout.svelte +++ b/frontend/src/routes/app/(reader)/+layout.svelte @@ -1,7 +1,8 @@ - -{#if iconUrl} - -{/if} - - diff --git a/frontend/src/lib/actions/collectionsActions.ts b/frontend/src/lib/actions/collectionsActions.ts new file mode 100644 index 0000000..c299ce1 --- /dev/null +++ b/frontend/src/lib/actions/collectionsActions.ts @@ -0,0 +1,19 @@ +import type { Collection } from '$lib/types'; +import api from '../api'; + +export async function getCollections() { + const res = await api.get('/collections'); + return res.collections as Collection[]; +} + +export async function getCollectionBySlug(slug: string) { + const res = await api.get(`/collections/${slug}`); + return res.collection as Collection; +} + +export async function createCollection(name: string, isPublic: boolean) { + const res = await api.post('/collections', { name, is_public: isPublic }); + return res.collection as Collection; +} + + diff --git a/frontend/src/lib/actions/initActions.ts b/frontend/src/lib/actions/initActions.ts new file mode 100644 index 0000000..17ed23f --- /dev/null +++ b/frontend/src/lib/actions/initActions.ts @@ -0,0 +1,11 @@ +import type { Collection } from '$lib/types'; +import api from '../api'; + +export async function init() { + const res = await api.get('/init'); + return { + collections: res.collections as Collection[] + }; +} + + diff --git a/frontend/src/lib/actions/publicationsActions.ts b/frontend/src/lib/actions/publicationsActions.ts new file mode 100644 index 0000000..b5af2b3 --- /dev/null +++ b/frontend/src/lib/actions/publicationsActions.ts @@ -0,0 +1,12 @@ +import type { Publication } from '$lib/types'; +import api from '../api'; + +export async function addPublication(collectionSlug: string, url: string) { + const res = await api.post('/publications', { + collection_slug: collectionSlug, + url + }); + return res.publication as Publication; +} + + diff --git a/frontend/src/routes/app/types.ts b/frontend/src/lib/types.ts similarity index 100% rename from frontend/src/routes/app/types.ts rename to frontend/src/lib/types.ts index a2c28f4..9e9c35b 100644 --- a/frontend/src/routes/app/types.ts +++ b/frontend/src/lib/types.ts @@ -1,4 +1,3 @@ - export interface Collection { id: number; name: string; @@ -39,3 +38,4 @@ export interface Item { word_count?: number; } + diff --git a/frontend/src/routes/app/(reader)/+layout.svelte b/frontend/src/routes/app/(reader)/+layout.svelte index cfa6800..7dbe5f6 100644 --- a/frontend/src/routes/app/(reader)/+layout.svelte +++ b/frontend/src/routes/app/(reader)/+layout.svelte @@ -15,8 +15,9 @@ } from '../appStore'; import { goto } from '$app/navigation'; import { page } from '$app/stores'; - import type { Collection, Publication, Item } from '../types'; + import type { Collection, Publication, Item } from '$lib/types'; import { onMount, tick } from 'svelte'; + import { toast } from '@hyvor/design/components'; import api from '$lib/api'; import ArticleView from '../ArticleView.svelte'; @@ -52,9 +53,9 @@ collectionName = ''; collectionIsPublic = false; goto(`/app/${created.slug}`); - } catch (e) { - console.error('Failed to create collection', e); - } + } catch (e) { + toast.error(e instanceof Error ? e.message : 'Failed to create collection'); + } } function selectPublication(publication?: Publication) { @@ -140,10 +141,10 @@ addingPublication = true; addPublicationError = null; const collectionSlug = $selectedCollection?.slug; - if (!collectionSlug) { - console.error('No collection selected'); - return; - } + if (!collectionSlug) { + toast.error('No collection selected'); + return; + } const res = await api.post('/publications', { collection_slug: collectionSlug, url: value, @@ -154,9 +155,9 @@ } showAddPublicationModal = false; rssUrl = ''; - } catch (e) { - console.error('Failed to add publication', e); - addPublicationError = e instanceof Error ? e.message : 'Failed to add publication'; + } catch (e) { + addPublicationError = e instanceof Error ? e.message : 'Failed to add publication'; + toast.error(addPublicationError); } finally { addingPublication = false; } @@ -169,9 +170,9 @@ try { const res = await api.get('/init'); $collections = res.collections; - } catch (e) { - console.error('Initialization failed', e); - } finally { + } catch (e) { + toast.error(e instanceof Error ? e.message : 'Initialization failed'); + } finally { $loadingInit = false; } }); diff --git a/frontend/src/routes/app/(reader)/[collection_slug]/+layout.svelte b/frontend/src/routes/app/(reader)/[collection_slug]/+layout.svelte index 89d4513..1fb374d 100644 --- a/frontend/src/routes/app/(reader)/[collection_slug]/+layout.svelte +++ b/frontend/src/routes/app/(reader)/[collection_slug]/+layout.svelte @@ -9,6 +9,7 @@ selectedPublication, loadingPublications } from '../../appStore'; + import { toast } from '@hyvor/design/components'; let { children } = $props(); let lastFetchedSlug: string | null = null; @@ -26,7 +27,6 @@ if (!collection || collection.slug === lastFetchedSlug) return; lastFetchedSlug = collection.slug; - console.log("Fetching publications for collection:", collection.slug); loadingPublications.set(true); try { @@ -34,7 +34,7 @@ publications.set(res.publications); selectedPublication.set(null); } catch (e) { - console.error('Failed to fetch publications:', e); + toast.error(e instanceof Error ? e.message : 'Failed to fetch publications'); } finally { loadingPublications.set(false); } diff --git a/frontend/src/routes/app/(reader)/[collection_slug]/[[publication_slug]]/+page.svelte b/frontend/src/routes/app/(reader)/[collection_slug]/[[publication_slug]]/+page.svelte index 124f7db..e117f60 100644 --- a/frontend/src/routes/app/(reader)/[collection_slug]/[[publication_slug]]/+page.svelte +++ b/frontend/src/routes/app/(reader)/[collection_slug]/[[publication_slug]]/+page.svelte @@ -1,6 +1,7 @@ @@ -183,11 +210,22 @@
+
+ { + showSidebarMobile = true; + }} + > + + +
{#if $loadingInit} {:else} - + {#snippet trigger()}
{$selectedCollection?.name || 'Select Collection'} @@ -195,7 +233,7 @@
{/snippet} {#snippet content()} - + {#each $collections as collection} {/each} +
-
+
- {#if $loadingPublications} -
- -
- {:else} - - {#each $publications as publication} + {#if $loadingPublications} +
+ +
+ {:else} - {/each} - {/if} + {#each $publications as publication} + + {/each} + {/if}
{#if selectedItem} - {#if item.image} {/if} @@ -359,39 +395,46 @@ {/if}
+ +
{ + showSidebarMobile = false; + }} + >
{ showCreateCollectionModal = false; }} - on:confirm={handleCreateCollection} + bind:show={showCreateCollectionModal} + size="small" + title="Create Collection" + closeOnOutsideClick={true} + closeOnEscape={true} + footer={{ + cancel: { text: 'Cancel', props: { color: 'input' } }, + confirm: { text: 'Create', props: { disabled: !collectionName.trim() } } + }} + on:cancel={() => { + showCreateCollectionModal = false; + }} + on:confirm={handleCreateCollection} > - + diff --git a/frontend/src/routes/app/ArticleView.svelte b/frontend/src/routes/app/ArticleView.svelte index 20f958b..d079b76 100644 --- a/frontend/src/routes/app/ArticleView.svelte +++ b/frontend/src/routes/app/ArticleView.svelte @@ -1,5 +1,5 @@