From 248555f7ad71ce24a7bca5e42e9f1924350b2f29 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Thu, 23 Oct 2025 09:59:18 +0200 Subject: [PATCH 1/6] add /edit stub --- src/app.d.ts | 2 +- src/lib/EditPost.svelte | 35 ++++++++++++++ src/lib/FullPost.svelte | 2 +- src/lib/MetaNav.svelte | 12 ++++- src/lib/backend.ts | 5 +- src/routes/create/+page.svelte | 29 ++--------- src/routes/edit/[x+3d][id]/+page.svelte | 64 +++++++++++++++++++++++++ src/routes/edit/[x+3d][id]/+page.ts | 51 ++++++++++++++++++++ src/routes/search/+page.server.ts | 10 ++-- src/routes/search/+page.svelte | 1 + 10 files changed, 175 insertions(+), 36 deletions(-) create mode 100644 src/lib/EditPost.svelte create mode 100644 src/routes/edit/[x+3d][id]/+page.svelte create mode 100644 src/routes/edit/[x+3d][id]/+page.ts diff --git a/src/app.d.ts b/src/app.d.ts index d49d347..dd01331 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -14,7 +14,7 @@ declare global { site: ServerHealth | null, me: UserEntry | null, results?: object[], - query?: string + query?: string, } // interface PageState {} // interface Platform {} diff --git a/src/lib/EditPost.svelte b/src/lib/EditPost.svelte new file mode 100644 index 0000000..ba0c397 --- /dev/null +++ b/src/lib/EditPost.svelte @@ -0,0 +1,35 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/lib/FullPost.svelte b/src/lib/FullPost.svelte index 82a2dba..5f09f3d 100644 --- a/src/lib/FullPost.svelte +++ b/src/lib/FullPost.svelte @@ -43,7 +43,7 @@ let { title, created_at, id, content = '', to } = post;
  • Report
  • {/if} {#if me && me.id === post.author?.id } -
  • Edit
  • +
  • Edit
  • {/if} diff --git a/src/lib/MetaNav.svelte b/src/lib/MetaNav.svelte index 9b9d224..b9df7aa 100644 --- a/src/lib/MetaNav.svelte +++ b/src/lib/MetaNav.svelte @@ -1,6 +1,6 @@ @@ -22,20 +21,12 @@

    Posting as @{me.username}

    - - - + - {#if privacy === 0} Your post will be PUBLIC! {/if} @@ -60,22 +51,10 @@ \ No newline at end of file diff --git a/src/routes/edit/[x+3d][id]/+page.svelte b/src/routes/edit/[x+3d][id]/+page.svelte new file mode 100644 index 0000000..f86b364 --- /dev/null +++ b/src/routes/edit/[x+3d][id]/+page.svelte @@ -0,0 +1,64 @@ + + + +{#if me?.id === post.author?.id} + +
    +

    Posting as @{me?.username}

    + + + + + + {#if privacy === 0} + Your post will be PUBLIC! + {/if} + + + + + + {#snippet left()} + ... + {/snippet} + + {#snippet right()} + ... + {/snippet} +
    +{:else if me} + You can't edit posts that are not your own. +{:else} + + You must be logged in in order to edit your own posts. + +{/if} + + \ No newline at end of file diff --git a/src/routes/edit/[x+3d][id]/+page.ts b/src/routes/edit/[x+3d][id]/+page.ts new file mode 100644 index 0000000..2ab8998 --- /dev/null +++ b/src/routes/edit/[x+3d][id]/+page.ts @@ -0,0 +1,51 @@ +import { backend, type GuildEntry } from '$lib/backend.js'; +import { getMe } from '$lib/globals.svelte'; +import { error, isHttpError, redirect } from '@sveltejs/kit'; + +export async function load(event) { + + const { params } = event; + const { id } = params; + + const resp = await backend.withEvent(event).fetch('post/' + encodeURIComponent(id)); + + if(resp.status === 404) { + error(404); + } + + let post; + + try{ + const respJ = await resp.json(); + + let { posts } = respJ; + post = posts[id]; + + let me = getMe(); + + if (!me) { + redirect(303, "/login?next=" + encodeURIComponent(event.url.pathname)); + } + if ( post.author.id !== me?.id) { + error(403); + } + + if (post?.to && post.to.type === 'guild') { + const guild: GuildEntry = post.to; + const guildResp = await backend.withEvent(event).fetch('guild/' + encodeURIComponent(guild.id)); + const guildJson = await guildResp.json(); + const guildInfo = guildJson?.guilds?.[guild.id]; + guildInfo.type = 'guild'; + post.to = guildInfo || guild; + console.log(post.to); + } + + } catch (e) { + if (isHttpError(e)) throw e; + + console.error(e); + error(502); + } + + return post; +} \ No newline at end of file diff --git a/src/routes/search/+page.server.ts b/src/routes/search/+page.server.ts index 7234839..4ec3ad5 100644 --- a/src/routes/search/+page.server.ts +++ b/src/routes/search/+page.server.ts @@ -32,14 +32,12 @@ export const actions = { event.locals.results = results; event.locals.query = query; console.log(event.locals); - return } } satisfies Actions; -export async function load (event) { - const { results, query } = event.locals; - - console.log({ results, query }); - return { results, query }; +export function load (event) { + const { results, query } = event.locals; + + return { results, query }; } diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte index 379e2d5..144ebfb 100644 --- a/src/routes/search/+page.svelte +++ b/src/routes/search/+page.svelte @@ -6,6 +6,7 @@ import type { PageProps } from "./$types"; let { data }: PageProps = $props(); + console.log(data); let { query, results } = $derived(data); From 11deee34a71bc9cced387c51c06ebdb8cdd8b901 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Thu, 23 Oct 2025 11:08:14 +0200 Subject: [PATCH 2/6] make upvotes work --- src/lib/FeedPost.svelte | 63 +++++++++++++++++++++++++++++++-------- src/lib/FullPost.svelte | 8 ++--- src/lib/VoteButton.svelte | 42 +++++++++++++++++++++----- src/lib/backend.ts | 5 +++- 4 files changed, 93 insertions(+), 25 deletions(-) diff --git a/src/lib/FeedPost.svelte b/src/lib/FeedPost.svelte index 728b811..e05016f 100644 --- a/src/lib/FeedPost.svelte +++ b/src/lib/FeedPost.svelte @@ -1,25 +1,62 @@ - -

    - {title} -

    - - -
    - + diff --git a/src/lib/FullPost.svelte b/src/lib/FullPost.svelte index 5f09f3d..93a3f5a 100644 --- a/src/lib/FullPost.svelte +++ b/src/lib/FullPost.svelte @@ -18,7 +18,7 @@ let { post }: { post: PostEntry } = $props(); let me = getMe(); -let { title, created_at, id, content = '', to } = post; +let { title, id, content = '', to, votes, my_vote } = post; @@ -34,10 +34,10 @@ let { title, created_at, id, content = '', to } = post;
    -
    +
    + +
      {#if me && me.id !== post.author?.id}
    • Report
    • diff --git a/src/lib/VoteButton.svelte b/src/lib/VoteButton.svelte index 56e5ac5..4d0c644 100644 --- a/src/lib/VoteButton.svelte +++ b/src/lib/VoteButton.svelte @@ -1,31 +1,46 @@
      {#if vote > 0} - {:else} - {/if} {score ?? '-'} - {#if vote > 0} - {:else} - {/if} @@ -37,5 +52,18 @@ let { score } : { score?: number | null } = $props(); flex-direction: column; align-items: center; } + + button.inline { + color: var(--border); + } + button.inline.up { + color: var(--accent); + } + button.inline.down { + color: var(--c11-accent); + } + :global(.color-theme-11) button.inline.down, :global(.color-theme-9) button.inline.down { + color: var(--c14-accent); + } diff --git a/src/lib/backend.ts b/src/lib/backend.ts index 2397fee..d840175 100644 --- a/src/lib/backend.ts +++ b/src/lib/backend.ts @@ -31,7 +31,10 @@ export type PostEntry = { author?: UserEntry | null, content?: string, to: UserEntry | GuildEntry , - privacy?: number + privacy?: number, + votes?: number | null, + my_vote?: 1 | -1 | 0, + comment_count?: number | null }; export type ServerHealth = { From da1c2809d98885fd476308e7fa5c148ad1fd97a4 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Thu, 23 Oct 2025 12:57:04 +0200 Subject: [PATCH 3/6] add CommentCount --- src/lib/CommentCount.svelte | 24 ++++++++++++++++++++++++ src/lib/FeedPost.svelte | 8 +++++++- src/lib/FullPost.svelte | 6 +++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/lib/CommentCount.svelte diff --git a/src/lib/CommentCount.svelte b/src/lib/CommentCount.svelte new file mode 100644 index 0000000..a4f5ea1 --- /dev/null +++ b/src/lib/CommentCount.svelte @@ -0,0 +1,24 @@ + + + +
      + + {count??'-'} +
      + + \ No newline at end of file diff --git a/src/lib/FeedPost.svelte b/src/lib/FeedPost.svelte index e05016f..a0b0d51 100644 --- a/src/lib/FeedPost.svelte +++ b/src/lib/FeedPost.svelte @@ -3,9 +3,10 @@ import PostMeta from "./PostMeta.svelte"; import { SvelteShowdown } from "svelte-showdown"; import VoteButton from "./VoteButton.svelte"; + import CommentCount from "./CommentCount.svelte"; let { post }: { post: PostEntry } = $props(); -let { id, title, content = "", votes, my_vote } = post; +let { id, title, content = "", votes, my_vote, comment_count } = post; @@ -20,6 +21,7 @@ let { id, title, content = "", votes, my_vote } = post;
      @@ -40,6 +42,10 @@ let { id, title, content = "", votes, my_vote } = post; align-items: center; } + .post-title { + line-height: 1.2; + } + .shorten { max-height: 18em; overflow-y: hidden; diff --git a/src/lib/FullPost.svelte b/src/lib/FullPost.svelte index 93a3f5a..3acff12 100644 --- a/src/lib/FullPost.svelte +++ b/src/lib/FullPost.svelte @@ -12,13 +12,14 @@ import { SvelteShowdown } from "svelte-showdown"; import VoteButton from "./VoteButton.svelte"; import { getMe } from "./globals.svelte"; + import CommentCount from "./CommentCount.svelte"; let { post }: { post: PostEntry } = $props(); let me = getMe(); -let { title, id, content = '', to, votes, my_vote } = post; +let { title, id, content = '', to, votes, my_vote, comment_count } = post; @@ -37,6 +38,7 @@ let { title, id, content = '', to, votes, my_vote } = post;
        {#if me && me.id !== post.author?.id} @@ -49,6 +51,8 @@ let { title, id, content = '', to, votes, my_vote } = post; + + {#snippet left()} {#if to.type === 'guild'} From 599075219f60a7aa08a875ad36e04e65e3079369 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Thu, 23 Oct 2025 15:43:00 +0200 Subject: [PATCH 4/6] add comment section stub --- src/lib/CommentSection.svelte | 16 ++++++++++++++++ src/lib/FeedPost.svelte | 2 +- src/lib/FullPost.svelte | 7 ++++--- src/lib/GuildAbout.svelte | 3 +-- src/lib/backend.ts | 9 +++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/lib/CommentSection.svelte diff --git a/src/lib/CommentSection.svelte b/src/lib/CommentSection.svelte new file mode 100644 index 0000000..9f6955a --- /dev/null +++ b/src/lib/CommentSection.svelte @@ -0,0 +1,16 @@ + + +{#if comments === null} + + + +{/if} \ No newline at end of file diff --git a/src/lib/FeedPost.svelte b/src/lib/FeedPost.svelte index a0b0d51..8b0f0aa 100644 --- a/src/lib/FeedPost.svelte +++ b/src/lib/FeedPost.svelte @@ -28,7 +28,7 @@ let { id, title, content = "", votes, my_vote, comment_count } = post; diff --git a/src/routes/login/+page.server.ts b/src/routes/login/+page.server.ts index 25752ae..8f9053c 100644 --- a/src/routes/login/+page.server.ts +++ b/src/routes/login/+page.server.ts @@ -5,7 +5,6 @@ import { redirect } from 'sveltekit-flash-message/server'; export const actions = { default: async (event) => { - // TODO login const { request } = event; From 80ecfd67471527843e29329cbd51d85c923427a3 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Sat, 1 Nov 2025 09:51:41 +0100 Subject: [PATCH 6/6] improve guild selection, add Wip --- package.json | 2 +- src/lib/GuildSelect.svelte | 2 +- src/lib/Wip.svelte | 8 ++++++++ src/lib/globals.svelte.ts | 2 -- src/routes/create/+page.svelte | 12 +++++++----- src/routes/edit/[x+3d][id]/+page.svelte | 5 +++-- src/routes/register/+page.svelte | 3 ++- 7 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/lib/Wip.svelte diff --git a/package.json b/package.json index b081e66..1850e2d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@yusurko/vigil", "private": true, - "version": "0.1.0-dev42", + "version": "0.1.0-dev43", "type": "module", "scripts": { "dev": "vite dev", diff --git a/src/lib/GuildSelect.svelte b/src/lib/GuildSelect.svelte index ddf41ae..529ad08 100644 --- a/src/lib/GuildSelect.svelte +++ b/src/lib/GuildSelect.svelte @@ -2,7 +2,7 @@ import { backend, type GuildEntry } from "./backend"; -let value = $state(""); +let { value = $bindable("") } = $props(); let suggestions: Promise = $derived(getSuggestions(value)); diff --git a/src/lib/Wip.svelte b/src/lib/Wip.svelte new file mode 100644 index 0000000..0913a74 --- /dev/null +++ b/src/lib/Wip.svelte @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/src/lib/globals.svelte.ts b/src/lib/globals.svelte.ts index 984b82f..622dbf3 100644 --- a/src/lib/globals.svelte.ts +++ b/src/lib/globals.svelte.ts @@ -22,8 +22,6 @@ export function setHealth ({ name, version, post_count, user_count, color_theme health.color_theme = color_theme; } - - export function setMe (me: UserEntry | null) { health.me = me; } diff --git a/src/routes/create/+page.svelte b/src/routes/create/+page.svelte index ca13396..af0029c 100644 --- a/src/routes/create/+page.svelte +++ b/src/routes/create/+page.svelte @@ -4,14 +4,16 @@ import { getMe } from "$lib/globals.svelte"; import GuildSelect from "$lib/GuildSelect.svelte"; import SLayout from "$lib/SLayout.svelte"; + import Wip from "$lib/Wip.svelte"; import { RiErrorWarningLine } from "svelte-remixicon"; let me = getMe(); let content = $state(""); let privacy = $state(0); + let guildName = $state(""); - + let enablePost = $derived(!!content && !!guildName && false); @@ -22,7 +24,7 @@ @@ -31,16 +33,16 @@ Your post will be PUBLIC! {/if} - + {#snippet left()} - ... + {/snippet} {#snippet right()} - ... + {/snippet} {:else} diff --git a/src/routes/edit/[x+3d][id]/+page.svelte b/src/routes/edit/[x+3d][id]/+page.svelte index f86b364..22d9955 100644 --- a/src/routes/edit/[x+3d][id]/+page.svelte +++ b/src/routes/edit/[x+3d][id]/+page.svelte @@ -5,6 +5,7 @@ import { getMe } from "$lib/globals.svelte"; import GuildSelect from "$lib/GuildSelect.svelte"; import SLayout from "$lib/SLayout.svelte"; + import Wip from "$lib/Wip.svelte"; import { RiErrorWarningLine } from "svelte-remixicon"; let me = getMe(); @@ -38,11 +39,11 @@ {#snippet left()} - ... + {/snippet} {#snippet right()} - ... + {/snippet} {:else if me} diff --git a/src/routes/register/+page.svelte b/src/routes/register/+page.svelte index 4195c82..b1e61cc 100644 --- a/src/routes/register/+page.svelte +++ b/src/routes/register/+page.svelte @@ -1,6 +1,7 @@