diff --git a/src/lib/client/base.ts b/src/lib/client/base.ts index fe731e1d..1ef282af 100644 --- a/src/lib/client/base.ts +++ b/src/lib/client/base.ts @@ -214,4 +214,18 @@ export abstract class BaseClient { abstract uploadImage( form: types.UploadImage, ): Promise + + abstract setFlair?(form: types.SetPersonFlair): Promise } + +export type NullableFnArg = T extends ( + ...args: infer A +) => any + ? A + : Fallback + +export type NullableFnReturn = T extends ( + ...args: any[] +) => infer A + ? A + : Fallback diff --git a/src/lib/client/lemmy.svelte.ts b/src/lib/client/lemmy.svelte.ts index cb0bf865..becd75f3 100644 --- a/src/lib/client/lemmy.svelte.ts +++ b/src/lib/client/lemmy.svelte.ts @@ -5,7 +5,7 @@ import { error } from '@sveltejs/kit' import { type GetSiteResponse } from '$lib/client/types' import { LemmyClient } from './lemmy/lemmy' import { PiefedClient } from './piefed/piefed' -import { DEFAULT_CLIENT_TYPE, type ClientType } from './base' +import { DEFAULT_CLIENT_TYPE, type ClientType, BaseClient } from './base' class SiteData { #data = $state() @@ -64,7 +64,7 @@ export function client({ ) => Promise auth?: string clientType?: ClientType -} = {}) { +} = {}): BaseClient { if (!instanceURL) instanceURL = profile.current.instance || DEFAULT_INSTANCE_URL diff --git a/src/lib/client/piefed/piefed.ts b/src/lib/client/piefed/piefed.ts index 341573f7..db550ca0 100644 --- a/src/lib/client/piefed/piefed.ts +++ b/src/lib/client/piefed/piefed.ts @@ -1,5 +1,10 @@ import createClient from 'openapi-fetch' -import type { BaseClient, ClientType } from '../base' +import type { + BaseClient, + ClientType, + NullableFnArg, + NullableFnReturn, +} from '../base' import { fromCreateComment, fromCreatePost, @@ -26,6 +31,7 @@ import { toSortType, } from './rewrite' import type { paths } from './schema' +import type { SetPersonFlair, PersonView } from '../types' export class PiefedClient implements BaseClient { type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' } @@ -893,4 +899,14 @@ export class PiefedClient implements BaseClient { msg: 'yeah it worked i think', } } + + async setFlair( + params: NullableFnArg[0], + ): NullableFnReturn { + const response = ( + await this.#client.POST('/user/set_flair', { body: params }) + ).data! + + return toPersonView(response.person_view) + } } diff --git a/src/lib/client/types/schemas/schemas.ts b/src/lib/client/types/schemas/schemas.ts index c3b48b25..f49745e3 100644 --- a/src/lib/client/types/schemas/schemas.ts +++ b/src/lib/client/types/schemas/schemas.ts @@ -1985,3 +1985,8 @@ export interface DeleteImage { token: string filename: string } + +export interface SetPersonFlair { + community_id: number + flair_text: string +} diff --git a/src/lib/components/lemmy/community/CommunityCard.svelte b/src/lib/components/lemmy/community/CommunityCard.svelte index 6e5df636..64a3b879 100644 --- a/src/lib/components/lemmy/community/CommunityCard.svelte +++ b/src/lib/components/lemmy/community/CommunityCard.svelte @@ -67,28 +67,31 @@ + {#await community_view}
{:then community_view} + + setFlair = !setFlair} /> +