Merge pull request #650 from Xyphyn/format-refactor
refactor: clean up legacy stuff
This commit is contained in:
193 files changed
+1350
-1931
No files matched your search
+15
-7
@@ -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
|
||||
}
|
||||
+2
-2
@@ -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",
|
||||
|
||||
+21
-31
@@ -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<Notifications>({
|
||||
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<number>(res => res(0))
|
||||
: new Promise<number>((res) => res(0))
|
||||
|
||||
const applicationsPromise = admin
|
||||
? getClient()
|
||||
.getUnreadRegistrationApplicationCount()
|
||||
.then(res => res.registration_applications)
|
||||
.then((res) => res.registration_applications)
|
||||
.catch(() => 0)
|
||||
: new Promise<number>(res => res(0))
|
||||
: new Promise<number>((res) => res(0))
|
||||
|
||||
const [unreads, reports, applications] = await Promise.all([
|
||||
unreadsPromise,
|
||||
|
||||
@@ -20,6 +20,7 @@ export abstract class BaseClient {
|
||||
abstract type: ClientType
|
||||
|
||||
abstract getSite(): Promise<types.GetSiteResponse>
|
||||
abstract editSite(form: types.EditSite): Promise<types.SiteResponse>
|
||||
abstract generateTotpSecret(): Promise<types.GenerateTotpSecretResponse>
|
||||
abstract listLogins(): Promise<types.LoginToken[]>
|
||||
abstract listAllMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
|
||||
@@ -221,6 +222,7 @@ export abstract class BaseClient {
|
||||
abstract uploadImage(
|
||||
form: types.UploadImage,
|
||||
): Promise<types.UploadImageResponse>
|
||||
abstract deleteImage(form: types.DeleteImage): Promise<boolean>
|
||||
|
||||
abstract setFlair?(form: types.SetPersonFlair): Promise<types.PersonView>
|
||||
}
|
||||
|
||||
@@ -476,4 +476,14 @@ export class LemmyClient implements BaseClient {
|
||||
): ReturnType<BaseClient['uploadImage']> {
|
||||
return await this.#client.uploadImage(...params)
|
||||
}
|
||||
async editSite(
|
||||
...params: Parameters<BaseClient['editSite']>
|
||||
): ReturnType<BaseClient['editSite']> {
|
||||
return await this.#client.editSite(...params)
|
||||
}
|
||||
async deleteImage(
|
||||
...params: Parameters<BaseClient['deleteImage']>
|
||||
): ReturnType<BaseClient['deleteImage']> {
|
||||
return await this.#client.deleteImage(...params)
|
||||
}
|
||||
}
|
||||
@@ -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<BaseClient['editSite']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
async deleteImage(): ReturnType<BaseClient['deleteImage']> {
|
||||
throw new Error('unsupported')
|
||||
}
|
||||
}
|
||||
@@ -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!),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface BlockInstanceResponse {
|
||||
blocked: boolean;
|
||||
blocked: boolean
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface CaptchaResponse {
|
||||
png: string;
|
||||
wav: string;
|
||||
uuid: string;
|
||||
png: string
|
||||
wav: string
|
||||
uuid: string
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface GenerateTotpSecretResponse {
|
||||
totp_secret_url: string;
|
||||
totp_secret_url: string
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface GetSiteMetadata {
|
||||
url: string;
|
||||
url: string
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface GetUnreadCountResponse {
|
||||
replies: number;
|
||||
mentions: number;
|
||||
private_messages: number;
|
||||
replies: number
|
||||
mentions: number
|
||||
private_messages: number
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface GetUnreadRegistrationApplicationCountResponse {
|
||||
registration_applications: number;
|
||||
registration_applications: number
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface SuccessResponse {
|
||||
success: boolean;
|
||||
success: boolean
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface UpdateTotpResponse {
|
||||
enabled: boolean;
|
||||
enabled: boolean
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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}
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
upload()
|
||||
}}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
{#if customUrl}
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
if (!imageUrl) throw new Error('missing imageurl')
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
{:else}
|
||||
<ImageAttachForm
|
||||
multiple={false}
|
||||
onupload={uploaded => {
|
||||
onupload={(uploaded) => {
|
||||
open = false
|
||||
passedImageUrl = uploaded[0]
|
||||
}}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet<[any]>} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props & { [key: string]: any }} */
|
||||
let { children, ...rest } = $props()
|
||||
</script>
|
||||
|
||||
{@render children?.({ ...rest })}
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
{#if type == 'community'}
|
||||
<Search
|
||||
search={async q => {
|
||||
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 @@
|
||||
</Search>
|
||||
{:else if type == 'instance'}
|
||||
<Search
|
||||
search={async q => {
|
||||
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}
|
||||
>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import type { LocalImage, Person } from '$lib/client/types'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import type { LocalImage, Person } from '$lib/client/types'
|
||||
import { action, Button, modal, toast } from 'mono-svelte'
|
||||
import { ArrowDownTray, Icon, Trash } from 'svelte-hero-icons'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import { ArrowDownTray, Trash } from 'svelte-hero-icons'
|
||||
|
||||
let loading = $state(false)
|
||||
|
||||
@@ -60,11 +60,8 @@
|
||||
href="{instanceToURL(instance.data)}/pictrs/image/{image.pictrs_alias}"
|
||||
size="square-md"
|
||||
class="ml-auto"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowDownTray} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={ArrowDownTray}
|
||||
></Button>
|
||||
<Button
|
||||
title={$t('post.actions.more.delete')}
|
||||
onclick={() => {
|
||||
@@ -88,10 +85,7 @@
|
||||
size="square-md"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" mini color="text-red-500" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={Trash}
|
||||
></Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
@@ -20,14 +19,14 @@
|
||||
Minus,
|
||||
Pencil,
|
||||
Plus,
|
||||
ShieldCheck,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { slide } from 'svelte/transition'
|
||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||
import CommentForm from './CommentForm.svelte'
|
||||
import type { CommentNodeI } from './comments.svelte'
|
||||
import { CommentActions, CommentForm } from '.'
|
||||
|
||||
interface Props {
|
||||
node: CommentNodeI
|
||||
@@ -94,7 +93,7 @@
|
||||
<div>{$t('form.edit')}</div>
|
||||
{/snippet}
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save(replying ? 'reply' : 'edit')
|
||||
}}
|
||||
@@ -154,10 +153,22 @@
|
||||
>
|
||||
{#snippet extraBadges()}
|
||||
{#if node.comment_view.creator_is_moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
<Icon
|
||||
src={ShieldCheck}
|
||||
size="14"
|
||||
micro
|
||||
class="text-green-500"
|
||||
aria-label={$t('class.moderator')}
|
||||
/>
|
||||
{/if}
|
||||
{#if node.comment_view.creator_is_admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
<Icon
|
||||
src={ShieldCheck}
|
||||
size="16"
|
||||
micro
|
||||
class="text-red-500"
|
||||
aria-label={$t('class.admin')}
|
||||
/>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
@@ -262,7 +273,7 @@
|
||||
label={$t('comment.reply')}
|
||||
{postId}
|
||||
parentId={node.comment_view.comment.id}
|
||||
oncomment={e => {
|
||||
oncomment={(e) => {
|
||||
node.children = [
|
||||
{
|
||||
children: [],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
|
||||
import type { CommentView } from '$lib/client/types'
|
||||
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
|
||||
import {
|
||||
amMod,
|
||||
@@ -10,7 +10,6 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { deleteItem, save } from '$lib/lemmy/contentview.js'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import type { CommentView } from '$lib/client/types'
|
||||
import { Button, Menu, MenuButton } from 'mono-svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
@@ -23,6 +22,7 @@
|
||||
Share,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { CommentVote } from '.'
|
||||
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
@@ -74,11 +74,8 @@
|
||||
rounding="pill"
|
||||
size="square-md"
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={EllipsisHorizontal}
|
||||
></Button>
|
||||
{/snippet}
|
||||
<MenuButton
|
||||
onclick={() => {
|
||||
@@ -88,18 +85,13 @@
|
||||
})
|
||||
else navigator.clipboard.writeText(comment.comment.ap_id)
|
||||
}}
|
||||
icon={Share}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} mini size="16" />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
</MenuButton>
|
||||
{#if profile.current?.jwt}
|
||||
{#if comment.creator.id == profile.current.user?.local_user_view.person.id}
|
||||
<MenuButton onclick={() => onedit?.(comment)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} mini size="16" />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => onedit?.(comment)} icon={PencilSquare}>
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -108,10 +100,8 @@
|
||||
if (profile.current?.jwt)
|
||||
comment.saved = await save(comment, !comment.saved)
|
||||
}}
|
||||
icon={comment.saved ? BookmarkSlash : Bookmark}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
||||
{/snippet}
|
||||
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
</MenuButton>
|
||||
{#if profile.current?.user && profile.current.jwt && profile.current.user.local_user_view.person.id == comment.creator.id}
|
||||
@@ -124,20 +114,19 @@
|
||||
!comment.comment.deleted,
|
||||
)
|
||||
}}
|
||||
icon={Trash}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} mini size="16" />
|
||||
{/snippet}
|
||||
{comment.comment.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current.jwt && profile.current.user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton onclick={() => report(comment)} color="danger-subtle">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} mini size="16" />
|
||||
{/snippet}
|
||||
<MenuButton
|
||||
onclick={() => report(comment)}
|
||||
color="danger-subtle"
|
||||
icon={Flag}
|
||||
>
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient, site } from '$lib/client/lemmy.svelte'
|
||||
import { client, site } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { placeholders } from '$lib/util.svelte.js'
|
||||
import type { CommentResponse } from '$lib/client/types'
|
||||
@@ -56,7 +56,7 @@
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const response = await getClient().createComment({
|
||||
const response = await client().createComment({
|
||||
content: value,
|
||||
post_id: postId,
|
||||
parent_id: parentId,
|
||||
@@ -77,7 +77,7 @@
|
||||
</script>
|
||||
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import type { CommentView } from '$lib/client/types'
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { PostMeta } from '../post'
|
||||
import { Comment } from '.'
|
||||
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
}, 100)
|
||||
}
|
||||
|
||||
const observer = new ResizeObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (offsetEl) {
|
||||
initialOffset =
|
||||
entry.target.getBoundingClientRect().top + window.scrollY
|
||||
@@ -50,7 +50,7 @@
|
||||
{#snippet item(index)}
|
||||
<div class={['px-3 sm:px-6', index % 2 == 1 && '']}>
|
||||
<Comments
|
||||
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
|
||||
bind:nodes={() => [nodes[index]], (v) => (nodes[index] = v[0])}
|
||||
{post}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import type { Post } from '$lib/client/types'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
|
||||
import { ArrowDownCircle } from 'svelte-hero-icons'
|
||||
import Comment from './Comment.svelte'
|
||||
import Comments from './CommentTree.svelte'
|
||||
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
|
||||
@@ -34,7 +33,7 @@
|
||||
try {
|
||||
parent.loading = true
|
||||
|
||||
const newComments = await getClient(page.params.instance).getComments({
|
||||
const newComments = await client().getComments({
|
||||
max_depth: 5,
|
||||
parent_id: parent.comment_view.comment.id,
|
||||
type_: 'All',
|
||||
@@ -54,7 +53,7 @@
|
||||
// 0.18.2 -> 0.18.3 broke this
|
||||
// so i'm adding this check
|
||||
const treeParent = tree.find(
|
||||
c => c.comment_view.comment.id == parent.comment_view.comment.id,
|
||||
(c) => c.comment_view.comment.id == parent.comment_view.comment.id,
|
||||
)
|
||||
|
||||
if (treeParent) {
|
||||
@@ -130,15 +129,8 @@
|
||||
)
|
||||
}
|
||||
}}
|
||||
icon={ArrowDownCircle}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={ArrowDownCircle}
|
||||
micro
|
||||
size="16"
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
{/snippet}
|
||||
{$t('comment.more', {
|
||||
comments: node.comment_view.counts.child_count,
|
||||
})}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export { default as Comment } from './Comment.svelte'
|
||||
export { default as CommentActions } from './CommentActions.svelte'
|
||||
export { default as CommentForm } from './CommentForm.svelte'
|
||||
export { default as CommentItem } from './CommentItem.svelte'
|
||||
export { default as CommentListVirtualizer } from './CommentListVirtualizer.svelte'
|
||||
export { default as CommentTree } from './CommentTree.svelte'
|
||||
export { default as CommentVote } from './CommentVote.svelte'
|
||||
|
||||
export * from './comments.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'
|
||||
@@ -139,7 +139,6 @@
|
||||
loading.subscribing = false
|
||||
}
|
||||
|
||||
|
||||
let setFlair = $state(false)
|
||||
|
||||
interface Props {
|
||||
@@ -155,7 +154,6 @@
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
|
||||
{#await community_view}
|
||||
<div
|
||||
class="w-full h-full grid place-items-center"
|
||||
@@ -165,9 +163,12 @@
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{:then community_view}
|
||||
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||
<CommunityFlair community={community_view.community.id} onsubmit={() => setFlair = !setFlair} />
|
||||
</Modal>
|
||||
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||
<CommunityFlair
|
||||
community={community_view.community.id}
|
||||
onsubmit={() => (setFlair = !setFlair)}
|
||||
/>
|
||||
</Modal>
|
||||
<aside
|
||||
class={[
|
||||
'min-w-full pt-0 text-slate-600 dark:text-zinc-400 flex flex-col gap-1',
|
||||
@@ -198,7 +199,7 @@
|
||||
</EndPlaceholder>
|
||||
{#if profile.current?.jwt}
|
||||
{@const subscribed = profile.current.user?.follows.some(
|
||||
i => i.community.id == community_view.community.id,
|
||||
(i) => i.community.id == community_view.community.id,
|
||||
)}
|
||||
<Button
|
||||
disabled={loading.subscribing}
|
||||
@@ -209,25 +210,19 @@
|
||||
onclick={() => subscribe(community_view)}
|
||||
class="px-4 relative z-[inherit]"
|
||||
alignment="left"
|
||||
icon={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||
mini
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
{subscribed
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{#if client().setFlair}
|
||||
<SidebarButton
|
||||
onclick={() => setFlair = !setFlair}
|
||||
rounding="xl"
|
||||
icon={Tag}
|
||||
label={$t('cards.community.flair')}
|
||||
/>
|
||||
{#if client().setFlair}
|
||||
<SidebarButton
|
||||
onclick={() => (setFlair = !setFlair)}
|
||||
rounding="xl"
|
||||
icon={Tag}
|
||||
label={$t('cards.community.flair')}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if profile.current?.user && amMod(profile.current.user, community_view.community)}
|
||||
@@ -269,10 +264,8 @@
|
||||
size="lg"
|
||||
onclick={() =>
|
||||
block(community_view.community.id, !community_view.blocked)}
|
||||
icon={NoSymbol}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={NoSymbol} size="16" mini />
|
||||
{/snippet}
|
||||
{community_view.blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
@@ -282,10 +275,8 @@
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
onclick={() => blockInstance(community_view.community.instance_id)}
|
||||
icon={BuildingOffice2}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={BuildingOffice2} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -312,10 +303,8 @@
|
||||
dismissable: true,
|
||||
type: 'error',
|
||||
})}
|
||||
icon={Fire}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -364,7 +353,7 @@
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={moderators.map(i => ({
|
||||
items={moderators.map((i) => ({
|
||||
id: i.moderator.id,
|
||||
name: i.moderator.display_name || i.moderator.name,
|
||||
url: userLink(i.moderator),
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</script>
|
||||
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import ImageInputUpload from '$lib/components/form/ImageInputUpload.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient, site } from '$lib/client/lemmy.svelte'
|
||||
import { client, site } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Label,
|
||||
MenuButton,
|
||||
Switch,
|
||||
TextInput,
|
||||
toast,
|
||||
Option,
|
||||
Select,
|
||||
Material,
|
||||
Menu,
|
||||
} from 'mono-svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import Select from 'mono-svelte/forms/select/Select.svelte'
|
||||
import Material from 'mono-svelte/materials/Material.svelte'
|
||||
import Menu from 'mono-svelte/popover/Menu.svelte'
|
||||
import { GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
try {
|
||||
const res = edit
|
||||
? await getClient().editCommunity({
|
||||
? await client().editCommunity({
|
||||
title: formData.displayName,
|
||||
description: formData.sidebar,
|
||||
nsfw: formData.nsfw,
|
||||
@@ -79,7 +79,7 @@
|
||||
visibility: formData.visibility,
|
||||
discussion_languages: formData.languages,
|
||||
})
|
||||
: await getClient().createCommunity({
|
||||
: await client().createCommunity({
|
||||
name: formData.name,
|
||||
title: formData.displayName,
|
||||
description: formData.sidebar,
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
if (profile.current.user) {
|
||||
const c = profile.current.user.moderates
|
||||
.map(m => m.community.id)
|
||||
.map((m) => m.community.id)
|
||||
.indexOf(res.community_view.community.id)
|
||||
if (c != -1) {
|
||||
profile.current.user.moderates[c] = {
|
||||
@@ -139,14 +139,14 @@
|
||||
</script>
|
||||
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
class="flex flex-col gap-4 h-full w-full"
|
||||
>
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header>{$t('routes.createCommunity')}</Header>
|
||||
<Header>{$t('form.post.community')}</Header>
|
||||
{/if}
|
||||
<TextInput
|
||||
required
|
||||
@@ -188,7 +188,7 @@
|
||||
</Select>
|
||||
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<Label>{$t('form.profile.languages.title')}</Label>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if site.data}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
@@ -201,7 +201,7 @@
|
||||
</Badge>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#each site.data.all_languages.filter(l => !formData.languages?.includes(l.id)) as language (language.id)}
|
||||
{#each site.data.all_languages.filter((l) => !formData.languages?.includes(l.id)) as language (language.id)}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
@@ -217,7 +217,7 @@
|
||||
</Menu>
|
||||
{#each formData.languages ?? [] as languageId, index (languageId)}
|
||||
{@const language = site.data.all_languages.find(
|
||||
l => l.id == languageId,
|
||||
(l) => l.id == languageId,
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -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 {
|
||||
@@ -14,7 +14,15 @@
|
||||
CommunityModeratorView,
|
||||
SubscribedType,
|
||||
} from '$lib/client/types'
|
||||
import { action, Button, Menu, MenuButton, Modal, modal, toast } from 'mono-svelte'
|
||||
import {
|
||||
action,
|
||||
Button,
|
||||
Menu,
|
||||
MenuButton,
|
||||
Modal,
|
||||
modal,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import {
|
||||
BuildingOffice2,
|
||||
Check,
|
||||
@@ -61,9 +69,11 @@
|
||||
let setFlair = $state(false)
|
||||
</script>
|
||||
|
||||
|
||||
<Modal title={$t('cards.community.flair')} bind:open={setFlair}>
|
||||
<CommunityFlair community={community.id} onsubmit={() => setFlair = !setFlair} />
|
||||
<CommunityFlair
|
||||
community={community.id}
|
||||
onsubmit={() => (setFlair = !setFlair)}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
<EntityHeader
|
||||
@@ -119,7 +129,7 @@
|
||||
<hr class="flex-1 border-slate-200 dark:border-zinc-800 mx-3" />
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={moderators.map(m => ({
|
||||
items={moderators.map((m) => ({
|
||||
id: m.moderator.id,
|
||||
name: m.moderator.name,
|
||||
url: userLink(m.moderator),
|
||||
@@ -129,7 +139,12 @@
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
<div class={["flex items-center gap-2 h-max w-max", compact == 'lg' && 'lg:hidden']}>
|
||||
<div
|
||||
class={[
|
||||
'flex items-center gap-2 h-max w-max',
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
]}
|
||||
>
|
||||
{#if profile.current?.jwt}
|
||||
<Subscribe
|
||||
community={{
|
||||
@@ -152,14 +167,8 @@
|
||||
}}
|
||||
class="relative z-[inherit]"
|
||||
rounding="pill"
|
||||
icon={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
@@ -167,13 +176,19 @@
|
||||
{/snippet}
|
||||
</Subscribe>
|
||||
|
||||
<Button size="custom" class="h-9 aspect-square" rounding="pill" onclick={() => setFlair = !setFlair} aria-label={$t('cards.community.flair')}>
|
||||
<Button
|
||||
size="custom"
|
||||
class="h-9 aspect-square"
|
||||
rounding="pill"
|
||||
onclick={() => (setFlair = !setFlair)}
|
||||
aria-label={$t('cards.community.flair')}
|
||||
>
|
||||
<Icon src={Tag} size="16" micro />
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.user && profile.current.user.moderates
|
||||
.map(c => c.community.id)
|
||||
.map((c) => c.community.id)
|
||||
.includes(community.id)}
|
||||
<Button
|
||||
color="secondary"
|
||||
@@ -190,11 +205,13 @@
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
{#snippet target(attachment)}
|
||||
<Button {@attach attachment} size="custom" rounding="pill" class="h-8.5 aspect-square">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
<Button
|
||||
{@attach attachment}
|
||||
size="custom"
|
||||
rounding="pill"
|
||||
class="h-8.5 aspect-square"
|
||||
icon={EllipsisHorizontal}
|
||||
></Button>
|
||||
{/snippet}
|
||||
<MenuButton href="/modlog?community={community.id}">
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
@@ -214,10 +231,8 @@
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
onclick={() => block(community.id, !blocked)}
|
||||
icon={NoSymbol}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={NoSymbol} size="16" mini />
|
||||
{/snippet}
|
||||
{blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
@@ -227,10 +242,8 @@
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
onclick={() => blockInstance(community.instance_id)}
|
||||
icon={BuildingOffice2}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={BuildingOffice2} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -257,10 +270,8 @@
|
||||
dismissable: true,
|
||||
type: 'error',
|
||||
})}
|
||||
icon={Fire}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import LabelStat from '$lib/components/ui/LabelStat.svelte'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
@@ -8,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'
|
||||
@@ -23,6 +22,7 @@
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
|
||||
import { CommunityCard } from '.'
|
||||
|
||||
interface Props {
|
||||
community: CommunityView
|
||||
@@ -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}
|
||||
@@ -199,10 +201,8 @@
|
||||
? 'aspect-square @md:px-2 @md:min-w-30 @md:aspect-auto'
|
||||
: 'px-3',
|
||||
]}
|
||||
icon={subscribed ? Check : Plus}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={subscribed ? Check : Plus} size="16" micro />
|
||||
{/snippet}
|
||||
<span class={[view == 'compact' && 'hidden', '@md:block']}>
|
||||
{#if subscribed}
|
||||
{$t('cards.community.subscribed')}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export { default as CommunityCard } from './CommunityCard.svelte'
|
||||
export { default as CommunityFlair } from './CommunityFlair.svelte'
|
||||
export { default as CommunityForm } from './CommunityForm.svelte'
|
||||
export { default as CommunityHeader } from './CommunityHeader.svelte'
|
||||
export { default as CommunityItem } from './CommunityItem.svelte'
|
||||
export { default as CommunityLink } from './CommunityLink.svelte'
|
||||
export { default as CommunityTitle } from './CommunityTitle.svelte'
|
||||
+11
-11
@@ -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'
|
||||
@@ -13,18 +13,18 @@
|
||||
ServerStack,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { ClassValue, HTMLAttributes } from 'svelte/elements'
|
||||
import EndPlaceholder from '../ui/EndPlaceholder.svelte'
|
||||
import Expandable from '../ui/Expandable.svelte'
|
||||
import LabelStat from '../ui/LabelStat.svelte'
|
||||
import SidebarButton from '../ui/sidebar/SidebarButton.svelte'
|
||||
import ItemList from './generic/ItemList.svelte'
|
||||
import { optimizeImageURL } from './post/helpers'
|
||||
import EndPlaceholder from '../../ui/EndPlaceholder.svelte'
|
||||
import Expandable from '../../ui/Expandable.svelte'
|
||||
import LabelStat from '../../ui/LabelStat.svelte'
|
||||
import SidebarButton from '../../ui/sidebar/SidebarButton.svelte'
|
||||
import ItemList from '../generic/ItemList.svelte'
|
||||
import { optimizeImageURL } from '../post/helpers'
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||
site: SiteView
|
||||
taglines?: Tagline[] | undefined
|
||||
admins?: PersonView[] | undefined
|
||||
version?: string | undefined
|
||||
taglines?: Tagline[]
|
||||
admins?: PersonView[]
|
||||
version?: string
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={admins.map(i => ({
|
||||
items={admins.map((i) => ({
|
||||
id: i.person.id,
|
||||
name: i.person.display_name || i.person.name,
|
||||
url: userLink(i.person),
|
||||
@@ -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,18 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community, Person } from '$lib/client/types'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { Label, toast, Button, Modal, Switch } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Button, Checkbox, Modal } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import CommunityLink from '../community/CommunityLink.svelte'
|
||||
import Duration from '$lib/components/form/Duration.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { CommunityLink } from '../community'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
@@ -57,7 +53,7 @@
|
||||
}
|
||||
|
||||
if (community) {
|
||||
await getClient().banFromCommunity({
|
||||
await client().banFromCommunity({
|
||||
ban: !banned,
|
||||
community_id: community.id,
|
||||
person_id: item.id,
|
||||
@@ -66,7 +62,7 @@
|
||||
expires: date,
|
||||
})
|
||||
} else {
|
||||
await getClient().banPerson({
|
||||
await client().banPerson({
|
||||
ban: !banned,
|
||||
person_id: item.id,
|
||||
reason: reason || undefined,
|
||||
@@ -99,7 +95,13 @@
|
||||
title={banned ? $t('moderation.ban.unbanning') : $t('moderation.ban.banning')}
|
||||
>
|
||||
{#if item}
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(submit)}>
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
>
|
||||
<div class="flex items-center gap-1">
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<span class="font-bold">{item.name}</span>
|
||||
@@ -113,16 +115,15 @@
|
||||
label={$t('moderation.reason')}
|
||||
/>
|
||||
{#if !banned}
|
||||
<Checkbox bind:checked={deleteData}>
|
||||
<Switch bind:checked={deleteData}>
|
||||
{$t('moderation.ban.deleteData')}
|
||||
{#snippet description()}
|
||||
{$t('moderation.ban.warning')}
|
||||
{/snippet}
|
||||
</Checkbox>
|
||||
<div>
|
||||
<SectionTitle>{$t('moderation.ban.expires')}</SectionTitle>
|
||||
</Switch>
|
||||
<Label text={$t('moderation.ban.expires')}>
|
||||
<Duration bind:value={expires}></Duration>
|
||||
</div>
|
||||
</Label>
|
||||
{/if}
|
||||
<Button submit color="primary" {loading} disabled={loading} size="lg">
|
||||
{$t('form.submit')}
|
||||
|
||||
@@ -43,10 +43,7 @@
|
||||
{$t('moderation.label')}
|
||||
{/if}
|
||||
</MenuDivider>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{/snippet}
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item)} icon={Trash}>
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
? $t('moderation.restore')
|
||||
@@ -59,10 +56,8 @@
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
icon={ShieldExclamation}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{/snippet}
|
||||
{item.creator_banned_from_community
|
||||
? $t('moderation.ban.unbanFromCommunity')
|
||||
: $t('moderation.ban.banFromCommunity')}
|
||||
@@ -81,10 +76,8 @@
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
icon={Megaphone}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Megaphone} size="16" micro />
|
||||
{/snippet}
|
||||
{item.comment.distinguished
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
@@ -107,10 +100,11 @@
|
||||
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider showLabel>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() => remove(item, true)}
|
||||
icon={Fire}
|
||||
>
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -91,10 +91,8 @@
|
||||
color="warning-subtle"
|
||||
onclick={() => lock(!item.post.locked)}
|
||||
loading={acting}
|
||||
icon={item.post.locked ? LockOpen : LockClosed}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||
{/snippet}
|
||||
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
||||
</MenuButton>
|
||||
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
import { preventDefault, run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import type { CommentView, PostView } from '$lib/client/types'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||
import type { CommentView, PostView } from '$lib/client/types'
|
||||
import { Button, Modal, Select, Switch, toast } from 'mono-svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||
import { Fire, Trash } from 'svelte-hero-icons'
|
||||
import { Comment } from '../comment'
|
||||
import { Post } from '../post'
|
||||
import { amMod, isAdmin } from './moderation'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
@@ -257,10 +257,8 @@
|
||||
{loading}
|
||||
disabled={loading}
|
||||
submit
|
||||
icon={purge ? Fire : Trash}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" />
|
||||
{/snippet}
|
||||
{#if purge}
|
||||
{$t('admin.purge')}
|
||||
{:else}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
import { preventDefault, run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
@@ -15,6 +13,8 @@
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Post } from '../post'
|
||||
import { Comment } from '../comment'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
if (isPostView(item))
|
||||
return await client()
|
||||
.listPostLikes({ post_id: item.post.id, limit: 50, page: page })
|
||||
.then(i => i.post_likes)
|
||||
.then((i) => i.post_likes)
|
||||
if (isCommentView(item))
|
||||
return await client()
|
||||
.listCommentLikes({
|
||||
@@ -37,7 +37,7 @@
|
||||
limit: 50,
|
||||
page: page,
|
||||
})
|
||||
.then(i => i.comment_likes)
|
||||
.then((i) => i.comment_likes)
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import type {
|
||||
Comment,
|
||||
CommentView,
|
||||
Community,
|
||||
MyUserInfo,
|
||||
@@ -55,7 +56,7 @@ export const modals = writable<Modals>({
|
||||
})
|
||||
|
||||
export function report(item: PostView | CommentView | PrivateMessageView) {
|
||||
modals.update(m => ({
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
reporting: {
|
||||
open: true,
|
||||
@@ -65,7 +66,7 @@ export function report(item: PostView | CommentView | PrivateMessageView) {
|
||||
}
|
||||
|
||||
export function remove(item: SubmissionView, purge: boolean = false) {
|
||||
modals.update(m => ({
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
removing: {
|
||||
open: true,
|
||||
@@ -76,7 +77,7 @@ export function remove(item: SubmissionView, purge: boolean = false) {
|
||||
}
|
||||
|
||||
export function ban(banned: boolean, item: Person, community?: Community) {
|
||||
modals.update(m => ({
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
banning: {
|
||||
open: true,
|
||||
@@ -95,7 +96,7 @@ export async function feature(featured: boolean, item: Comment, jwt: string) {
|
||||
}
|
||||
|
||||
export async function viewVotes(item: PostView | CommentView) {
|
||||
modals.update(m => ({
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
votes: {
|
||||
open: true,
|
||||
@@ -105,7 +106,7 @@ export async function viewVotes(item: PostView | CommentView) {
|
||||
}
|
||||
|
||||
export const amMod = (me: MyUserInfo, community: Community) =>
|
||||
me.moderates.map(c => c.community.id).includes(community.id) ||
|
||||
me.moderates.map((c) => c.community.id).includes(community.id) ||
|
||||
(community.local && isAdmin(me))
|
||||
|
||||
export const amModOfAny = (me?: MyUserInfo) =>
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import PostActions from '$lib/components/lemmy/post/actions/PostActions.svelte'
|
||||
import { mediaType } from '$lib/components/lemmy/post/helpers.js'
|
||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
||||
import PostMeta, {
|
||||
parseTags,
|
||||
type Tag,
|
||||
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import PostBody from './PostBody.svelte'
|
||||
import {
|
||||
type Tag,
|
||||
PostMeta,
|
||||
PostActions,
|
||||
PostMedia,
|
||||
PostBody,
|
||||
parseTags,
|
||||
mediaType,
|
||||
PostMediaCompact,
|
||||
} from '.'
|
||||
|
||||
function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined {
|
||||
const tagContent = tags.map(t => t.content.toLowerCase())
|
||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||
|
||||
let rule: 'blur-sm' | 'hide' | undefined
|
||||
if (settings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
|
||||
@@ -94,7 +95,7 @@
|
||||
published={publishedToDate(post.post.published)}
|
||||
{badges}
|
||||
subscribed={profile.current?.user?.follows
|
||||
.map(c => c.community.id)
|
||||
.map((c) => c.community.id)
|
||||
.includes(post.community.id)
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'}
|
||||
|
||||
@@ -54,9 +54,11 @@ dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36`
|
||||
onclick={() => (expanded = !expanded)}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
class="text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0 {expanded
|
||||
? 'bg-slate-200/50 dark:bg-zinc-900 border shadow-md'
|
||||
: ''} left-1/2 -translate-x-1/2 mb-4"
|
||||
class={[
|
||||
'text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0',
|
||||
'left-1/2 -translate-x-1/2 mb-4',
|
||||
expanded && 'bg-slate-200/50 dark:bg-zinc-900 shadow-md',
|
||||
]}
|
||||
title="Expand"
|
||||
>
|
||||
<Icon
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import Post from './Post.svelte'
|
||||
import { Post } from '.'
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
<script lang="ts" module>
|
||||
type BadgeType =
|
||||
| 'nsfw'
|
||||
| 'saved'
|
||||
| 'featured'
|
||||
| 'deleted'
|
||||
| 'removed'
|
||||
| 'locked'
|
||||
| 'moderator'
|
||||
| 'admin'
|
||||
export interface Tag {
|
||||
content: string
|
||||
color?: string
|
||||
@@ -11,6 +20,64 @@
|
||||
['CW', { content: 'CW', color: '#ff000040' }],
|
||||
])
|
||||
|
||||
const badgeToData: Map<
|
||||
BadgeType,
|
||||
{
|
||||
icon: IconSource
|
||||
color: 'red-subtle' | 'yellow-subtle' | 'green-subtle'
|
||||
label: string
|
||||
}
|
||||
> = new Map([
|
||||
[
|
||||
'nsfw',
|
||||
{
|
||||
icon: ExclamationTriangle,
|
||||
color: 'red-subtle',
|
||||
label: t.get('post.badges.nsfw'),
|
||||
},
|
||||
],
|
||||
[
|
||||
'saved',
|
||||
{
|
||||
icon: Bookmark,
|
||||
color: 'yellow-subtle',
|
||||
label: t.get('post.badges.saved'),
|
||||
},
|
||||
],
|
||||
[
|
||||
'featured',
|
||||
{
|
||||
icon: Megaphone,
|
||||
color: 'green-subtle',
|
||||
label: t.get('post.badges.featured'),
|
||||
},
|
||||
],
|
||||
[
|
||||
'removed',
|
||||
{
|
||||
icon: Trash,
|
||||
color: 'green-subtle',
|
||||
label: t.get('post.badges.removed'),
|
||||
},
|
||||
],
|
||||
[
|
||||
'deleted',
|
||||
{
|
||||
icon: Trash,
|
||||
color: 'red-subtle',
|
||||
label: t.get('post.badges.deleted'),
|
||||
},
|
||||
],
|
||||
[
|
||||
'locked',
|
||||
{
|
||||
icon: LockClosed,
|
||||
color: 'yellow-subtle',
|
||||
label: t.get('post.badges.locked'),
|
||||
},
|
||||
],
|
||||
])
|
||||
|
||||
export const parseTags = (
|
||||
title?: string,
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
@@ -20,11 +87,11 @@
|
||||
|
||||
const newTitle = title
|
||||
.toString()
|
||||
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, match => {
|
||||
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, (match) => {
|
||||
const contents = match.split(',').map((part: string) => part.trim())
|
||||
|
||||
contents
|
||||
.map(i => i.replaceAll(/(\[|\])/g, ''))
|
||||
.map((i) => i.replaceAll(/(\[|\])/g, ''))
|
||||
.forEach((content: string) => {
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
@@ -43,7 +110,8 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import type { Community, Person, SubscribedType } from '$lib/client/types'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
@@ -52,10 +120,8 @@
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { settings, type View } from '$lib/settings.svelte'
|
||||
import type { Community, Person, SubscribedType } from '$lib/client/types'
|
||||
import { Badge, modal, Popover } from 'mono-svelte'
|
||||
import { Badge, Material, modal, Popover } from 'mono-svelte'
|
||||
import {
|
||||
Bookmark,
|
||||
ExclamationTriangle,
|
||||
@@ -69,7 +135,7 @@
|
||||
Trash,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import Material from 'mono-svelte/materials/Material.svelte'
|
||||
import { CommunityLink } from '../community'
|
||||
|
||||
interface Props {
|
||||
community?: Community
|
||||
@@ -83,16 +149,7 @@
|
||||
edited?: string
|
||||
view?: View
|
||||
// Badges
|
||||
badges?: {
|
||||
nsfw: boolean
|
||||
saved: boolean
|
||||
featured: boolean
|
||||
deleted: boolean
|
||||
removed: boolean
|
||||
locked: boolean
|
||||
moderator: boolean
|
||||
admin: boolean
|
||||
}
|
||||
badges?: Record<BadgeType, boolean>
|
||||
tags?: Tag[]
|
||||
style?: string
|
||||
titleClass?: string
|
||||
@@ -274,66 +331,18 @@
|
||||
</a>
|
||||
{/each}
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
{#snippet icon()}
|
||||
<Icon src={ExclamationTriangle} size="14" micro />
|
||||
{/snippet}
|
||||
{$t('post.badges.nsfw')}
|
||||
{#each Object.keys(badges)
|
||||
// filter by ones that are true
|
||||
.filter((i) => badges[i as BadgeType] == true)
|
||||
// get from predetermined map
|
||||
.map((i) => badgeToData.get(i as BadgeType))
|
||||
// remove null
|
||||
.filter((i) => i != undefined) as badge}
|
||||
<Badge label={badge.label} color={badge.color} allowIconOnly
|
||||
>{#snippet icon()}
|
||||
<Icon src={badge.icon} micro size="14" />{/snippet}{badge.label}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.saved}
|
||||
<Badge
|
||||
label={$t('post.badges.saved')}
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
{#snippet icon()}
|
||||
<Icon src={Bookmark} micro size="14" />
|
||||
{/snippet}
|
||||
{$t('post.badges.saved')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.locked}
|
||||
<Badge
|
||||
label={$t('post.badges.locked')}
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
{#snippet icon()}
|
||||
<Icon src={LockClosed} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.removed}
|
||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.deleted}
|
||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.featured}
|
||||
<Badge
|
||||
label={$t('post.badges.featured')}
|
||||
color="green-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
{#snippet icon()}
|
||||
<Icon src={Megaphone} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{/each}
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
@@ -341,8 +350,7 @@
|
||||
{@const useAttachedUrl = settings.posts.titleOpensUrl && postUrl}
|
||||
<h3
|
||||
class={[
|
||||
'max-sm:m-0!',
|
||||
'font-medium',
|
||||
'font-medium max-sm:mt-0!',
|
||||
titleClass,
|
||||
settings.markReadPosts && read && 'text-slate-600 dark:text-zinc-400',
|
||||
view == 'compact' ? 'text-base' : 'text-lg',
|
||||
@@ -352,10 +360,8 @@
|
||||
<a
|
||||
href={useAttachedUrl
|
||||
? postUrl
|
||||
: `/post/${encodeURIComponent(instance.data)}/${id}`}
|
||||
target={useAttachedUrl
|
||||
? '_blank'
|
||||
: undefined}
|
||||
: `/post/${encodeURIComponent(profile.current.instance)}/${id}`}
|
||||
target={useAttachedUrl ? '_blank' : undefined}
|
||||
rel={useAttachedUrl ? 'noopener noreferrer' : undefined}
|
||||
class="inline-block hover:underline hover:text-primary-900 dark:hover:text-primary-100 transition-colors"
|
||||
>
|
||||
|
||||
@@ -76,8 +76,8 @@
|
||||
vote = newVote
|
||||
|
||||
voteItem(post, newVote)
|
||||
.then(res => ({ upvotes, downvotes, score } = res))
|
||||
.catch(e => {
|
||||
.then((res) => ({ upvotes, downvotes, score } = res))
|
||||
.catch((e) => {
|
||||
toast({ content: errorMessage(e), type: 'error' })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
ShieldCheck,
|
||||
} from 'svelte-hero-icons'
|
||||
import { postLink } from '../helpers'
|
||||
import PostVote from '../PostVote.svelte'
|
||||
import { PostVote } from '..'
|
||||
|
||||
let saving = $state(false)
|
||||
let editing = $state(false)
|
||||
@@ -61,7 +61,7 @@
|
||||
<PostForm
|
||||
edit
|
||||
editingPost={post.post}
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
editing = false
|
||||
post = e
|
||||
onedit?.(e)
|
||||
@@ -124,11 +124,8 @@
|
||||
color="secondary"
|
||||
rounding="pill"
|
||||
class={buttonSquare}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={BugAnt}
|
||||
></Button>
|
||||
{/if}
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
|
||||
@@ -164,11 +161,8 @@
|
||||
loading={saving}
|
||||
disabled={saving}
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={post.saved ? BookmarkSlash : Bookmark}
|
||||
></Button>
|
||||
{/if}
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
@@ -180,11 +174,8 @@
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={EllipsisHorizontal}
|
||||
></Button>
|
||||
{/snippet}
|
||||
{#snippet children(open)}
|
||||
{#if open}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { PiefedClient } from '$lib/client/piefed/piefed'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { deleteItem, markAsRead } from '$lib/lemmy/contentview'
|
||||
import { setSessionStorage } from '$lib/session'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { instanceToURL } from '$lib/util.svelte'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { Button, Menu, MenuButton, toast } from 'mono-svelte'
|
||||
import {
|
||||
ArrowTopRightOnSquare,
|
||||
@@ -15,7 +17,6 @@
|
||||
EyeSlash,
|
||||
Flag,
|
||||
GlobeAlt,
|
||||
Icon,
|
||||
MapPin,
|
||||
PencilSquare,
|
||||
Share,
|
||||
@@ -24,8 +25,6 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import { report } from '../../moderation/moderation'
|
||||
import { hidePost } from '../helpers'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { PiefedClient } from '$lib/client/piefed/piefed'
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
@@ -52,10 +51,7 @@
|
||||
</script>
|
||||
|
||||
{#if profile.current?.user && profile.current?.jwt && profile.current.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => (editing = true)} icon={PencilSquare}>
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -65,10 +61,8 @@
|
||||
if (profile.current?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read)
|
||||
}}
|
||||
icon={post.read ? EyeSlash : Eye}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
@@ -78,10 +72,8 @@
|
||||
<MenuButton
|
||||
onclick={() => share()}
|
||||
class={['flex-1', !post.post.local && 'rounded-r-lg']}
|
||||
icon={Share}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
</MenuButton>
|
||||
{#if !post.post.local}
|
||||
@@ -94,27 +86,13 @@
|
||||
size="custom"
|
||||
class="w-6 h-6 self-center"
|
||||
data-autoclose="false"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={EllipsisHorizontal}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={EllipsisHorizontal}
|
||||
></Button>
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => share(true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={GlobeAlt} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => share(true)} icon={GlobeAlt}>
|
||||
{$t('filter.location.global')}
|
||||
</MenuButton>
|
||||
<MenuButton onclick={() => share(false)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={MapPin} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => share(false)} icon={MapPin}>
|
||||
{$t('filter.location.local')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -141,10 +119,8 @@
|
||||
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
icon={ArrowTopRightOnSquare}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if profile.current.user && post.creator.id == profile.current.user.local_user_view.person.id}
|
||||
@@ -154,10 +130,8 @@
|
||||
post.post.deleted = await deleteItem(post, !post.post.deleted)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
icon={Trash}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
@@ -177,19 +151,14 @@
|
||||
if (hidden) onhide?.(hidden)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
icon={XMark}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle" icon={Flag}>
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
|
||||
import { ArchiveBox, Plus } from 'svelte-hero-icons'
|
||||
import { Post } from '..'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
@@ -26,10 +26,7 @@
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<Button href="/communities" icon={Plus}>
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
@@ -26,6 +25,7 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { SvelteSet } from 'svelte/reactivity'
|
||||
import { fly } from 'svelte/transition'
|
||||
import { Post } from '..'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
@@ -54,7 +54,7 @@
|
||||
|
||||
const abortLoad = new AbortController()
|
||||
let seenIds = new SvelteSet<number>(
|
||||
feedData.posts.posts.map(post => post.post.id),
|
||||
feedData.posts.posts.map((post) => post.post.id),
|
||||
)
|
||||
|
||||
async function loadMore() {
|
||||
@@ -80,7 +80,7 @@
|
||||
sort: feedData.sort,
|
||||
type_: feedData.type_,
|
||||
})
|
||||
.catch(e => {
|
||||
.catch((e) => {
|
||||
throw new Error(e)
|
||||
})
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
feedData.cursor.next = newPosts.next_page
|
||||
feedData.posts.posts.push(
|
||||
...newPosts.posts.filter(post => {
|
||||
...newPosts.posts.filter((post) => {
|
||||
if (seenIds.has(post.post.id)) return false
|
||||
seenIds.add(post.post.id)
|
||||
return true
|
||||
@@ -107,7 +107,7 @@
|
||||
}
|
||||
|
||||
const callback: IntersectionObserverCallback = (entries, observer) => {
|
||||
entries.forEach(entry => {
|
||||
entries.forEach((entry) => {
|
||||
if (!entry.isIntersecting) return
|
||||
|
||||
const element = entry.target as HTMLElement
|
||||
@@ -147,7 +147,7 @@
|
||||
const feed = document.getElementById('feed')
|
||||
if (!feed) return
|
||||
|
||||
new MutationObserver(mutations => {
|
||||
new MutationObserver((mutations) => {
|
||||
mutations.forEach(({ addedNodes, removedNodes }) => {
|
||||
addedNodes.forEach(observePost)
|
||||
removedNodes.forEach(unobservePost)
|
||||
@@ -181,10 +181,12 @@
|
||||
title={$t('routes.frontpage.empty.title')}
|
||||
description={$t('routes.frontpage.empty.description')}
|
||||
>
|
||||
<Button href="/communities" rounding="pill" color="primary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" mini />
|
||||
{/snippet}
|
||||
<Button
|
||||
href="/communities"
|
||||
rounding="pill"
|
||||
color="primary"
|
||||
icon={ArrowTopRightOnSquare}
|
||||
>
|
||||
{$t('nav.communities')}
|
||||
</Button>
|
||||
</Placeholder>
|
||||
@@ -265,10 +267,7 @@
|
||||
community_name: feedData.community_name ?? 'undefined',
|
||||
})}
|
||||
{#snippet action()}
|
||||
<Button color="tertiary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronDoubleUp} size="16" micro />
|
||||
{/snippet}
|
||||
<Button color="tertiary" icon={ChevronDoubleUp}>
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import type { PostView } from '$lib/client/types'
|
||||
import { SvelteMap, SvelteSet } from 'svelte/reactivity'
|
||||
|
||||
export type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
crossposts: PostView[]
|
||||
}
|
||||
export type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
|
||||
|
||||
export const combineCrossposts = (
|
||||
posts: PostView[],
|
||||
): (PostViewWithCrossposts | PostViewWithoutCrossposts)[] => {
|
||||
const urlMap = new SvelteMap<
|
||||
string,
|
||||
PostViewWithCrossposts | PostViewWithoutCrossposts
|
||||
>()
|
||||
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
|
||||
const seenUrls = new SvelteSet<string>()
|
||||
|
||||
posts?.forEach(post => {
|
||||
if (
|
||||
!post ||
|
||||
(settings.hidePosts.deleted && post.post.deleted) ||
|
||||
(settings.hidePosts.removed && post.post.removed)
|
||||
)
|
||||
return
|
||||
if (!post?.post?.url) {
|
||||
results.push(post)
|
||||
return
|
||||
}
|
||||
|
||||
const existing = urlMap.get(post.post.url)
|
||||
if (existing) {
|
||||
existing.withCrossposts = true
|
||||
if (existing.withCrossposts) {
|
||||
existing.crossposts = [...(existing.crossposts || []), post]
|
||||
}
|
||||
|
||||
urlMap.set(post.post.url, existing)
|
||||
} else {
|
||||
urlMap.set(post.post.url, post)
|
||||
results.push(post)
|
||||
}
|
||||
seenUrls.add(post.post.url)
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { Header } from '$lib/components/ui/layout'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { client, site } from '$lib/client/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
@@ -24,8 +24,8 @@
|
||||
TextArea,
|
||||
TextInput,
|
||||
toast,
|
||||
Option,
|
||||
} from 'mono-svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import { onDestroy, onMount } from 'svelte'
|
||||
import {
|
||||
ArrowPath,
|
||||
@@ -96,15 +96,7 @@
|
||||
let communities: Community[] = $state([])
|
||||
|
||||
onMount(async () => {
|
||||
if (editingPost) {
|
||||
data.url = editingPost.url ?? ''
|
||||
data.body = editingPost.body ?? ''
|
||||
data.title = editingPost.name
|
||||
data.nsfw = editingPost.nsfw
|
||||
data.alt_text = editingPost.alt_text
|
||||
data.thumbnail = editingPost.thumbnail_url
|
||||
data.language_id = editingPost.language_id.toString()
|
||||
}
|
||||
if (editingPost) Object.assign(data, editingPost)
|
||||
|
||||
if (passedCommunity) {
|
||||
data.community = passedCommunity
|
||||
@@ -116,12 +108,11 @@
|
||||
limit: 40,
|
||||
})
|
||||
|
||||
communities = list.communities.map(c => c.community)
|
||||
communities = list.communities.map((c) => c.community)
|
||||
}
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
// @ts-expect-error TODO get rid of sessionStorage stuff
|
||||
if (saveDraft) setSessionStorage('postDraft', data)
|
||||
})
|
||||
|
||||
@@ -134,7 +125,6 @@
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!data.title || !profile.current?.jwt) return
|
||||
if (data.url && data.url != '') {
|
||||
try {
|
||||
new URL(data.url)
|
||||
@@ -209,7 +199,7 @@
|
||||
if (res.metadata.description)
|
||||
data.body = res.metadata.description
|
||||
.split('\n')
|
||||
.map(l => `> ${l}`)
|
||||
.map((l) => `> ${l}`)
|
||||
.join('\n')
|
||||
|
||||
toast({
|
||||
@@ -254,7 +244,7 @@
|
||||
{#await import('$lib/components/form/ImageInputModal.svelte') then { default: UploadModal }}
|
||||
<UploadModal
|
||||
bind:open={uploadingImage}
|
||||
bind:imageUrl={() => '', v => (data.url = v)}
|
||||
bind:imageUrl={() => '', (v) => (data.url = v)}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
@@ -262,7 +252,7 @@
|
||||
{#if addAltText}
|
||||
<Modal title={$t('form.post.altText')} bind:open={addAltText}>
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
addAltText = !addAltText
|
||||
}}
|
||||
@@ -277,7 +267,7 @@
|
||||
{/if}
|
||||
|
||||
<form
|
||||
onsubmit={e => {
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
@@ -298,7 +288,7 @@
|
||||
listing_type="All"
|
||||
label={$t('form.post.community')}
|
||||
required
|
||||
onselect={e => {
|
||||
onselect={(e) => {
|
||||
const c = e
|
||||
if (!c) {
|
||||
data.community = null
|
||||
@@ -370,10 +360,8 @@
|
||||
size="sm"
|
||||
color={data.alt_text ? 'primary' : 'ghost'}
|
||||
class="text-xs"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||
{/snippet}{$t('form.post.altText')}
|
||||
icon={ChatBubbleBottomCenterText}
|
||||
>{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
@@ -382,10 +370,8 @@
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
icon={Photo}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Photo} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
@@ -396,10 +382,8 @@
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
icon={Sparkles}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Sparkles} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import { isImage, isVideo } from '$lib/ui/image'
|
||||
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
|
||||
import type { CommentView, PersonView, Post } from '$lib/client/types'
|
||||
import {
|
||||
canParseUrl,
|
||||
findClosestNumber,
|
||||
isImage,
|
||||
isVideo,
|
||||
} from '$lib/util.svelte'
|
||||
|
||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
me.person.id == comment.creator.id
|
||||
@@ -57,24 +61,23 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
||||
return url?.match?.(YOUTUBE_REGEX)
|
||||
}
|
||||
|
||||
export const postLink = (post: Post) =>
|
||||
`/post/${encodeURIComponent(instance.data)}/${post.id}`
|
||||
export function postLink(post: Post) {
|
||||
return `/post/${encodeURIComponent(profile.current.instance)}/${post.id}`
|
||||
}
|
||||
|
||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||
export type IframeType = 'youtube' | 'video' | 'none'
|
||||
|
||||
export const mediaType = (url?: string): MediaType => {
|
||||
if (url) {
|
||||
if (isImage(url)) return 'image'
|
||||
if (isVideo(url)) return 'iframe'
|
||||
if (isYoutubeLink(url)) return 'iframe'
|
||||
if (canParseUrl(url)) return 'embed'
|
||||
return 'none'
|
||||
}
|
||||
|
||||
export function mediaType(url?: string): MediaType {
|
||||
if (!url) return 'none'
|
||||
if (isImage(url)) return 'image'
|
||||
if (isVideo(url)) return 'iframe'
|
||||
if (isYoutubeLink(url)) return 'iframe'
|
||||
if (canParseUrl(url)) return 'embed'
|
||||
return 'none'
|
||||
}
|
||||
export const iframeType = (url: string): IframeType => {
|
||||
|
||||
export function iframeType(url: string): IframeType {
|
||||
if (isVideo(url)) return 'video'
|
||||
if (isYoutubeLink(url)) return 'youtube'
|
||||
return 'none'
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
export { default as Post } from './Post.svelte'
|
||||
export { default as PostBody } from './PostBody.svelte'
|
||||
export { default as PostItem } from './PostItem.svelte'
|
||||
export { default as PostMeta } from './PostMeta.svelte'
|
||||
export { default as PostVote } from './PostVote.svelte'
|
||||
export { default as PostMedia } from './media/PostMedia.svelte'
|
||||
export { default as PostMediaCompact } from './media/PostMediaCompact.svelte'
|
||||
export { default as PostImage } from './media/PostImage.svelte'
|
||||
export { default as PostIframe } from './media/PostIframe.svelte'
|
||||
export { default as PostLink } from './link/PostLink.svelte'
|
||||
export { default as VirtualFeed } from './feed/VirtualFeed.svelte'
|
||||
export { default as PostFeed } from './feed/PostFeed.svelte'
|
||||
export { default as PostForm } from './form/PostForm.svelte'
|
||||
export { default as PostActions } from './actions/PostActions.svelte'
|
||||
|
||||
export {
|
||||
type Tag,
|
||||
parseTags,
|
||||
textToTag,
|
||||
default as PostsMeta,
|
||||
} from './PostMeta.svelte'
|
||||
|
||||
export * from './helpers'
|
||||
@@ -14,7 +14,6 @@
|
||||
let { post, blur = false }: Props = $props()
|
||||
|
||||
let imageLoaded: boolean | null = $state(null)
|
||||
|
||||
onMount(() => {
|
||||
imageLoaded = false
|
||||
})
|
||||
@@ -88,11 +87,11 @@
|
||||
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
||||
rounded-full ml-auto w-max m-2 p-0 gap-1
|
||||
*:bg-white *:border *:border-slate-200 dark:*:border-zinc-800 dark:*:bg-zinc-900"
|
||||
onclick={e => e.stopPropagation()}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Button
|
||||
onclick={e => {
|
||||
onclick={(e) => {
|
||||
e.stopPropagation()
|
||||
modal({
|
||||
title: 'Alt',
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
iframeType,
|
||||
type MediaType,
|
||||
} from '$lib/components/lemmy/post/helpers.js'
|
||||
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { Post } from '$lib/client/types'
|
||||
import PostIframe from './PostIframe.svelte'
|
||||
import PostImage from './PostImage.svelte'
|
||||
import {
|
||||
PostImage,
|
||||
PostIframe,
|
||||
PostLink,
|
||||
type MediaType,
|
||||
iframeType,
|
||||
} from '..'
|
||||
|
||||
interface Props {
|
||||
view?: View
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
bestImageURL,
|
||||
postLink,
|
||||
type MediaType,
|
||||
} from '$lib/components/lemmy/post/helpers.js'
|
||||
import { bestImageURL, postLink, type MediaType } from '..'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { Post } from '$lib/client/types'
|
||||
import { modal } from 'mono-svelte'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import { modal, Button } from 'mono-svelte'
|
||||
import {
|
||||
DocumentText,
|
||||
ExclamationTriangle,
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</script>
|
||||
|
||||
<Search
|
||||
search={async q => {
|
||||
search={async (q) => {
|
||||
const users = (
|
||||
await getClient(instance).search({
|
||||
q: q || ' ',
|
||||
@@ -39,15 +39,15 @@
|
||||
listing_type: listing_type,
|
||||
sort: 'TopAll',
|
||||
})
|
||||
).users.map(c => c.person)
|
||||
).users.map((c) => c.person)
|
||||
|
||||
if (hideOwnUser) {
|
||||
const myself = profile.current.user?.local_user_view.person.id
|
||||
return users.filter(c => c.id != myself)
|
||||
return users.filter((c) => c.id != myself)
|
||||
}
|
||||
return users
|
||||
}}
|
||||
extractName={c => `${c.name}@${new URL(c.actor_id).hostname}`}
|
||||
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
|
||||
bind:query={q}
|
||||
{...rest}
|
||||
>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
disabled = false,
|
||||
rows = 2,
|
||||
// should be preprocess instead
|
||||
beforePreview = input => input,
|
||||
beforePreview = (input) => input,
|
||||
previewing = $bindable(false),
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
@@ -125,8 +125,8 @@
|
||||
<Modal title={$t('form.post.uploadImage')} bind:open={uploadingImage}>
|
||||
<ImageAttachForm
|
||||
bind:image
|
||||
onupload={e => {
|
||||
e.forEach(i => {
|
||||
onupload={(e) => {
|
||||
e.forEach((i) => {
|
||||
wrapSelection(`\n\n`, '')
|
||||
})
|
||||
}}
|
||||
@@ -293,7 +293,7 @@
|
||||
class="bg-inherit z-0 border-0 rounded-none ring-0! focus:ring-transparent! transition-none! resize-none"
|
||||
bind:value
|
||||
bind:element={textArea}
|
||||
onkeydown={e => {
|
||||
onkeydown={(e) => {
|
||||
if (disabled) return
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
handleKeydown(e)
|
||||
@@ -306,7 +306,7 @@
|
||||
}
|
||||
}}
|
||||
oninput={adjustHeight}
|
||||
onpaste={e => {
|
||||
onpaste={(e) => {
|
||||
if (!e.clipboardData?.files) return
|
||||
const files = Array.from(e.clipboardData.files)
|
||||
if (files[0]?.type.startsWith('image/')) {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
iframeType,
|
||||
mediaType,
|
||||
optimizeImageURL,
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
PostIframe,
|
||||
} from '$lib/components/lemmy/post'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getContext } from 'svelte'
|
||||
|
||||
@@ -101,7 +101,7 @@ const regexes = {
|
||||
/**
|
||||
* Convert links to photon links
|
||||
*/
|
||||
export const photonify = link => {
|
||||
export const photonify = (link) => {
|
||||
if (regexes.community.test(link)) {
|
||||
const match = link.match(regexes.community)
|
||||
if (!match) return
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
}
|
||||
}, debounceResize)
|
||||
|
||||
const observer = new ResizeObserver(entries => {
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
debouncedUpdate(entries)
|
||||
})
|
||||
|
||||
@@ -185,7 +185,7 @@
|
||||
|
||||
onMount(() => {
|
||||
if (virtualListEl && browser) {
|
||||
Array.from(virtualListEl.children).forEach(node => {
|
||||
Array.from(virtualListEl.children).forEach((node) => {
|
||||
const indexAttr = node.getAttribute('data-index')
|
||||
if (indexAttr === null) return
|
||||
const index = Number(indexAttr)
|
||||
@@ -207,7 +207,7 @@
|
||||
<svelte:window
|
||||
bind:scrollY={
|
||||
() => (useWindow ? scrollY : 0),
|
||||
v => {
|
||||
(v) => {
|
||||
if (useWindow) scrollY = v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
}: Props = $props()
|
||||
|
||||
let optimizedURLs = $derived(
|
||||
[2, 3, 6, -1].map(n => optimizeUrl(url, (res || width) * n)),
|
||||
[2, 3, 6, -1].map((n) => optimizeUrl(url, (res || width) * n)),
|
||||
)
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { Icon, Share, XMark } from 'svelte-hero-icons'
|
||||
import { Share, XMark } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
flex flex-col z-100 backdrop-blur-xs"
|
||||
transition:fade={{ duration: 150 }}
|
||||
onclick={() => history.back()}
|
||||
onkeydown={e => {
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') history.back()
|
||||
}}
|
||||
use:focusTrap
|
||||
@@ -55,7 +55,7 @@
|
||||
rounding="full"
|
||||
padding="none"
|
||||
color="uniform"
|
||||
onclick={e => e.stopPropagation()}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
onclick={() => {
|
||||
@@ -66,22 +66,16 @@
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
aria-label={$t('post.actions.more.share')}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={Share}
|
||||
></Button>
|
||||
<Button
|
||||
onclick={() => history.back()}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
aria-label={$t('common.back')}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={XMark}
|
||||
></Button>
|
||||
</Material>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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,15 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
||||
small?: boolean
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { small = false, class: clazz = '', children, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<span {...rest} class="{!small ? 'text-lg' : 'text-xs'} font-medium {clazz}">
|
||||
{@render children?.()}
|
||||
</span>
|
||||
@@ -1,16 +0,0 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<aside
|
||||
class="break-words flex shrink
|
||||
flex-col gap-4 px-6 max-w-full w-full h-full
|
||||
overflow-auto text-sm border-slate-200 dark:border-zinc-800 {clazz}"
|
||||
>
|
||||
{@render children?.()}
|
||||
</aside>
|
||||
File renamed without changes.
@@ -2,7 +2,7 @@
|
||||
import { navigating } from '$app/state'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
import { MagnifyingGlass } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
query?: string | null
|
||||
@@ -30,9 +30,6 @@
|
||||
title="Search"
|
||||
rounding="pill"
|
||||
loading={navigating.to?.route.id == '/search'}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={MagnifyingGlass} size="16" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={MagnifyingGlass}
|
||||
></Button>
|
||||
</div>
|
||||
@@ -0,0 +1,6 @@
|
||||
export { default as Header } from './pages/Header.svelte'
|
||||
export { default as Tabs } from './pages/Tabs.svelte'
|
||||
export { default as CommonList } from './CommonList.svelte'
|
||||
export { default as SearchBar } from './SearchBar.svelte'
|
||||
export { default as Shell } from './Shell.svelte'
|
||||
export { default as Pageination } from './Pageination.svelte'
|
||||
@@ -26,7 +26,7 @@
|
||||
}: Props = $props()
|
||||
|
||||
let matchType = $derived<('search' | 'pathname')[]>(
|
||||
routes.map(i =>
|
||||
routes.map((i) =>
|
||||
new URL(`https://example.com${i.href}`)?.search != ''
|
||||
? 'search'
|
||||
: 'pathname',
|
||||
@@ -39,7 +39,7 @@
|
||||
const hrefSearch = new Set(href.searchParams.values())
|
||||
// checks if there is any
|
||||
const usePathname = !routes.some(
|
||||
i =>
|
||||
(i) =>
|
||||
new Set(
|
||||
new URL(`https://example.com${i.href}`).searchParams.values(),
|
||||
).intersection(currentSearch).size > 0,
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
icon,
|
||||
href,
|
||||
adaptive = true,
|
||||
isSelectedFilter = path => href != undefined && path == href,
|
||||
isSelectedFilter = (path) => href != undefined && path == href,
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
label={$t('nav.admin')}
|
||||
icon={ServerStack}
|
||||
class="relative"
|
||||
isSelectedFilter={path => path.startsWith('/admin')}
|
||||
isSelectedFilter={(path) => path.startsWith('/admin')}
|
||||
/>
|
||||
{/if}
|
||||
{#if amModOfAny(profile.current?.user)}
|
||||
@@ -142,7 +142,7 @@
|
||||
<Spinner width={20} />
|
||||
</div>
|
||||
{:then { default: Profile }}
|
||||
<Profile />
|
||||
<Profile />
|
||||
{/await}
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation'
|
||||
|
||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||
import SiteCard from '$lib/components/lemmy/instance/InstanceCard.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { site } from '$lib/client/lemmy.svelte'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
@@ -66,10 +66,7 @@
|
||||
{/snippet}
|
||||
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton href="/inbox">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Inbox} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/inbox" icon={Inbox}>
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold py-0.5!">
|
||||
@@ -94,43 +91,25 @@
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuDivider>{$t('profile.profile')}</MenuDivider>
|
||||
<MenuButton href="/profile">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/profile" icon={UserCircle}>
|
||||
{$t('profile.profile')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/saved">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Bookmark} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/saved" icon={Bookmark}>
|
||||
{$t('profile.saved')}
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<MenuButton href="/accounts/login">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowLeftOnRectangle} mini size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/accounts/login" icon={ArrowLeftOnRectangle}>
|
||||
{$t('account.login')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/signup">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Identification} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/signup" icon={Identification}>
|
||||
{$t('account.signup')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton href="/accounts">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserGroup} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/accounts" icon={UserGroup}>
|
||||
{$t('account.accounts')}
|
||||
</MenuButton>
|
||||
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
|
||||
<MenuButton href="/settings">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Cog6Tooth} micro size="16" />
|
||||
{/snippet}
|
||||
<MenuButton href="/settings" icon={Cog6Tooth}>
|
||||
{$t('nav.menu.settings')}
|
||||
</MenuButton>
|
||||
<Select bind:value={theme.colorScheme} size="sm" placement="bottom">
|
||||
@@ -158,19 +137,11 @@
|
||||
</Option>
|
||||
{/snippet}
|
||||
</Select>
|
||||
<MenuButton href="/theme">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Swatch} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton href="/theme" icon={Swatch}>
|
||||
{$t('nav.menu.theme')}
|
||||
</MenuButton>
|
||||
{#if settings.debugInfo}
|
||||
<MenuButton href="/util">
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} mini size="16" />
|
||||
{/snippet}
|
||||
Debug
|
||||
</MenuButton>
|
||||
<MenuButton href="/util" icon={BugAnt}>Debug</MenuButton>
|
||||
{/if}
|
||||
<li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full">
|
||||
<div class="flex flex-row gap-2 w-full items-center">
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import { theme } from '$lib/ui/colors.svelte'
|
||||
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||
import { fuzzySearch } from '$lib/util.svelte'
|
||||
import { TextInput } from 'mono-svelte'
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
@@ -55,16 +55,16 @@
|
||||
|
||||
if (term.length < 1) {
|
||||
if (breadcrumbs.length <= 0) {
|
||||
filteredGroups = groups.map(group => ({
|
||||
filteredGroups = groups.map((group) => ({
|
||||
...group,
|
||||
actions: flattenActions(group.actions, false),
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
filteredGroups = groups
|
||||
.map(group => {
|
||||
.map((group) => {
|
||||
const scoredActions = flattenActions(group.actions)
|
||||
.map(action => ({
|
||||
.map((action) => ({
|
||||
...action,
|
||||
score: Math.max(
|
||||
fuzzySearch(action.name, term),
|
||||
@@ -72,7 +72,7 @@
|
||||
action.detail ? fuzzySearch(action.detail, term) : -1,
|
||||
),
|
||||
}))
|
||||
.filter(action => action.score > 0)
|
||||
.filter((action) => action.score > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
|
||||
return {
|
||||
@@ -80,11 +80,11 @@
|
||||
actions: scoredActions,
|
||||
score: Math.max(
|
||||
fuzzySearch(group.name, term),
|
||||
...scoredActions.map(a => a.score),
|
||||
...scoredActions.map((a) => a.score),
|
||||
),
|
||||
}
|
||||
})
|
||||
.filter(group => group.actions.length > 0)
|
||||
.filter((group) => group.actions.length > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@
|
||||
actions: Action[],
|
||||
subaction: boolean = true,
|
||||
): Action[] {
|
||||
return actions.flatMap(action => [
|
||||
return actions.flatMap((action) => [
|
||||
action,
|
||||
...(action.subActions && subaction
|
||||
? flattenActions(action.subActions)
|
||||
@@ -137,10 +137,10 @@
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.ctrlKey) {
|
||||
const actions = groups
|
||||
.flatMap(g => g.actions)
|
||||
.filter(a => a.shortcut != undefined)
|
||||
.flatMap((g) => g.actions)
|
||||
.filter((a) => a.shortcut != undefined)
|
||||
|
||||
actions.forEach(a => {
|
||||
actions.forEach((a) => {
|
||||
if (event.key === a.shortcut) {
|
||||
event.preventDefault()
|
||||
if (a.href) goto(a.href)
|
||||
@@ -220,7 +220,7 @@
|
||||
})
|
||||
|
||||
let flattenedActions = $derived(
|
||||
filteredGroups.flatMap(group => group.actions),
|
||||
filteredGroups.flatMap((group) => group.actions),
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -269,7 +269,7 @@
|
||||
>
|
||||
<CommandItem
|
||||
{action}
|
||||
onclick={e => {
|
||||
onclick={(e) => {
|
||||
if (action.href) {
|
||||
togglePalette()
|
||||
return
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { type ResumableItem } from '$lib/lemmy/item'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { theme, type ThemeData } from '$lib/ui/colors.svelte'
|
||||
import { theme, type ThemeData } from '$lib/ui/theme/theme.svelte'
|
||||
import { fullCommunityName } from '$lib/util.svelte'
|
||||
import {
|
||||
ArrowRightOnRectangle,
|
||||
@@ -73,7 +73,7 @@ export function getGroups(
|
||||
return [
|
||||
{
|
||||
name: t.get('nav.commands.recents'),
|
||||
actions: resumables.map(r => ({
|
||||
actions: resumables.map((r) => ({
|
||||
name: r.name,
|
||||
icon: r.avatar ?? PencilSquare,
|
||||
href: r.url,
|
||||
@@ -306,7 +306,7 @@ export function getGroups(
|
||||
},
|
||||
{
|
||||
name: t.get('account.accounts'),
|
||||
actions: profiles.map(p => ({
|
||||
actions: profiles.map((p) => ({
|
||||
name: p.username ?? t.get('account.guest'),
|
||||
icon: p.avatar ?? UserCircle,
|
||||
detail: p.instance,
|
||||
@@ -379,7 +379,7 @@ export function getGroups(
|
||||
{
|
||||
name: t.get('nav.commands.setTheme'),
|
||||
icon: Swatch,
|
||||
subActions: td.themes.map(th => ({
|
||||
subActions: td.themes.map((th) => ({
|
||||
name: t.get('nav.commands.setThemeTo', { default: th.name }),
|
||||
icon: Swatch,
|
||||
handle: () => (theme.data.currentTheme = th.id),
|
||||
@@ -400,7 +400,7 @@ export function getGroups(
|
||||
{
|
||||
name: t.get('profile.subscribed'),
|
||||
actions:
|
||||
profile.user?.follows.map(f => ({
|
||||
profile.user?.follows.map((f) => ({
|
||||
icon: f.community.icon,
|
||||
name: f.community.title,
|
||||
href: `/c/${fullCommunityName(
|
||||
|
||||
@@ -48,7 +48,10 @@
|
||||
<div class="font-medium">{profile.current.username}</div>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
<div class="text-xs text-slate-500 dark:text-zinc-500">
|
||||
<span class="capitalize">{profile.current.client?.name ?? DEFAULT_CLIENT_TYPE.name}</span> • {profile.current.instance}
|
||||
<span class="capitalize"
|
||||
>{profile.current.client?.name ?? DEFAULT_CLIENT_TYPE.name}</span
|
||||
>
|
||||
• {profile.current.instance}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -75,7 +78,10 @@
|
||||
<div class="font-medium text-sm">{p.username}</div>
|
||||
{#if !LINKED_INSTANCE_URL}
|
||||
<div class="text-xs text-slate-500 dark:text-zinc-500">
|
||||
<span class="capitalize">{p.client?.name ?? DEFAULT_CLIENT_TYPE.name}</span> • {p.instance}
|
||||
<span class="capitalize"
|
||||
>{p.client?.name ?? DEFAULT_CLIENT_TYPE.name}</span
|
||||
>
|
||||
• {p.instance}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -95,10 +101,7 @@
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
<MenuButton href="/accounts">
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserGroup} size="16" micro />
|
||||
{/snippet}
|
||||
<MenuButton href="/accounts" icon={UserGroup}>
|
||||
{$t('account.accounts')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -4,9 +4,9 @@
|
||||
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/colors.svelte'
|
||||
import { theme } from '$lib/ui/theme/theme.svelte'
|
||||
import { Badge, Option, Select } from 'mono-svelte'
|
||||
import {
|
||||
ArrowLeftOnRectangle,
|
||||
@@ -131,7 +131,7 @@
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={profile.current.user.moderates.map(i => ({
|
||||
items={profile.current.user.moderates.map((i) => ({
|
||||
id: i.community.id,
|
||||
name: i.community.title,
|
||||
url: communityLink(i.community),
|
||||
@@ -157,7 +157,7 @@
|
||||
{/snippet}
|
||||
|
||||
<ItemList
|
||||
items={profile.current.user.follows.map(i => ({
|
||||
items={profile.current.user.follows.map((i) => ({
|
||||
id: i.community.id,
|
||||
name: i.community.title,
|
||||
url: communityLink(i.community),
|
||||
|
||||
@@ -947,5 +947,9 @@
|
||||
"title": "Add a post title",
|
||||
"body": "What do you have to say?",
|
||||
"comments": "Join the conversation"
|
||||
},
|
||||
"class": {
|
||||
"moderator": "Moderator",
|
||||
"admin": "Administrator"
|
||||
}
|
||||
}
|
||||
@@ -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}`
|
||||
@@ -92,8 +92,8 @@ function resumableStore(limit: number = 10) {
|
||||
set,
|
||||
update,
|
||||
add: (item: ResumableItem) => {
|
||||
update(resumables => {
|
||||
if (resumables.find(i => JSON.stringify(i) == JSON.stringify(item)))
|
||||
update((resumables) => {
|
||||
if (resumables.find((i) => JSON.stringify(i) == JSON.stringify(item)))
|
||||
return resumables
|
||||
resumables.unshift(item)
|
||||
if (resumables.length > limit) resumables.pop()
|
||||
@@ -107,9 +107,9 @@ export const resumables = resumableStore()
|
||||
|
||||
export function addFavorite(item: Community, add: boolean = true) {
|
||||
const favs = profile.current.favorites ?? []
|
||||
if (favs.map(fav => fav.id).includes(item.id)) if (add) return
|
||||
if (favs.map((fav) => fav.id).includes(item.id)) if (add) return
|
||||
if (!add) {
|
||||
favs.splice(favs.map(c => c.id).indexOf(item.id), 1)
|
||||
favs.splice(favs.map((c) => c.id).indexOf(item.id), 1)
|
||||
} else {
|
||||
favs.unshift(item)
|
||||
}
|
||||
|
||||
+12
-26
@@ -1,30 +1,29 @@
|
||||
import { profile, type ProfileInfo } from '$lib/auth.svelte'
|
||||
import { getClient } from '$lib/client/lemmy.svelte'
|
||||
import { trycatch } from '$lib/util.svelte'
|
||||
import { client } from '$lib/client/lemmy.svelte'
|
||||
import type { Community, MyUserInfo } from '$lib/client/types'
|
||||
|
||||
// TODO obliterate this file
|
||||
|
||||
export const blockUser = async (block: boolean, id: number) => {
|
||||
export async function blockUser(block: boolean, id: number) {
|
||||
const auth = profile.current?.jwt
|
||||
|
||||
if (!auth) throw new Error('Unauthorized')
|
||||
|
||||
await getClient().blockPerson({
|
||||
await client().blockPerson({
|
||||
block: block,
|
||||
person_id: id,
|
||||
})
|
||||
}
|
||||
|
||||
export const isBlocked = (me: MyUserInfo, user: number) =>
|
||||
me.person_blocks.map(b => b.target.id).includes(user)
|
||||
export function isBlocked(me: MyUserInfo, user: number) {
|
||||
return me.person_blocks.map((b) => b.target.id).includes(user)
|
||||
}
|
||||
|
||||
export const addSubscription = (
|
||||
export function addSubscription(
|
||||
community: Community,
|
||||
subscribe: boolean = true,
|
||||
) => {
|
||||
) {
|
||||
const index = profile.current.user?.follows
|
||||
.map(f => f.community.id)
|
||||
.map((f) => f.community.id)
|
||||
.indexOf(community.id)
|
||||
|
||||
if (subscribe && index == -1) {
|
||||
@@ -37,19 +36,6 @@ export const addSubscription = (
|
||||
}
|
||||
}
|
||||
|
||||
export const addAdmin = async (handle: string, added: boolean) =>
|
||||
trycatch(async () => {
|
||||
const user = await getClient().resolveObject({
|
||||
q: handle,
|
||||
})
|
||||
|
||||
if (!user.person) throw new Error('No user found')
|
||||
|
||||
return await getClient().addAdmin({
|
||||
added: added,
|
||||
person_id: user.person.person.id,
|
||||
})
|
||||
})
|
||||
|
||||
export const hasFavorite = (profile: ProfileInfo, id: number): boolean =>
|
||||
profile.favorites?.map(i => i.id).includes(id) ?? false
|
||||
export function hasFavorite(profile: ProfileInfo, id: number): boolean {
|
||||
return profile.favorites?.map((i) => i.id).includes(id) ?? false
|
||||
}
|
||||
@@ -73,6 +73,7 @@
|
||||
children?: Snippet
|
||||
suffix?: Snippet
|
||||
onclick?: HTMLButtonAttributes['onclick']
|
||||
icon?: IconSource
|
||||
}
|
||||
|
||||
export type { Props as ButtonProps }
|
||||
@@ -87,6 +88,7 @@
|
||||
|
||||
import Spinner from '../loader/Spinner.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
let {
|
||||
loading = false,
|
||||
@@ -103,6 +105,7 @@
|
||||
prefix,
|
||||
children,
|
||||
suffix,
|
||||
icon,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
@@ -136,6 +139,8 @@
|
||||
<Spinner width={loaderWidth ?? 16} />
|
||||
{:else if prefix}
|
||||
{@render prefix?.()}
|
||||
{:else if icon}
|
||||
<Icon src={icon} size="16" mini />
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
{@render suffix?.()}
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -22,7 +22,8 @@
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<label
|
||||
<svelte:element
|
||||
this={text || customText ? 'label' : 'h3'}
|
||||
{...rest}
|
||||
for={forID}
|
||||
class={['text-sm text-slate-800 dark:text-zinc-200 font-medium', clazz]}
|
||||
@@ -33,4 +34,4 @@
|
||||
{@render customText?.()}
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
</label>
|
||||
</svelte:element>
|
||||
@@ -32,8 +32,8 @@
|
||||
const context = getContext<SelectContext>('select')
|
||||
|
||||
$effect(() => {
|
||||
if ($locale || !context.options.find(v => v == option)) {
|
||||
const index = context.options.findIndex(i => i.value == option.value)
|
||||
if ($locale || !context.options.find((v) => v == option)) {
|
||||
const index = context.options.findIndex((i) => i.value == option.value)
|
||||
|
||||
if (index != -1) {
|
||||
context.options.splice(index, 1, option)
|
||||
@@ -44,7 +44,7 @@
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
const index = context.options.findIndex(i => i.value == option.value)
|
||||
const index = context.options.findIndex((i) => i.value == option.value)
|
||||
if (index != -1) {
|
||||
context.options.splice(index, 1)
|
||||
}
|
||||
|
||||
@@ -93,8 +93,12 @@
|
||||
</script>
|
||||
|
||||
{#snippet selectTarget(attachment: Attachment)}
|
||||
<Label text={label} customText={customLabel} class={['space-y-1 relative', baseClass]}>
|
||||
<div class="relative" role="presentation">
|
||||
<Label
|
||||
text={label}
|
||||
customText={customLabel}
|
||||
class={['space-y-1 relative', baseClass]}
|
||||
>
|
||||
<div class="relative w-max max-w-full" role="presentation">
|
||||
<select
|
||||
{@attach attachment}
|
||||
{...rest}
|
||||
@@ -109,10 +113,10 @@
|
||||
clazz,
|
||||
]}
|
||||
bind:value
|
||||
onmousedown={e => {
|
||||
onmousedown={(e) => {
|
||||
e.preventDefault()
|
||||
}}
|
||||
onkeypress={e => {
|
||||
onkeypress={(e) => {
|
||||
e.preventDefault()
|
||||
open = !open
|
||||
}}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { pushState, replaceState } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
import { XMark } from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
import { Button } from '../index.js'
|
||||
import Portal from '../popover/Portal.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { page } from '$app/state'
|
||||
import { pushState, replaceState } from '$app/navigation'
|
||||
|
||||
interface Props {
|
||||
action?: string | undefined
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
if (!isInHistory && open) {
|
||||
replaceState('', {
|
||||
openModals: currentModals.filter(id => id !== modalId),
|
||||
openModals: currentModals.filter((id) => id !== modalId),
|
||||
})
|
||||
hasHistoryEntry = false
|
||||
open = false
|
||||
@@ -85,7 +85,7 @@
|
||||
flex flex-col items-center justify-center backdrop-blur-xs
|
||||
bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
transition:fade|global={{ duration: 100 }}
|
||||
onclick={e => {
|
||||
onclick={(e) => {
|
||||
// @ts-expect-error html node hell
|
||||
if (!el.contains(e.target)) onclose()
|
||||
}}
|
||||
@@ -110,11 +110,8 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
color="tertiary"
|
||||
size="square-sm"
|
||||
onclick={() => onclose()}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="20" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
icon={XMark}
|
||||
></Button>
|
||||
{/if}
|
||||
{#if title !== null}
|
||||
<h1 class="font-semibold text-xl max-w-full">
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
},
|
||||
})
|
||||
|
||||
const menuAttach: Attachment = element => {
|
||||
const menuAttach: Attachment = (element) => {
|
||||
const e = element as HTMLButtonElement
|
||||
|
||||
const mouseLeave = () => (openOnHover ? (open = false) : false)
|
||||
|
||||
@@ -70,13 +70,13 @@
|
||||
<TextInput
|
||||
{@attach attachment}
|
||||
bind:value={query}
|
||||
oninput={e => {
|
||||
oninput={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
oninput?.(e)
|
||||
debounceFunc()
|
||||
}}
|
||||
onfocus={e => {
|
||||
onfocus={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
oninput?.(e)
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<button
|
||||
onclick={() => {
|
||||
toast.action?.()
|
||||
toasts.update(toasts => toasts.filter(t => t.id != toast.id))
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer"
|
||||
>
|
||||
@@ -78,7 +78,7 @@
|
||||
{/if}
|
||||
<button
|
||||
onclick={() => {
|
||||
toasts.update(toasts => toasts.filter(t => t.id != toast.id))
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer text-slate-600 dark:text-zinc-400"
|
||||
>
|
||||
|
||||
@@ -40,8 +40,8 @@ export function toast({
|
||||
}) {
|
||||
let id = 0
|
||||
|
||||
toasts.update(toasts => {
|
||||
id = Math.max(0, ...toasts.map(t => t.id)) + 1
|
||||
toasts.update((toasts) => {
|
||||
id = Math.max(0, ...toasts.map((t) => t.id)) + 1
|
||||
|
||||
return [
|
||||
...toasts,
|
||||
@@ -58,11 +58,11 @@ export function toast({
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
toasts.update(toasts => toasts.filter(toast => toast.id != id))
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
}, duration)
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
export const removeToast = (id: number) =>
|
||||
toasts.update(toasts => toasts.filter(toast => toast.id != id))
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
Loaded 100 of 193 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user