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);