diff --git a/.prettierrc b/.prettierrc index 32a99389..c62afff6 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,9 +1,17 @@ { - "arrowParens": "avoid", - "tabWidth": 2, - "semi": false, - "singleQuote": true, - "htmlWhitespaceSensitivity": "ignore", - "plugins": ["prettier-plugin-svelte"], - "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] + "arrowParens": "always", + "tabWidth": 2, + "semi": false, + "singleQuote": true, + "htmlWhitespaceSensitivity": "css", + "plugins": ["prettier-plugin-svelte"], + "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }], + "trailingComma": "all", + "bracketSameLine": false, + "svelteAllowShorthand": true, + "svelteBracketNewLine": true, + "svelteIndentScriptAndStyle": true, + "svelteSortOrder": "scripts-options-markup-styles", + "svelteStrictMode": false, + "useTabs": false } diff --git a/bun.lockb b/bun.lockb index 76cd9658..dc2b665a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 8f2d18c9..2b8ca50b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@sveltejs/adapter-node": "^5.2.9", "@sveltejs/adapter-static": "^3.0.8", "@sveltejs/kit": "^2.17.1", - "@sveltejs/vite-plugin-svelte": "^4.0.0", + "@sveltejs/vite-plugin-svelte": "^4.0.4", "@tailwindcss/container-queries": "^0.1.1", "@tailwindcss/postcss": "^4.1.8", "@types/nprogress": "^0.2.0", @@ -29,7 +29,7 @@ "openapi-fetch": "^0.14.0", "postcss": "^8.4.30", "prettier": "^3.3.3", - "prettier-plugin-svelte": "^3.2.7", + "prettier-plugin-svelte": "^3.4.0", "svelte": "^5.37.3", "svelte-adapter-bun-next": "^1.0.3", "svelte-check": "^4.0.0", diff --git a/src/lib/auth.svelte.ts b/src/lib/auth.svelte.ts index 73ebb0c1..cf0c94e8 100644 --- a/src/lib/auth.svelte.ts +++ b/src/lib/auth.svelte.ts @@ -7,7 +7,6 @@ import { import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js' import { client, getClient, site } from '$lib/client/lemmy.svelte' import { instanceToURL, moveItem } from '$lib/util.svelte' -import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js' import { toast } from 'mono-svelte' import { writable } from 'svelte/store' import { t } from './i18n/translations' @@ -61,8 +60,8 @@ const getCookie = (key: string): string | undefined => { return document?.cookie ?.split(';') - .map(c => c.trim()) - .find(c => c.split('=')?.[0] == key) + .map((c) => c.trim()) + .find((c) => c.split('=')?.[0] == key) ?.split('=')?.[1] } @@ -82,7 +81,7 @@ class Profile { }, ) #current = $derived( - this.meta.profiles.find(i => i.id == this.meta.profile) ?? + this.meta.profiles.find((i) => i.id == this.meta.profile) ?? this.getDefaultProfile(), ) @@ -123,7 +122,7 @@ class Profile { setInterval( () => { if (profile.current.jwt) - this.checkInbox().then(res => notifications.update(() => res)) + this.checkInbox().then((res) => notifications.update(() => res)) }, 4 * 60 * 1000, ) @@ -165,7 +164,7 @@ class Profile { } set current(value) { if (!value) return - const index = this.meta.profiles.findIndex(i => i.id == value?.id) + const index = this.meta.profiles.findIndex((i) => i.id == value?.id) this.meta.profiles[index] = value } @@ -200,7 +199,7 @@ class Profile { site.data = undefined client({ instanceURL: this.#current.instance }) .getSite() - .then(res => (site.data = res)) + .then((res) => (site.data = res)) } } @@ -226,8 +225,8 @@ class Profile { async add(jwt: string, instance: string, type: ClientType) { const user = await userFromJwt(jwt, instance) - .then(u => u) - .catch(err => { + .then((u) => u) + .catch((err) => { toast({ content: errorMessage(err as string), type: 'error' }) }) if (!user?.user) { @@ -237,7 +236,7 @@ class Profile { }) } - const id = Math.max(...this.meta.profiles.map(p => p.id)) + 1 + const id = Math.max(...this.meta.profiles.map((p) => p.id)) + 1 this.meta.profile = id this.meta.profiles.unshift({ id: id, @@ -253,7 +252,7 @@ class Profile { remove(id: number) { this.meta.profiles.splice( - this.meta.profiles.findIndex(p => p.id == id), + this.meta.profiles.findIndex((p) => p.id == id), 1, ) if (id == this.meta.profile) this.meta.profile = -1 @@ -261,7 +260,7 @@ class Profile { move(id: number, up: boolean) { try { - const index = this.meta.profiles.findIndex(i => i.id == id) + const index = this.meta.profiles.findIndex((i) => i.id == id) this.meta.profiles = moveItem( this.meta.profiles, index, @@ -277,7 +276,7 @@ class Profile { $effect(() => { const serialized = { ...this.meta, - profiles: this.meta.profiles.map(p => serializeUser(p)), + profiles: this.meta.profiles.map((p) => serializeUser(p)), } setFromStorage('profileData', serialized) @@ -292,7 +291,7 @@ class Profile { $effect(() => { this.fetchUserData().then(() => { if (this.current.jwt) - this.checkInbox().then(res => notifications.update(() => res)) + this.checkInbox().then((res) => notifications.update(() => res)) }) }) }) @@ -309,9 +308,7 @@ export const notifications = writable({ async function userFromJwt( jwt: string, instance: string, -): Promise< - { user: MyUserInfo | undefined; site: GetSiteResponse } | undefined -> { +): Promise<{ user?: MyUserInfo; site: GetSiteResponse } | undefined> { const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite() const timer = setTimeout( @@ -325,23 +322,16 @@ async function userFromJwt( ) const site = await sitePromise - .then(r => { + .then((r) => { clearTimeout(timer) return r }) - .catch(e => { + .catch((e) => { toast({ content: `Failed to contact the instance. ${e}` }) }) if (!site) return - if (!versionIsSupported(site.version, MINIMUM_VERSION)) { - toast({ - content: `This version of Photon only supports Lemmy instances with version ${MINIMUM_VERSION} or higher. This Lemmy instance is running: ${site.version}`, - type: 'error', - }) - } - const myUser = site.my_user return { @@ -360,27 +350,27 @@ function serializeUser(user: ProfileInfo): ProfileInfo { async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) { const unreadsPromise = getClient() .getUnreadCount() - .then(res => res.mentions + res.private_messages + res.replies) + .then((res) => res.mentions + res.private_messages + res.replies) .catch(() => 0) const reportsPromise = mod ? getClient() .getReportCount({}) .then( - res => + (res) => res.comment_reports + res.post_reports + (res.private_message_reports ?? 0), ) .catch(() => 0) - : new Promise(res => res(0)) + : new Promise((res) => res(0)) const applicationsPromise = admin ? getClient() .getUnreadRegistrationApplicationCount() - .then(res => res.registration_applications) + .then((res) => res.registration_applications) .catch(() => 0) - : new Promise(res => res(0)) + : new Promise((res) => res(0)) const [unreads, reports, applications] = await Promise.all([ unreadsPromise, diff --git a/src/lib/client/base.ts b/src/lib/client/base.ts index 2a943c70..34a66b51 100644 --- a/src/lib/client/base.ts +++ b/src/lib/client/base.ts @@ -20,6 +20,7 @@ export abstract class BaseClient { abstract type: ClientType abstract getSite(): Promise + abstract editSite(form: types.EditSite): Promise abstract generateTotpSecret(): Promise abstract listLogins(): Promise abstract listAllMedia(form: types.ListMedia): Promise @@ -221,6 +222,7 @@ export abstract class BaseClient { abstract uploadImage( form: types.UploadImage, ): Promise + abstract deleteImage(form: types.DeleteImage): Promise abstract setFlair?(form: types.SetPersonFlair): Promise } diff --git a/src/lib/client/lemmy/lemmy.ts b/src/lib/client/lemmy/lemmy.ts index 0be24707..b6d0534e 100644 --- a/src/lib/client/lemmy/lemmy.ts +++ b/src/lib/client/lemmy/lemmy.ts @@ -476,4 +476,14 @@ export class LemmyClient implements BaseClient { ): ReturnType { return await this.#client.uploadImage(...params) } + async editSite( + ...params: Parameters + ): ReturnType { + return await this.#client.editSite(...params) + } + async deleteImage( + ...params: Parameters + ): ReturnType { + return await this.#client.deleteImage(...params) + } } diff --git a/src/lib/client/piefed/piefed.ts b/src/lib/client/piefed/piefed.ts index 05bd6ec1..bec6ad34 100644 --- a/src/lib/client/piefed/piefed.ts +++ b/src/lib/client/piefed/piefed.ts @@ -113,7 +113,7 @@ export class PiefedClient implements BaseClient { return { community_view: toCommunityView(response.community_view), cross_posts: response.cross_posts.map(toPostView), - moderators: response.moderators.map(i => ({ + moderators: response.moderators.map((i) => ({ community: toCommunity(i.community), moderator: toPerson(i.moderator), })), @@ -261,7 +261,7 @@ export class PiefedClient implements BaseClient { return { ...response, community_view: toCommunityView(response.community_view), - moderators: response.moderators.map(i => ({ + moderators: response.moderators.map((i) => ({ community: toCommunity(i.community), moderator: toPerson(i.moderator), })), @@ -380,7 +380,7 @@ export class PiefedClient implements BaseClient { ).data! return { - moderators: response.moderators.map(i => ({ + moderators: response.moderators.map((i) => ({ community: toCommunity(i.community), moderator: toPerson(i.moderator), })), @@ -731,7 +731,7 @@ export class PiefedClient implements BaseClient { return { comments: response.comments.map(toCommentView), - moderates: response.moderates.map(i => ({ + moderates: response.moderates.map((i) => ({ community: toCommunity(i.community), moderator: toPerson(i.moderator), })), @@ -908,4 +908,11 @@ export class PiefedClient implements BaseClient { return toPersonView(response.person_view) } + + async editSite(): ReturnType { + throw new Error('unsupported') + } + async deleteImage(): ReturnType { + throw new Error('unsupported') + } } diff --git a/src/lib/client/piefed/rewrite.ts b/src/lib/client/piefed/rewrite.ts index 769ca84c..bdf36a80 100644 --- a/src/lib/client/piefed/rewrite.ts +++ b/src/lib/client/piefed/rewrite.ts @@ -86,7 +86,7 @@ export function toMyUser( ): MyUserInfo { return { ...myUser, - community_blocks: myUser.community_blocks.map(i => ({ + community_blocks: myUser.community_blocks.map((i) => ({ community: toCommunity(i.community), person: toPerson(i.person), })), @@ -101,23 +101,23 @@ export function toMyUser( }, person: toPerson(myUser.local_user_view.person), }, - follows: myUser.follows.map(i => ({ + follows: myUser.follows.map((i) => ({ follower: toPerson(i.follower), community: toCommunity(i.community), })), - moderates: myUser.moderates.map(i => ({ + moderates: myUser.moderates.map((i) => ({ community: toCommunity(i.community), moderator: toPerson(i.moderator), })), - instance_blocks: myUser.instance_blocks.map(i => ({ + instance_blocks: myUser.instance_blocks.map((i) => ({ instance: i.instance, person: toPerson(i.person), })), - person_blocks: myUser.person_blocks.map(i => ({ + person_blocks: myUser.person_blocks.map((i) => ({ person: toPerson(i.person), target: toPerson(i.target), })), - discussion_languages: myUser.discussion_languages.map(i => i.id!), + discussion_languages: myUser.discussion_languages.map((i) => i.id!), } } diff --git a/src/lib/client/types/schemas/BlockInstanceResponse.ts b/src/lib/client/types/schemas/BlockInstanceResponse.ts index a9a1f886..ba645ed5 100644 --- a/src/lib/client/types/schemas/BlockInstanceResponse.ts +++ b/src/lib/client/types/schemas/BlockInstanceResponse.ts @@ -1,3 +1,3 @@ export interface BlockInstanceResponse { - blocked: boolean; + blocked: boolean } diff --git a/src/lib/client/types/schemas/CaptchaResponse.ts b/src/lib/client/types/schemas/CaptchaResponse.ts index 60537f31..d3550f58 100644 --- a/src/lib/client/types/schemas/CaptchaResponse.ts +++ b/src/lib/client/types/schemas/CaptchaResponse.ts @@ -1,5 +1,5 @@ export interface CaptchaResponse { - png: string; - wav: string; - uuid: string; + png: string + wav: string + uuid: string } diff --git a/src/lib/client/types/schemas/GenerateTotpSecretResponse.ts b/src/lib/client/types/schemas/GenerateTotpSecretResponse.ts index 6487ed95..c7f08418 100644 --- a/src/lib/client/types/schemas/GenerateTotpSecretResponse.ts +++ b/src/lib/client/types/schemas/GenerateTotpSecretResponse.ts @@ -1,3 +1,3 @@ export interface GenerateTotpSecretResponse { - totp_secret_url: string; + totp_secret_url: string } diff --git a/src/lib/client/types/schemas/GetSiteMetadata.ts b/src/lib/client/types/schemas/GetSiteMetadata.ts index e655e89b..ea5cb055 100644 --- a/src/lib/client/types/schemas/GetSiteMetadata.ts +++ b/src/lib/client/types/schemas/GetSiteMetadata.ts @@ -1,3 +1,3 @@ export interface GetSiteMetadata { - url: string; + url: string } diff --git a/src/lib/client/types/schemas/GetUnreadCountResponse.ts b/src/lib/client/types/schemas/GetUnreadCountResponse.ts index afd20066..9311d98f 100644 --- a/src/lib/client/types/schemas/GetUnreadCountResponse.ts +++ b/src/lib/client/types/schemas/GetUnreadCountResponse.ts @@ -1,5 +1,5 @@ export interface GetUnreadCountResponse { - replies: number; - mentions: number; - private_messages: number; + replies: number + mentions: number + private_messages: number } diff --git a/src/lib/client/types/schemas/GetUnreadRegistrationApplicationCountResponse.ts b/src/lib/client/types/schemas/GetUnreadRegistrationApplicationCountResponse.ts index d1a82db2..432c861a 100644 --- a/src/lib/client/types/schemas/GetUnreadRegistrationApplicationCountResponse.ts +++ b/src/lib/client/types/schemas/GetUnreadRegistrationApplicationCountResponse.ts @@ -1,3 +1,3 @@ export interface GetUnreadRegistrationApplicationCountResponse { - registration_applications: number; + registration_applications: number } diff --git a/src/lib/client/types/schemas/LoginResponse.ts b/src/lib/client/types/schemas/LoginResponse.ts index 425733fb..c72e4bec 100644 --- a/src/lib/client/types/schemas/LoginResponse.ts +++ b/src/lib/client/types/schemas/LoginResponse.ts @@ -1,5 +1,5 @@ export interface LoginResponse { - jwt?: string; - registration_created: boolean; - verify_email_sent: boolean; + jwt?: string + registration_created: boolean + verify_email_sent: boolean } diff --git a/src/lib/client/types/schemas/SuccessResponse.ts b/src/lib/client/types/schemas/SuccessResponse.ts index e0dd3705..f43a513f 100644 --- a/src/lib/client/types/schemas/SuccessResponse.ts +++ b/src/lib/client/types/schemas/SuccessResponse.ts @@ -1,3 +1,3 @@ export interface SuccessResponse { - success: boolean; + success: boolean } diff --git a/src/lib/client/types/schemas/UpdateTotpResponse.ts b/src/lib/client/types/schemas/UpdateTotpResponse.ts index eaa16512..c1a3de6d 100644 --- a/src/lib/client/types/schemas/UpdateTotpResponse.ts +++ b/src/lib/client/types/schemas/UpdateTotpResponse.ts @@ -1,3 +1,3 @@ export interface UpdateTotpResponse { - enabled: boolean; + enabled: boolean } diff --git a/src/lib/components/error/ErrorContainer.svelte b/src/lib/components/error/ErrorContainer.svelte index 260bddad..88db397c 100644 --- a/src/lib/components/error/ErrorContainer.svelte +++ b/src/lib/components/error/ErrorContainer.svelte @@ -11,7 +11,7 @@ } export function clearErrorScope(scope: string | null | undefined) { - errors = errors.filter(error => error.scope != scope) + errors = errors.filter((error) => error.scope != scope) } @@ -32,7 +32,7 @@ let { scope = undefined, class: clazz = '' }: Props = $props() let scopedErrors = $derived( - errors.filter(e => e.scope == scope || e.scope == 'global'), + errors.filter((e) => e.scope == scope || e.scope == 'global'), ) diff --git a/src/lib/components/form/ImageAttachForm.svelte b/src/lib/components/form/ImageAttachForm.svelte index 7547917b..f9b4c936 100644 --- a/src/lib/components/form/ImageAttachForm.svelte +++ b/src/lib/components/form/ImageAttachForm.svelte @@ -36,19 +36,19 @@ try { const uploaded = ( await Promise.all( - Array.from(image).map(i => + Array.from(image).map((i) => uploadImage(i, profile.current.instance, profile.current.jwt!) - .then(uploaded => { + .then((uploaded) => { progress += 1 / (image?.length ?? 0) return uploaded }) - .catch(err => { + .catch((err) => { toast({ content: errorMessage(err), type: 'error' }) return 'Failed to upload' }), ), ) - ).filter(i => i != undefined) + ).filter((i) => i != undefined) if (!uploaded) throw new Error('Image upload returned undefined') @@ -72,7 +72,7 @@ {/if}
{ + onsubmit={(e) => { e.preventDefault() upload() }} diff --git a/src/lib/components/form/ImageInputModal.svelte b/src/lib/components/form/ImageInputModal.svelte index d93b1456..58045c45 100644 --- a/src/lib/components/form/ImageInputModal.svelte +++ b/src/lib/components/form/ImageInputModal.svelte @@ -35,7 +35,7 @@ {#if customUrl} { + onsubmit={(e) => { e.preventDefault() if (!imageUrl) throw new Error('missing imageurl') @@ -60,7 +60,7 @@ {:else} { + onupload={(uploaded) => { open = false passedImageUrl = uploaded[0] }} diff --git a/src/lib/components/helper/Empty.svelte b/src/lib/components/helper/Empty.svelte deleted file mode 100644 index 2514dc6a..00000000 --- a/src/lib/components/helper/Empty.svelte +++ /dev/null @@ -1,11 +0,0 @@ - - -{@render children?.({ ...rest })} diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte index d52deca3..90107304 100644 --- a/src/lib/components/lemmy/ObjectAutocomplete.svelte +++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte @@ -34,7 +34,7 @@ {#if type == 'community'} { + search={async (q) => { const results = await getClient(instance).search({ q: q || ' ', type_: 'Communities', @@ -43,9 +43,9 @@ sort: 'TopAll', }) - return results.communities.map(c => c.community) + return results.communities.map((c) => c.community) }} - extractName={c => `${c.title}@${new URL(c.actor_id).hostname}`} + extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`} bind:query={q} {...rest} > @@ -79,16 +79,16 @@ {:else if type == 'instance'} { + search={async (q) => { const results = (await instances) || {} return q ? (results.federated_instances?.linked || []).filter( - i => i.software === 'lemmy' && i.domain.includes(q), + (i) => i.software === 'lemmy' && i.domain.includes(q), ) : [] }} - extractName={i => `${i.domain}`} + extractName={(i) => `${i.domain}`} bind:query={q} {...rest} > diff --git a/src/lib/components/lemmy/PictrsImage.svelte b/src/lib/components/lemmy/PictrsImage.svelte index 8935509b..b24656be 100644 --- a/src/lib/components/lemmy/PictrsImage.svelte +++ b/src/lib/components/lemmy/PictrsImage.svelte @@ -1,15 +1,15 @@ { + onsubmit={(e) => { e.preventDefault() submit() }} diff --git a/src/lib/components/lemmy/comment/CommentItem.svelte b/src/lib/components/lemmy/comment/CommentItem.svelte index 904d60bb..26862425 100644 --- a/src/lib/components/lemmy/comment/CommentItem.svelte +++ b/src/lib/components/lemmy/comment/CommentItem.svelte @@ -1,12 +1,12 @@ - {#await community_view}
{:then community_view} - - setFlair = !setFlair} /> - + + (setFlair = !setFlair)} + /> +