add guild info in post, report and edit button

This commit is contained in:
Yusur 2025-10-11 20:14:07 +02:00
parent cd92a4b12e
commit c33ab48225
4 changed files with 27 additions and 7 deletions

View file

@ -1,7 +1,7 @@
<script lang="ts">
import { DateTime } from "luxon";
import { RiHistoryLine, RiHome2Line, RiUserLine } from "svelte-remixicon";
import { RiEditLine, RiFlagLine, RiHistoryLine, RiHome2Line, RiUserLine } from "svelte-remixicon";
import type { PostEntry } from "./backend";
import SLayout from "./SLayout.svelte";
import GuildAbout from "./GuildAbout.svelte";
@ -11,10 +11,13 @@
import GuildMenu from "./GuildMenu.svelte";
import { SvelteShowdown } from "svelte-showdown";
import VoteButton from "./VoteButton.svelte";
import { getMe } from "./globals.svelte";
let { post }: { post: PostEntry } = $props();
let me = getMe();
let { title, created_at, id, content = '', to } = post;
</script>
@ -36,6 +39,12 @@ let { title, created_at, id, content = '', to } = post;
<VoteButton />
</div>
<ul class="message-options row">
{#if me && me.id !== post.author?.id}
<li><a href="/report/post/{id}"><RiFlagLine/> Report</a></li>
{/if}
{#if me && me.id === post.author?.id }
<li><a href="/edit/post/{id}"><RiEditLine/> Edit</a></li>
{/if}
</ul>
</div>
</article>

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { RiHashtag, RiHistoryLine, RiUserLine } from "svelte-remixicon";
import { RiHistoryLine, RiShieldCrossLine, RiUserLine } from "svelte-remixicon";
import type { PostEntry } from "./backend";
import { DateTime } from "luxon";
@ -10,7 +10,7 @@ let { post } : {post: PostEntry }= $props();
{#if post.author}<a href="/@{post.author.username}">@{post.author.username}</a>
{:else}<i>Someone</i>{/if}</li>
{#if post.to.type == 'guild'}
<li><RiHashtag /> <a href="/+{post.to.name}">+{post.to.name}</a></li>
<li><RiShieldCrossLine /> <a href="/+{post.to.name}">+{post.to.name}</a></li>
{/if}
<li><RiHistoryLine /> <time datetime={post.created_at}>{ DateTime.fromISO(post.created_at).toFormat('d LLL yyyy') }</time></li>
</ul>

View file

@ -1,12 +1,11 @@
import { backend } from '$lib/backend.js';
import { backend, type GuildEntry } from '$lib/backend.js';
import { error } from '@sveltejs/kit';
export async function load(event) {
const { params } = event;
const { id } = params;
const resp = await backend.withEvent(event).fetch('post/' + encodeURIComponent(id));
@ -14,18 +13,30 @@ export async function load(event) {
error(404);
}
let post;
try{
const respJ = await resp.json();
let { posts } = respJ;
return posts[id];
post = posts[id];
//return {};
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) {
console.error(e);
error(502);
}
return post;
}

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B