feat [1/2]: add topics & feeds listing

This commit is contained in:
James Xylight authored and xylight committed 2025-09-17 00:27:11 +00:00
1 parent 1a948281a8
commit 5ed8346027
22 files changed
+426 -124

No files matched your search

+2 -1
View File
@@ -223,8 +223,9 @@ export abstract class BaseClient {
form: types.UploadImage,
): Promise<types.UploadImageResponse>
abstract deleteImage(form: types.DeleteImage): Promise<boolean>
abstract setFlair?(form: types.SetPersonFlair): Promise<types.PersonView>
abstract getFeeds?(form: types.GetFeeds): Promise<types.GetFeedsResponse>
abstract getTopics?(form: types.GetTopics): Promise<types.GetTopicsResponse>
}
export type NullableFnArg<T, Fallback = never> = T extends (
+33
View File
@@ -20,6 +20,7 @@ import {
toCommentView,
toCommunity,
toCommunityView,
toFeedView,
toLocalSite,
toMyUser,
toPerson,
@@ -29,6 +30,7 @@ import {
toPostView,
toPrivateMessageView,
toSortType,
toTopicView,
} from './rewrite'
import type { paths } from './schema'
import type { SubscribedType } from '../types'
@@ -166,6 +168,7 @@ export class PiefedClient implements BaseClient {
).data!
return {
...response,
posts: response.posts.map(toPostView),
next_page: (Number(params.page_cursor ?? 1) + 1).toString(),
}
@@ -969,4 +972,34 @@ export class PiefedClient implements BaseClient {
async deleteImage(): ReturnType<BaseClient['deleteImage']> {
throw new Error('unsupported')
}
async getFeeds(
params: NullableFnArg<BaseClient['getFeeds']>[0],
): NullableFnReturn<BaseClient['getFeeds']> {
const response = (
await this.#client.GET('/api/alpha/feed/list', {
params: { query: params },
})
).data!
return {
...response,
feeds: response.feeds.map(toFeedView),
}
}
async getTopics(
params: NullableFnArg<BaseClient['getTopics']>[0],
): NullableFnReturn<BaseClient['getTopics']> {
const response = (
await this.#client.GET('/api/alpha/topic/list', {
params: { query: params },
})
).data!
return {
...response,
topics: response.topics.map(toTopicView),
}
}
}
+22
View File
@@ -7,6 +7,7 @@ import type {
CommunityView,
CreateComment,
CreatePost,
FeedView,
GetComments,
GetPost,
GetPosts,
@@ -23,6 +24,7 @@ import type {
Search,
SortType,
SubscribedType,
TopicView,
} from '../types'
import type { components } from './schema'
@@ -207,6 +209,26 @@ export function toPersonMentionView(
}
}
export function toTopicView(
topicView: components['schemas']['TopicView'],
): TopicView {
return {
...topicView,
communities: topicView.communities?.map(toCommunity),
children: topicView.children.map(toTopicView),
}
}
export function toFeedView(
feedView: components['schemas']['FeedView'],
): FeedView {
return {
...feedView,
communities: feedView.communities?.map(toCommunity),
children: feedView.children.map(toFeedView),
}
}
// Query calls
export function fromGetPosts(
getPosts: GetPosts,
+2
View File
@@ -16,4 +16,6 @@ export interface GetPosts {
show_read?: boolean
show_nsfw?: boolean
page_cursor?: PaginationCursor
feed_id?: string
topic_id?: string
}
+56
View File
@@ -2001,3 +2001,59 @@ export interface CommunityFlair {
blur_images: boolean
ap_id: string | null
}
export interface GetFeeds {
include_communities?: boolean
mine_only?: boolean
}
export interface FeedView {
actor_id: string
ap_domain: string
children: FeedView[]
communities?: Community[]
communities_count: number
id: number
is_instance_feed: boolean
local: boolean
name: string
nsfl: boolean
nsfw: boolean
owner: boolean
public: boolean
published: string
show_posts_from_children: boolean
subscribed: boolean
subscriptions_count: number
title: string
updated: string
user_id: number
banner?: string
description?: string
description_html?: string
icon?: string
parent_feed_id?: number
}
export interface GetFeedsResponse {
feeds: FeedView[]
}
export interface GetTopics {
include_communities: boolean
}
export interface TopicView {
children: TopicView[]
communities?: Community[]
communities_count: number
id: number
name: string
show_posts_from_children: boolean
title: string
parent_topic_id?: number
}
export interface GetTopicsResponse {
topics: TopicView[]
}
+1 -1
View File
@@ -18,7 +18,7 @@
<div class="flex flex-row gap-2 items-center">
{#if customIcon}{@render customIcon()}{:else}
<Avatar url={icon} width={32} />
<Avatar url={icon} width={32} alt={name} circle={false} />
{/if}
<div class="flex flex-col">
<span class="font-semibold text-base">{name}</span>
+1 -1
View File
@@ -3,7 +3,7 @@
interface Props {
label: string
content: string
content: string | number
formatted?: boolean
labelClass?: string
contentClass?: string
@@ -0,0 +1,29 @@
<script lang="ts">
import type { Snippet } from 'svelte'
import Avatar from '../Avatar.svelte'
interface Props {
href?: string
icon?: string
title: string
detail?: string
children?: Snippet
}
let { href, icon, title, detail, children }: Props = $props()
</script>
<div class="flex flex-row gap-2 items-center">
<Avatar url={icon} alt={title} width={detail ? 32 : 24} circle={false} />
<a class="flex-1 flex flex-col group" {href}>
<h3
class="font-medium text-base overflow-hidden text-ellipsis leading-5 group-hover:underline"
>
{title}
</h3>
<p class="text-sm text-slate-600 dark:text-zinc-400">
{detail}
</p>
</a>
{@render children?.()}
</div>
+10 -12
View File
@@ -70,23 +70,21 @@
&:hover {
background-color: var(--color-slate-25);
}
}
&:not(.xs) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 3.5);
}
ul > :global(li:not(.xs) > *) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 3.5);
@media screen and (min-width: 40rem) {
&:not(.xs) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 4);
}
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 4);
}
}
.xs {
padding-block: calc(var(--spacing) * 0.5);
padding-block: calc(var(--spacing) * 1);
}
ul > :global(li.xs > *) {
padding-block: calc(var(--spacing) * 0.5);
padding-block: calc(var(--spacing) * 1);
}
ul > :global(li).selected {
@@ -1,5 +1,5 @@
<script lang="ts">
import { navigating } from '$app/state'
import { navigating, page } from '$app/state'
import { t } from '$lib/i18n/translations'
import { Button, TextInput } from 'mono-svelte'
import { MagnifyingGlass } from 'svelte-hero-icons'
@@ -29,7 +29,7 @@
class="shrink-0 h-full aspect-square shadow-md"
title="Search"
rounding="pill"
loading={navigating.to?.route.id == '/search'}
loading={navigating.to?.route.id == page.url.pathname}
icon={MagnifyingGlass}
></Button>
</div>
+5
View File
@@ -264,6 +264,11 @@
},
"translators": "Translators",
"accounts": "Accounts",
"explore": {
"title": "Explore",
"feeds": "Feeds",
"topics": "Topics"
},
"communities": {
"title": "Communities",
"trending": "Trending",