feat: add language options to everywhere that support sit
This commit is contained in:
1 parent
c65801e574
commit
14ba363c85
8 files changed
+232
-20
No files matched your search
@@ -1,16 +1,16 @@
|
||||
<script lang="ts">
|
||||
import type { CommentResponse } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { Menu, Select, Spinner, toast, Option, MenuButton } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { placeholders } from '$lib/util.svelte.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
import { Icon, Language, XMark } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
postId: number
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
let loading = $state(false)
|
||||
let preview = false
|
||||
let language: number | undefined = $state()
|
||||
|
||||
async function submit() {
|
||||
if (!$profile?.user || !$profile?.jwt || value == '') return
|
||||
@@ -100,6 +101,38 @@
|
||||
}}
|
||||
previewButton={previewAction}
|
||||
>
|
||||
<Menu>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
size="square-md"
|
||||
rounding="pill"
|
||||
color={language != undefined ? 'primary' : 'ghost'}
|
||||
title={$t('form.profile.languages.title')}
|
||||
>
|
||||
<Icon src={Language} size="16" micro />
|
||||
</Button>
|
||||
{/snippet}
|
||||
|
||||
{#if $site}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => (language = undefined)}
|
||||
>
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{$t('form.post.unset')}
|
||||
</MenuButton>
|
||||
{#each $site?.all_languages as languageOption}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
language = languageOption.id
|
||||
}}
|
||||
>
|
||||
{languageOption.name}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
{/if}
|
||||
</Menu>
|
||||
<div class="flex-1"></div>
|
||||
{#if actions}
|
||||
<Button
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, Switch, toast } from 'mono-svelte'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { Badge, ImageInput, MenuButton, Switch, toast } from 'mono-svelte'
|
||||
import { client, getClient, site } from '$lib/lemmy.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
@@ -13,16 +13,19 @@
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
|
||||
import Label from 'mono-svelte/forms/Label.svelte'
|
||||
import { DocumentPlus, GlobeAlt, Icon, MapPin } from 'svelte-hero-icons'
|
||||
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
|
||||
import Select from 'mono-svelte/forms/select/Select.svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import Material from 'mono-svelte/materials/Material.svelte'
|
||||
import Menu from 'mono-svelte/popover/Menu.svelte'
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* The community ID to edit.
|
||||
*/
|
||||
edit?: number | undefined
|
||||
edit?: number
|
||||
formData?: {
|
||||
name: string
|
||||
displayName: string
|
||||
@@ -33,13 +36,14 @@
|
||||
postsLockedToModerators: boolean
|
||||
submitting: boolean
|
||||
visibility: 'Public' | 'LocalOnly'
|
||||
languages?: number[]
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
edit = undefined,
|
||||
formData = $bindable({
|
||||
formData: passedFormData = $bindable({
|
||||
name: '',
|
||||
displayName: '',
|
||||
sidebar: '',
|
||||
@@ -47,10 +51,13 @@
|
||||
postsLockedToModerators: false,
|
||||
submitting: false,
|
||||
visibility: 'Public',
|
||||
languages: undefined,
|
||||
}),
|
||||
formtitle,
|
||||
}: Props = $props()
|
||||
|
||||
let formData = $state(passedFormData)
|
||||
|
||||
async function submit() {
|
||||
if (!$profile?.jwt) return
|
||||
if ((!edit && formData.name == '') || formData.displayName == '') return
|
||||
@@ -68,6 +75,7 @@
|
||||
banner: formData.banner,
|
||||
community_id: edit,
|
||||
visibility: formData.visibility,
|
||||
discussion_languages: formData.languages,
|
||||
})
|
||||
: await getClient().createCommunity({
|
||||
name: formData.name,
|
||||
@@ -78,6 +86,7 @@
|
||||
icon: formData.icon,
|
||||
banner: formData.banner,
|
||||
visibility: formData.visibility,
|
||||
discussion_languages: formData.languages,
|
||||
})
|
||||
|
||||
toast({
|
||||
@@ -225,6 +234,54 @@
|
||||
<Option icon={GlobeAlt} value="Public">Public</Option>
|
||||
<Option icon={MapPin} value="LocalOnly">Local Only</Option>
|
||||
</Select>
|
||||
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if $site}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
</Badge>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#each $site.all_languages as language, index}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
formData.languages = [
|
||||
...(formData.languages ?? []),
|
||||
language.id,
|
||||
]
|
||||
}}
|
||||
>
|
||||
{language.name}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
</Menu>
|
||||
{#each formData.languages ?? [] as languageId, index}
|
||||
{@const language = $site.all_languages.find(
|
||||
(l) => l.id == languageId,
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
class="hover:brightness-150 transition-all"
|
||||
onclick={() => {
|
||||
formData.languages?.splice(index, 1)
|
||||
}}
|
||||
>
|
||||
<Badge class="cursor-pointer">{language?.name}</Badge>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Material>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
submit
|
||||
color="primary"
|
||||
|
||||
@@ -167,6 +167,10 @@
|
||||
"label": "Delete account",
|
||||
"deleteContent": "Delete content",
|
||||
"warning": "This will delete ALL of your submissions."
|
||||
},
|
||||
"languages": {
|
||||
"title": "Languages",
|
||||
"description": "If any are set, you will only see content explicitly tagged as that language. Most content, untagged, falls under 'Undetermined'."
|
||||
}
|
||||
},
|
||||
"email": "Email",
|
||||
@@ -587,7 +591,8 @@
|
||||
"add": "Add",
|
||||
"cancel": "Cancel",
|
||||
"send": "Send",
|
||||
"general": "General"
|
||||
"general": "General",
|
||||
"remove": "Remove"
|
||||
},
|
||||
"message": {
|
||||
"success": "Success",
|
||||
|
||||
@@ -13,6 +13,7 @@ export { default as FileInput } from './forms/FileInput.svelte'
|
||||
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'
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { Label, Switch, toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import {
|
||||
Badge,
|
||||
Label,
|
||||
Material,
|
||||
Menu,
|
||||
MenuButton,
|
||||
Switch,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import type { EditSite } from 'lemmy-js-client'
|
||||
import type { PageData } from './$types.js'
|
||||
import { Button, Checkbox, Select, TextInput } from 'mono-svelte'
|
||||
import ImageUploadModal from '$lib/components/lemmy/modal/ImageUploadModal.svelte'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { DocumentPlus, Icon, Plus } from 'svelte-hero-icons'
|
||||
import { t } from '$lib/translations.js'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
|
||||
interface Props {
|
||||
data: PageData
|
||||
}
|
||||
|
||||
let { data }: Props = $props()
|
||||
let { data: pageData }: Props = $props()
|
||||
let data = $state(pageData)
|
||||
|
||||
const formData: Omit<EditSite, 'auth'> | undefined = $state(
|
||||
data.site
|
||||
@@ -65,7 +73,13 @@
|
||||
<title>{$t('routes.admin.title')}</title>
|
||||
</svelte:head>
|
||||
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(save)}>
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save()
|
||||
}}
|
||||
>
|
||||
<Header pageHeader>{$t('routes.admin.config.title')}</Header>
|
||||
{#if formData}
|
||||
<TextInput bind:value={formData.name} label={$t('form.name')} />
|
||||
@@ -218,6 +232,51 @@
|
||||
<Switch bind:checked={formData.captcha_enabled} defaultValue={false}>
|
||||
{$t('routes.admin.config.captcha.enabled')}
|
||||
</Switch>
|
||||
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<p>{$t('form.profile.languages.description')}</p>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if $site && formData.discussion_languages}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
</Badge>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#each $site.all_languages as language, index}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
formData.discussion_languages?.push(language.id)
|
||||
}}
|
||||
>
|
||||
{language.name}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
</Menu>
|
||||
{#each formData.discussion_languages as languageId, index}
|
||||
{@const language = $site.all_languages.find(
|
||||
(l) => l.id == languageId,
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
class="hover:brightness-150 transition-all"
|
||||
onclick={() => {
|
||||
formData.discussion_languages?.splice(index, 1)
|
||||
}}
|
||||
>
|
||||
<Badge class="cursor-pointer">{language?.name}</Badge>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Material>
|
||||
</div>
|
||||
{/if}
|
||||
<Button color="primary" size="lg" loading={saving} disabled={saving} submit>
|
||||
{$t('common.save')}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
banner: data.community.community_view.community.banner,
|
||||
visibility: data.community.community_view.community.visibility,
|
||||
submitting: false,
|
||||
languages: data.community.discussion_languages,
|
||||
}}
|
||||
>
|
||||
{#snippet formtitle()}
|
||||
|
||||
@@ -3,17 +3,28 @@
|
||||
|
||||
import { profile, profileData, setUserID } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, Material, removeToast, toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import {
|
||||
Badge,
|
||||
ImageInput,
|
||||
Material,
|
||||
Menu,
|
||||
MenuButton,
|
||||
removeToast,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import type { SaveUserSettings } from 'lemmy-js-client'
|
||||
import { Button, Switch, TextInput } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { t } from '$lib/translations.js'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import type { PageData } from './$types'
|
||||
import { Icon, Plus } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
inline?: boolean
|
||||
data: any
|
||||
data: PageData
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
@@ -22,6 +33,7 @@
|
||||
let formData: Omit<SaveUserSettings, 'auth'> | undefined = $state({
|
||||
...data.my_user?.local_user_view?.local_user,
|
||||
...data.my_user?.local_user_view?.person,
|
||||
discussion_languages: data.my_user?.discussion_languages,
|
||||
})
|
||||
|
||||
let profileImage: FileList | undefined = $state()
|
||||
@@ -105,6 +117,50 @@
|
||||
<Switch bind:checked={formData.show_read_posts}>
|
||||
{$t('form.profile.showRead')}
|
||||
</Switch>
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<p>{$t('form.profile.languages.description')}</p>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if $site && formData.discussion_languages}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
</Badge>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#each $site.all_languages as language, index}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
formData.discussion_languages?.push(language.id)
|
||||
}}
|
||||
>
|
||||
{language.name}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
</Menu>
|
||||
{#each formData.discussion_languages as languageId, index}
|
||||
{@const language = $site.all_languages.find(
|
||||
(l) => l.id == languageId,
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
class="hover:brightness-150 transition-all"
|
||||
onclick={() => {
|
||||
formData.discussion_languages?.splice(index, 1)
|
||||
}}
|
||||
>
|
||||
<Badge class="cursor-pointer">{language?.name}</Badge>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Material>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
submit
|
||||
|
||||
@@ -9,7 +9,7 @@ export let ssr = false
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const my_user =
|
||||
get(profile)?.user ??
|
||||
// get(profile)?.user ??
|
||||
(await client({ auth: get(profile)?.jwt, func: fetch }).getSite()).my_user
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user