diff --git a/src/lib/components/lemmy/community/CommunityCard.svelte b/src/lib/components/lemmy/community/CommunityCard.svelte index 64a3b879..44c82cc0 100644 --- a/src/lib/components/lemmy/community/CommunityCard.svelte +++ b/src/lib/components/lemmy/community/CommunityCard.svelte @@ -82,7 +82,7 @@ import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte' import { t } from '$lib/i18n/translations' import { errorMessage } from '$lib/lemmy/error' - import { userLink } from '$lib/lemmy/generic' + import { userLink } from '$lib/util.svelte' import { addSubscription } from '$lib/lemmy/user.js' import { settings } from '$lib/settings.svelte' import { fullCommunityName } from '$lib/util.svelte.js' diff --git a/src/lib/components/lemmy/community/CommunityHeader.svelte b/src/lib/components/lemmy/community/CommunityHeader.svelte index 015eef00..b8addf04 100644 --- a/src/lib/components/lemmy/community/CommunityHeader.svelte +++ b/src/lib/components/lemmy/community/CommunityHeader.svelte @@ -5,7 +5,7 @@ import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte' import { publishedToDate } from '$lib/components/util/date' import { t } from '$lib/i18n/translations' - import { userLink } from '$lib/lemmy/generic' + import { userLink } from '$lib/util.svelte' import { settings } from '$lib/settings.svelte' import { fullCommunityName } from '$lib/util.svelte' import type { diff --git a/src/lib/components/lemmy/community/CommunityItem.svelte b/src/lib/components/lemmy/community/CommunityItem.svelte index 180226ed..fc51e126 100644 --- a/src/lib/components/lemmy/community/CommunityItem.svelte +++ b/src/lib/components/lemmy/community/CommunityItem.svelte @@ -7,7 +7,7 @@ import { client } from '$lib/client/lemmy.svelte' import { addSubscription } from '$lib/lemmy/user.js' import { settings } from '$lib/settings.svelte' - import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js' + import { fullCommunityName } from '$lib/util.svelte.js' import type { CommunityView } from '$lib/client/types' import { Button, modal } from 'mono-svelte' import type { Snippet } from 'svelte' @@ -158,7 +158,9 @@ {#snippet children({ subscribe, subscribing })} - {@const subscribed = isSubscribed(community.subscribed)} + {@const subscribed = + community.subscribed == 'Subscribed' || + community.subscribed == 'Pending'} - - diff --git a/src/lib/components/lemmy/user/UserItem.svelte b/src/lib/components/lemmy/user/UserItem.svelte index 88526ab6..14c00ea0 100644 --- a/src/lib/components/lemmy/user/UserItem.svelte +++ b/src/lib/components/lemmy/user/UserItem.svelte @@ -1,7 +1,7 @@ {#if content != '-1'} -
- +
+
{label} - - +
+
{#if formatted} {:else} {content} {/if} - -
+ + {/if} diff --git a/src/lib/components/ui/sidebar/Sidebar.svelte b/src/lib/components/ui/sidebar/Sidebar.svelte index 7879a8ee..cf764a05 100644 --- a/src/lib/components/ui/sidebar/Sidebar.svelte +++ b/src/lib/components/ui/sidebar/Sidebar.svelte @@ -4,7 +4,7 @@ import Expandable from '$lib/components/ui/Expandable.svelte' import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte' import { t } from '$lib/i18n/translations' - import { communityLink } from '$lib/lemmy/generic' + import { communityLink } from '$lib/util.svelte' import { settings } from '$lib/settings.svelte.js' import { theme } from '$lib/ui/theme/theme.svelte' import { Badge, Option, Select } from 'mono-svelte' diff --git a/src/lib/lemmy/generic.ts b/src/lib/lemmy/generic.ts deleted file mode 100644 index 31ed50f9..00000000 --- a/src/lib/lemmy/generic.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { fullCommunityName } from '$lib/util.svelte' -import type { Community, Person } from '$lib/client/types' - -export const communityLink = (community: Community, prefix: string = '') => - `${prefix}/c/${fullCommunityName(community.name, community.actor_id)}` - -export const userLink = (person: Person, prefix: string = '') => - `${prefix}/u/${person.name}@${new URL(person.actor_id).hostname}` diff --git a/src/lib/lemmy/user.ts b/src/lib/lemmy/user.ts index fe2755d3..dd617e26 100644 --- a/src/lib/lemmy/user.ts +++ b/src/lib/lemmy/user.ts @@ -36,19 +36,6 @@ export function addSubscription( } } -export async function addAdmin(handle: string, added: boolean) { - const user = await client().resolveObject({ - q: handle, - }) - - if (!user.person) throw new Error('No user found') - - return await client().addAdmin({ - added: added, - person_id: user.person.person.id, - }) -} - export function hasFavorite(profile: ProfileInfo, id: number): boolean { return profile.favorites?.map((i) => i.id).includes(id) ?? false } diff --git a/src/lib/mono/forms/Checkbox.svelte b/src/lib/mono/forms/Checkbox.svelte deleted file mode 100644 index e1e4673f..00000000 --- a/src/lib/mono/forms/Checkbox.svelte +++ /dev/null @@ -1,35 +0,0 @@ - - - diff --git a/src/lib/mono/forms/ImageInput.svelte b/src/lib/mono/forms/ImageInput.svelte deleted file mode 100644 index adb15266..00000000 --- a/src/lib/mono/forms/ImageInput.svelte +++ /dev/null @@ -1,86 +0,0 @@ - - -
- {#if customLabel || label} - - {/if} - - {#if url != undefined} - - {/if} -
diff --git a/src/lib/mono/index.ts b/src/lib/mono/index.ts index 11b0bde3..9b36f518 100644 --- a/src/lib/mono/index.ts +++ b/src/lib/mono/index.ts @@ -12,9 +12,7 @@ export { default as TextInput } from './forms/TextInput.svelte' export { default as TextArea } from './forms/TextArea.svelte' export { default as Select } from './forms/select/Select.svelte' export { default as Option } from './forms/select/Option.svelte' -export { default as ImageInput } from './forms/ImageInput.svelte' -export { default as Checkbox } from './forms/Checkbox.svelte' export { default as Switch } from './forms/Switch.svelte' export { default as Popover } from './popover/Popover.svelte' diff --git a/src/lib/settings.svelte.ts b/src/lib/settings.svelte.ts index fbff707d..f02c7a6c 100644 --- a/src/lib/settings.svelte.ts +++ b/src/lib/settings.svelte.ts @@ -58,14 +58,12 @@ interface Settings { presets: Preset[] defaultRemoveAction: 'comment' | 'message' | null } - randomPlaceholders: boolean modlogCardView: boolean | undefined debugInfo: boolean expandImages: boolean font: 'inter' | 'system' | 'browser' leftAlign: boolean - hidePhoton: boolean newWidth: boolean markPostsAsRead: boolean @@ -143,14 +141,12 @@ export const defaultSettings: Settings = { ], defaultRemoveAction: null, }, - randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? false, modlogCardView: toBool(env.PUBLIC_MODLOG_CARD_VIEW) ?? undefined, debugInfo: toBool(env.PUBLIC_DEBUG_INFO) ?? false, expandImages: toBool(env.PUBLIC_EXPAND_IMAGES) ?? true, view: (env.PUBLIC_VIEW as View) ?? 'compact', font: (env.PUBLIC_FONT as 'inter') ?? 'inter', leftAlign: toBool(env.PUBLIC_LEFT_ALIGN) ?? false, - hidePhoton: toBool(env.PUBLIC_REMOVE_CREDIT) ?? false, newWidth: toBool(env.PUBLIC_LIMIT_LAYOUT_WIDTH) ?? true, markPostsAsRead: toBool(env.PUBLIC_MARK_POSTS_AS_READ) ?? true, openLinksInNewTab: false, diff --git a/src/lib/util.svelte.ts b/src/lib/util.svelte.ts index 0e600bbe..6b51ad5f 100644 --- a/src/lib/util.svelte.ts +++ b/src/lib/util.svelte.ts @@ -1,12 +1,9 @@ +import { browser } from '$app/environment' import { goto } from '$app/navigation' import { client } from '$lib/client/lemmy.svelte' -import { settings } from '$lib/settings.svelte' -import type { SubscribedType } from '$lib/client/types' -import { toast } from 'mono-svelte' -import { t } from './i18n/translations' -import { errorMessage } from './lemmy/error' import { SvelteURL } from 'svelte/reactivity' -import { browser } from '$app/environment' +import { t } from './i18n/translations' +import type { Community, Person } from './client/types' // Despite the name, this will round up // Example: findClosestNumber([8, 16, 32, 64, 128], 76) will return 128 @@ -32,28 +29,7 @@ export const fullCommunityName = (name: string, actorId: string) => `${name}@${new SvelteURL(actorId).hostname}` export const placeholders = { - url: ['https://example.com'], - post: [ - 'Does anybody read these placeholders?', - 'Top 10 reasons why a meteor would help Earth', - 'Title text', - 'I took a picture of something idk', - ], - body: ['bottom text', 'body text', 'body text'], - comment: [ - 'what?', - 'new response just dropped', - 'this comment placeholder is very important dont forget', - 'existential crisis in progress', - 'hello user i am a sentient placeholder. please dont type anything or i disappear forever. thanks', - ], get: (type: 'url' | 'post' | 'body' | 'comment') => { - if (settings.randomPlaceholders) { - return placeholders[type][ - Math.floor(Math.random() * placeholders[type].length) - ] - } - switch (type) { case 'post': return t.get('placeholders.title') @@ -92,18 +68,11 @@ export function moveItem( return newArray } -export const removeItem = (array: T[], predicate: (item: T) => boolean) => { - array.splice(array.findIndex(predicate), 1) -} - export const DOMAIN_REGEX = /^(http(s)?:\/\/)?((?!-)[A-Za-z0-9-]{1,63}\.)+[A-Za-z]{2,63}(:[0-9]{0,5})?$/g export const DOMAIN_REGEX_FORMS = '(http(s)?://)?((?!-)[A-Za-z0-9]{1,63}.)+[A-Za-z]{2,63}(:[0-9]{0,5})?' -export const isSubscribed = (subscribed: SubscribedType) => - subscribed == 'Pending' || subscribed == 'Subscribed' - export async function uploadImage( image: File | null | undefined, instance: string, @@ -136,10 +105,6 @@ export function canParseUrl(url: string): boolean { } } -export function instanceId(actorId: string) { - return new SvelteURL(actorId).hostname -} - export function escapeHtml(input: string): string { return input .replace(/&/g, '&') @@ -214,3 +179,9 @@ export const isVideo = (url: string | undefined) => { return false } } + +export const communityLink = (community: Community, prefix: string = '') => + `${prefix}/c/${fullCommunityName(community.name, community.actor_id)}` + +export const userLink = (person: Person, prefix: string = '') => + `${prefix}/u/${person.name}@${new SvelteURL(person.actor_id).hostname}` diff --git a/src/routes/admin/team/+page.svelte b/src/routes/admin/team/+page.svelte index 4d22e1e1..1f705371 100644 --- a/src/routes/admin/team/+page.svelte +++ b/src/routes/admin/team/+page.svelte @@ -1,22 +1,19 @@ @@ -75,32 +75,33 @@
{ - trycatch(async () => { - if (!profile.current?.jwt || newAdmin == '') return - adding = true + onsubmit={async (e) => { + e.preventDefault() + if (!profile.current?.jwt || !newAdmin) return + adding = true - const r = await addAdmin(`${newAdmin}@${instance.data}`, true) - if (!r) return - - toast({ - content: 'Successfully added that admin.', - type: 'success', - }) - - if (data.site) data.site.admins = r.admins - - newAdmin = '' - adding = false + const res = await client().addAdmin({ + added: true, + person_id: newAdmin, }) - })} + + toast({ + content: 'Successfully added that admin.', + type: 'success', + }) + + if (data.site) data.site.admins = res.admins + + newAdmin = undefined + adding = false + }} > - +
+ (newAdmin = p.id)} + /> +