feat [3/3]: add topic viewing

This commit is contained in:
James Xylight authored and xylight committed 2025-09-17 00:27:11 +00:00
1 parent a82d8c296d
commit fda8e5fb37
9 files changed
+71 -43

No files matched your search

+15 -15
View File
@@ -1,17 +1,17 @@
{ {
"arrowParens": "always", "arrowParens": "always",
"tabWidth": 2, "tabWidth": 2,
"semi": false, "semi": false,
"singleQuote": true, "singleQuote": true,
"htmlWhitespaceSensitivity": "css", "htmlWhitespaceSensitivity": "ignore",
"plugins": ["prettier-plugin-svelte"], "plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }], "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
"trailingComma": "all", "trailingComma": "all",
"bracketSameLine": false, "bracketSameLine": false,
"svelteAllowShorthand": true, "svelteAllowShorthand": true,
"svelteBracketNewLine": true, "svelteBracketNewLine": true,
"svelteIndentScriptAndStyle": true, "svelteIndentScriptAndStyle": true,
"svelteSortOrder": "scripts-options-markup-styles", "svelteSortOrder": "scripts-options-markup-styles",
"svelteStrictMode": false, "svelteStrictMode": false,
"useTabs": false "useTabs": false
} }
@@ -61,6 +61,7 @@
content: i.flair_title, content: i.flair_title,
color: i.background_color, color: i.background_color,
icon: null, icon: null,
type: 'flair' as 'flair' | 'custom',
})) ?? []), })) ?? []),
], ],
} }
@@ -9,4 +9,4 @@
let { post }: Props = $props() let { post }: Props = $props()
</script> </script>
<Post {post} class="py-0!" /> <Post {post} />
+22 -12
View File
@@ -12,12 +12,14 @@
content: string content: string
color?: string color?: string
icon?: IconSource | null icon?: IconSource | null
textColor?: string
type: 'flair' | 'custom'
} }
export const textToTag: Map<string, Tag> = new Map<string, Tag>([ export const textToTag: Map<string, Tag> = new Map<string, Tag>([
['OC', { content: 'OC', color: '#03A8F240' }], ['OC', { content: 'OC', color: '#03A8F240', type: 'custom' }],
['NSFL', { content: 'NSFL', color: '#ff000040' }], ['NSFL', { content: 'NSFL', color: '#ff000040', type: 'custom' }],
['CW', { content: 'CW', color: '#ff000040' }], ['CW', { content: 'CW', color: '#ff000040', type: 'custom' }],
]) ])
export const parseTags = ( export const parseTags = (
@@ -38,6 +40,7 @@
extracted.push( extracted.push(
textToTag.get(content) ?? { textToTag.get(content) ?? {
content: content, content: content,
type: 'custom',
}, },
) )
}) })
@@ -308,28 +311,34 @@
{/if} {/if}
</div> </div>
<div <div
class="flex flex-row min-sm:justify-end items-center self-center class="flex flex-row min-sm:justify-end items-center self-center flex-wrap gap-2 *:shrink-0 badges min-sm:ml-2"
flex-wrap gap-2 *:shrink-0 badges min-sm:ml-2"
style="grid-area: badges;" style="grid-area: badges;"
> >
{#if tags} {#if tags}
{#each tags as tag} {#each tags as tag}
<a {@const href =
tag.type == 'flair'
? null
: `/search?community=${community?.id}&q=[${tag.content}]&type=Posts`}
<svelte:element
this={href ? 'a' : 'div'}
{href}
class="hover:brightness-110" class="hover:brightness-110"
href="/search?community={community?.id}&q=[{tag.content}]&type=Posts" style="{tag.color ? `--tag-color: ${tag.color};` : ''} {tag.textColor
style={tag.color ? `--tag-color: ${tag.color};` : ''} ? `--tag-text-color: ${tag.textColor}`
: ''}"
> >
<Badge class={tag.color ? 'badge-tag-color' : ''}> <Badge class={tag.color ? 'badge-tag-color' : ''}>
{#snippet icon()} {#snippet icon()}
{#if tag.icon} {#if tag.icon}
<Icon src={tag.icon} micro size="14" /> <Icon src={tag.icon} micro size="14" />
{:else if tag !== null} {:else if tag === undefined}
<Icon src={Tag} micro size="14" /> <Icon src={Tag} micro size="14" />
{/if} {/if}
{/snippet} {/snippet}
{tag.content} {tag.content}
</Badge> </Badge>
</a> </svelte:element>
{/each} {/each}
{/if} {/if}
{#each Object.keys(badges) {#each Object.keys(badges)
@@ -339,8 +348,8 @@
.map((i) => badgeToData.get(i as BadgeType)) .map((i) => badgeToData.get(i as BadgeType))
// remove null // remove null
.filter((i) => i != undefined) as badge} .filter((i) => i != undefined) as badge}
<Badge label={badge.label} color={badge.color} allowIconOnly <Badge label={badge.label} color={badge.color} allowIconOnly>
>{#snippet icon()} {#snippet icon()}
<Icon src={badge.icon} micro size="14" />{/snippet}{badge.label} <Icon src={badge.icon} micro size="14" />{/snippet}{badge.label}
</Badge> </Badge>
{/each} {/each}
@@ -420,5 +429,6 @@
:global(.badge-tag-color) { :global(.badge-tag-color) {
background-color: var(--tag-color) !important; background-color: var(--tag-color) !important;
color: var(--tag-text-color, #000) !important;
} }
</style> </style>
@@ -142,7 +142,9 @@
{/if} {/if}
{/if} {/if}
{#if user.flair} {#if user.flair}
<Badge color="blue-subtle" class="px-1.5! py-0.5!">{user.flair}</Badge> <Badge color="blue-subtle" class="px-1.5! py-0.5! whitespace-nowrap">
{user.flair}
</Badge>
{/if} {/if}
{@render extraBadges?.()} {@render extraBadges?.()}
{/if} {/if}
+7 -7
View File
@@ -54,13 +54,13 @@
<span <span
{...rest} {...rest}
class="{allowIconOnly class={[
? 'max-md:px-1.5 max-md:py-1.5' allowIconOnly && 'max-md:px-1.5 max-md:py-1.5',
: ''} px-2 py-1 {badgeRoundness[ 'text-xs font-medium flex items-center gap-1 ring-1 ring-inset px-2 py-1',
rounding badgeRoundness[rounding],
]} text-xs font-medium flex items-center gap-1 ring-1 ring-inset {badgeColor[ badgeColor[color],
color clazz,
]} {clazz}" ]}
title={label} title={label}
> >
{@render icon?.()} {@render icon?.()}
+1 -1
View File
@@ -131,7 +131,7 @@
animate={false} animate={false}
> >
{#snippet item(p, index)} {#snippet item(p, index)}
<label class="relative"> <label class="relative block">
<input <input
type="radio" type="radio"
id={p.id.toString()} id={p.id.toString()}
@@ -10,6 +10,7 @@
postLink, postLink,
PostMedia, PostMedia,
PostMeta, PostMeta,
type Tag,
} from '$lib/components/lemmy/post' } from '$lib/components/lemmy/post'
import Markdown from '$lib/components/markdown/Markdown.svelte' import Markdown from '$lib/components/markdown/Markdown.svelte'
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte' import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
@@ -71,6 +72,23 @@
loading = false loading = false
data.thread.singleThread = false data.thread.singleThread = false
} }
let tags = $derived.by<{ title?: string; tags: Tag[] }>(() => {
const parsed = parseTags(data.post.post.name)
return {
title: parsed.title,
tags: [
...parsed.tags,
...(data.post.flair_list?.map((i) => ({
content: i.flair_title,
color: i.background_color,
icon: null,
textColor: i.text_color,
})) ?? []),
],
}
})
</script> </script>
<svelte:head> <svelte:head>
@@ -129,14 +147,11 @@
edited={data.post.post.updated} edited={data.post.post.updated}
title={data.post.post.name} title={data.post.post.name}
style="width: max-content;" style="width: max-content;"
tags={parseTags(data.post.post.name).tags} tags={tags.tags}
/> />
</div> </div>
<h1 class="font-medium text-xl leading-5"> <h1 class="font-medium text-xl leading-5">
<Markdown <Markdown source={tags.title ?? data.post.post.name} inline />
source={parseTags(data.post.post.name).title ?? data.post.post.name}
inline
/>
</h1> </h1>
</header> </header>
<PostMedia <PostMedia
+1 -1
View File
@@ -11,7 +11,7 @@
let { data = $bindable() } = $props() let { data = $bindable() } = $props()
let title = $state('Loading...') let title = $state('Loading...')
data.topic.then((i) => (title = i?.title ?? '')) data.topic.then((i) => (title = i?.name ?? ''))
</script> </script>
<svelte:head> <svelte:head>