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/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/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/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/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/FeedPost.svelte b/src/lib/FeedPost.svelte index 728b811..8b0f0aa 100644 --- a/src/lib/FeedPost.svelte +++ b/src/lib/FeedPost.svelte @@ -1,25 +1,68 @@ - -

- {title} -

- - -
- +
+
+

+ {title} +

+ +
+ +
+
- +
diff --git a/src/lib/FullPost.svelte b/src/lib/FullPost.svelte index 82a2dba..f3a6e63 100644 --- a/src/lib/FullPost.svelte +++ b/src/lib/FullPost.svelte @@ -1,7 +1,5 @@ @@ -34,21 +34,24 @@ let { title, created_at, id, content = '', to } = post;
-
+
+ + +
    {#if me && me.id !== post.author?.id}
  • Report
  • {/if} {#if me && me.id === post.author?.id } -
  • Edit
  • +
  • Edit
  • {/if}
+ + {#snippet left()} {#if to.type === 'guild'} @@ -74,13 +77,13 @@ let { title, created_at, id, content = '', to } = post; overflow-x: auto; } .post-body { - margin-inline-start: 3em; + margin-inline-start: 2em; } .message-stats { position: absolute; inset-inline-start: 0; top: 0; - width: 3em; + width: 2em; display: flex; flex-direction: column; justify-content: flex-start; diff --git a/src/lib/GuildAbout.svelte b/src/lib/GuildAbout.svelte index 8d5c569..8be9b0f 100644 --- a/src/lib/GuildAbout.svelte +++ b/src/lib/GuildAbout.svelte @@ -9,7 +9,6 @@ let { guild }: { guild: GuildEntry } = $props(); - {#if guild}
    @@ -21,4 +20,4 @@ let { guild }: { guild: GuildEntry } = $props(); {/if}
-{/if} \ No newline at end of file +{/if} 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/MetaNav.svelte b/src/lib/MetaNav.svelte index 9b9d224..94a1d01 100644 --- a/src/lib/MetaNav.svelte +++ b/src/lib/MetaNav.svelte @@ -1,6 +1,6 @@ +{#if me}
  • -
  • -
  • +
  • +
+{/if} 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/backend.ts b/src/lib/backend.ts index 92cbfdb..4953448 100644 --- a/src/lib/backend.ts +++ b/src/lib/backend.ts @@ -29,8 +29,21 @@ export type PostEntry = { title: string, created_at: string, author?: UserEntry | null, - content?: string | null, - to: UserEntry | GuildEntry + content?: string, + to: UserEntry | GuildEntry , + privacy?: number, + votes?: number | null, + my_vote?: 1 | -1 | 0, + comment_count?: number | null +}; + +export type CommentEntry = { + id: string, + parent?: {id: string}, + locked?: boolean, + removed?: number | true, + content?: string, + created_at: string }; export type ServerHealth = { 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/+layout.svelte b/src/routes/+layout.svelte index ff7f53f..7579dd9 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -36,7 +36,7 @@ let colorThemeCls = $derived(`color-scheme-${colorScheme} color-theme-${colorThe - +

{appName()} @@ -54,7 +54,7 @@ let colorThemeCls = $derived(`color-scheme-${colorScheme} color-theme-${colorThe - +

diff --git a/src/routes/create/+page.svelte b/src/routes/create/+page.svelte index 16cb54d..af0029c 100644 --- a/src/routes/create/+page.svelte +++ b/src/routes/create/+page.svelte @@ -1,18 +1,19 @@ @@ -22,34 +23,26 @@

Posting as @{me.username}

- - - + - {#if privacy === 0} Your post will be PUBLIC! {/if} - + {#snippet left()} - ... + {/snippet} {#snippet right()} - ... + {/snippet} {:else} @@ -60,22 +53,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..22d9955 --- /dev/null +++ b/src/routes/edit/[x+3d][id]/+page.svelte @@ -0,0 +1,65 @@ + + + +{#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/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; 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 @@