cleanup: delete unused files

This commit is contained in:
James Xylight committed 2025-09-07 10:47:30 -07:00
1 parent de26affacd
commit 3e909600d9
18 files changed
+64 -309

No files matched your search

@@ -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'
@@ -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 {
@@ -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 @@
</Button>
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
{@const subscribed = isSubscribed(community.subscribed)}
{@const subscribed =
community.subscribed == 'Subscribed' ||
community.subscribed == 'Pending'}
<Button
disabled={subscribing || !profile.current?.jwt}
loading={subscribing}
@@ -1,6 +1,6 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { communityLink } from '$lib/lemmy/generic'
import { communityLink } from '$lib/util.svelte'
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import type { Community } from '$lib/client/types'
@@ -2,7 +2,7 @@
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
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 type { PersonView, SiteView, Tagline } from '$lib/client/types'
import { Badge } from 'mono-svelte'
@@ -1,71 +0,0 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { getClient } from '$lib/client/lemmy.svelte'
import { t } from '$lib/i18n/translations'
import type { Person } from '$lib/client/types'
import { Button, Modal, toast } from 'mono-svelte'
import { Icon, PaperAirplane } from 'svelte-hero-icons'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open?: boolean
user: Person
}
let { open = $bindable(false), user }: Props = $props()
let message = $state('')
let loading = $state(false)
async function sendMessage() {
if (!profile.current?.jwt || message == '') return
loading = true
try {
await getClient().createPrivateMessage({
content: message,
recipient_id: user.id,
})
toast({
content: $t('toast.sentMessage'),
type: 'success',
})
open = false
} catch (err) {
toast({
content: errorMessage(err as string),
type: 'error',
})
}
loading = false
}
</script>
<Modal bind:open>
{#snippet customTitle()}
<h1 class="text-2xl font-bold">Message</h1>
{/snippet}
<form onsubmit={preventDefault(sendMessage)} class="flex flex-col gap-4">
<p class="inline-flex flex-row gap-2 items-center">
<Icon src={PaperAirplane} size="16" mini />
<UserLink avatar {user} />
</p>
<MarkdownEditor
bind:value={message}
label={$t('content.message')}
rows={4}
/>
<Button color="primary" size="lg" submit {loading} disabled={loading}>
{$t('common.send')}
</Button>
</form>
</Modal>
@@ -1,7 +1,7 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import { userLink } from '$lib/lemmy/generic'
import { userLink } from '$lib/util.svelte'
import type { PersonView } from '$lib/client/types'
interface Props {
+6 -6
View File
@@ -21,16 +21,16 @@
</script>
{#if content != '-1'}
<div class="flex flex-col {clazz}">
<span class="text-slate-600 dark:text-zinc-400 text-xs {labelClass}">
<dl class={['flex flex-col', clazz]}>
<dt class={['text-slate-600 dark:text-zinc-400 text-xs', labelClass]}>
{label}
</span>
<span class="text-base {contentClass}">
</dt>
<dd class={['text-base', contentClass]}>
{#if formatted}
<FormattedNumber number={Number(content)} />
{:else}
{content}
{/if}
</span>
</div>
</dd>
</dl>
{/if}
+1 -1
View File
@@ -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'
-8
View File
@@ -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}`
-13
View File
@@ -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
}
-35
View File
@@ -1,35 +0,0 @@
<script lang="ts">
interface Props {
defaultValue?: boolean
checked?: boolean | undefined
inlineDescription?: boolean
children?: import('svelte').Snippet
description?: import('svelte').Snippet
}
let {
defaultValue = false,
checked = $bindable(defaultValue),
inlineDescription = false,
children,
description,
}: Props = $props()
</script>
<label
class="font-normal cursor-pointer text-sm flex flex-row items-baseline gap-2"
>
<input type="checkbox" bind:checked class="cursor-pointer" />
<div
class="inline-flex {inlineDescription
? 'flex-row'
: 'flex-col'} font-medium gap-1"
>
{@render children?.()}
{#if description}
<span class="font-normal text-slate-600 dark:text-zinc-400">
{@render description?.()}
</span>
{/if}
</div>
</label>
-86
View File
@@ -1,86 +0,0 @@
<script lang="ts">
import { DocumentPlus, Icon } from 'svelte-hero-icons'
import Label from '../forms/Label.svelte'
import { generateID } from '../forms/helper.js'
import TextInput from './TextInput.svelte'
interface Props {
accept?: string
files?: FileList | undefined | null
label?: string | undefined
id?: string
url?: string | undefined
customLabel?: import('svelte').Snippet
}
let {
accept = 'image/*',
files = $bindable(),
label = undefined,
id = generateID(),
url = undefined,
customLabel,
}: Props = $props()
let dragover = $state(false)
let previewURL = $derived(files ? URL.createObjectURL(files[0]) : undefined)
</script>
<div class="flex flex-col">
{#if customLabel || label}
<Label for={id} text={label} class="mb-1">
{@render customLabel?.()}
</Label>
{/if}
<label
class={[
'flex flex-col items-center justify-center px-8 py-4 mx-auto w-full rounded-xl',
'border border-slate-200 dark:border-zinc-800 border-dashed hover:border-slate-300 hover:dark:border-zinc-700',
'cursor-pointer min-h-36 transition-colors bg-white dark:bg-zinc-950',
dragover && 'border-sky-500 text-sky-500',
]}
ondrop={(event) => {
event.preventDefault()
files = event.dataTransfer?.files ?? null
}}
ondragover={(event) => {
event.preventDefault()
if (event.dataTransfer) {
event.dataTransfer.dropEffect = 'copy'
dragover = true
}
}}
ondragleave={(e) => {
e.preventDefault()
dragover = false
}}
>
{#if files}
<!-- svelte-ignore a11y_missing_attribute -->
<img
src={previewURL}
onload={() => {
if (previewURL) URL.revokeObjectURL(previewURL)
}}
class="w-full max-w-sm h-full rounded-lg"
/>
{:else}
<Icon
src={DocumentPlus}
class="text-slate-400 dark:text-zinc-500"
size="36"
solid
/>
<p class="text-slate-600 dark:text-zinc-400 font-medium">Attach a file</p>
{/if}
<input type="file" bind:files {accept} class="hidden" />
</label>
{#if url != undefined}
<TextInput
class="rounded-t-none border-t-0 rounded-xl"
placeholder="https://example.com/img1.png"
/>
{/if}
</div>
-2
View File
@@ -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'
-4
View File
@@ -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,
+9 -38
View File
@@ -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<T>(
return newArray
}
export const removeItem = <T>(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, '&amp;')
@@ -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}`
+38 -37
View File
@@ -1,22 +1,19 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
import { client } from '$lib/client/lemmy.svelte'
import UserAutocomplete from '$lib/components/lemmy/user/UserAutocomplete.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import { Header } from '$lib/components/ui/layout'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { t } from '$lib/i18n/translations.js'
import { instance } from '$lib/instance.svelte.js'
import { getClient } from '$lib/client/lemmy.svelte'
import { addAdmin } from '$lib/lemmy/user.js'
import { trycatch } from '$lib/util.svelte.js'
import { Button, TextInput, toast } from 'mono-svelte'
import { errorMessage } from '$lib/lemmy/error.js'
import { Button, toast } from 'mono-svelte'
import { Icon, Plus, QuestionMarkCircle, Trash } from 'svelte-hero-icons'
let { data: pageData } = $props()
let data = $state(pageData)
let newAdmin: string = $state(''),
let newAdmin = $state<number>(),
adding: boolean = $state(false)
async function removeAdmin(
@@ -31,19 +28,22 @@
if (!profile.current?.jwt) return
const result = await trycatch(() =>
getClient().addAdmin({
try {
const res = await client().addAdmin({
added: false,
person_id: id,
}),
)
})
if (result) {
data.site!.admins = result.admins
data.site.admins = res.admins
toast({
content: $t('toast.removeAdmin'),
type: 'success',
})
} catch (err) {
toast({
content: errorMessage(err as string),
type: 'error',
})
}
}
</script>
@@ -75,32 +75,33 @@
</ul>
<form
class="flex flex-row gap-2 mt-auto w-full"
onsubmit={preventDefault(() => {
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
}}
>
<TextInput
bind:value={newAdmin}
placeholder="@user"
class="flex-1"
pattern={'@[^ |]{1,}'}
/>
<div class="w-full">
<UserAutocomplete
listing_type="All"
onselect={(p) => (newAdmin = p.id)}
/>
</div>
<Button
loading={adding}
disabled={adding}
+1 -1
View File
@@ -11,7 +11,7 @@
import { publishedToDate } from '$lib/components/util/date.js'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
import { t } from '$lib/i18n/translations.js'
import { communityLink } from '$lib/lemmy/generic.js'
import { communityLink } from '$lib/util.svelte.js'
import { isCommentView } from '$lib/lemmy/item.js'
import { Option, Select } from 'mono-svelte'
import { AdjustmentsHorizontal, Icon, PencilSquare } from 'svelte-hero-icons'