mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 11:39:16 +01:00
refactor: ♻️ Make auth store require less null checks
This commit is contained in:
parent
68e23a818a
commit
b23ed66401
32 changed files with 111 additions and 124 deletions
|
|
@ -32,9 +32,9 @@ const copy = (data: string) => {
|
|||
const authStore = useAuthStore();
|
||||
|
||||
const data: [string, string | VNode][] = [
|
||||
["User ID", authStore.account?.id ?? ""],
|
||||
["Instance domain", authStore.instance?.domain ?? ""],
|
||||
["Instance version", authStore.instance?.versia_version ?? ""],
|
||||
["User ID", authStore.account.id],
|
||||
["Instance domain", authStore.instance.domain],
|
||||
["Instance version", authStore.instance.versia_version ?? ""],
|
||||
["Client ID", authStore.application?.client_id ?? ""],
|
||||
[
|
||||
"Client secret",
|
||||
|
|
@ -55,7 +55,7 @@ const data: [string, string | VNode][] = [
|
|||
class="font-sans"
|
||||
size="sm"
|
||||
// @ts-expect-error missing onClick types
|
||||
onClick={() => copy(authStore.token?.access_token ?? "")}
|
||||
onClick={() => copy(authStore.token.access_token)}
|
||||
>
|
||||
Click to copy
|
||||
</Button>,
|
||||
|
|
|
|||
|
|
@ -76,12 +76,12 @@ useListen("preferences:open", () => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open" v-if="authStore.isSignedIn">
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent
|
||||
class="md:max-w-5xl w-full h-full p-0 md:max-h-[70dvh] overflow-hidden"
|
||||
>
|
||||
<Tabs
|
||||
class="md:grid-cols-[auto_minmax(0,1fr)] !grid gap-2 *:p-4 overflow-hidden *:overflow-y-auto *:h-full"
|
||||
class="md:grid-cols-[auto_minmax(0,1fr)] grid! gap-2 *:p-4 overflow-hidden *:overflow-y-auto *:h-full"
|
||||
orientation="vertical"
|
||||
:default-value="pages[0]"
|
||||
>
|
||||
|
|
@ -92,8 +92,8 @@ useListen("preferences:open", () => {
|
|||
class="grid gap-3 items-center grid-cols-[auto_minmax(0,1fr)]"
|
||||
>
|
||||
<Avatar
|
||||
:name="authStore.account!.display_name || authStore.account!.username"
|
||||
:src="authStore.account!.avatar"
|
||||
:name="authStore.account.display_name || authStore.account.username"
|
||||
:src="authStore.account.avatar"
|
||||
/>
|
||||
<DialogTitle>Preferences</DialogTitle>
|
||||
</div>
|
||||
|
|
@ -101,7 +101,7 @@ useListen("preferences:open", () => {
|
|||
Make changes to your preferences here.
|
||||
</DialogDescription>
|
||||
<TabsList
|
||||
class="md:grid md:grid-cols-1 w-full h-fit *:justify-start !justify-start"
|
||||
class="md:grid md:grid-cols-1 w-full h-fit *:justify-start justify-start!"
|
||||
>
|
||||
<TabsTrigger
|
||||
v-for="page in pages"
|
||||
|
|
|
|||
|
|
@ -37,10 +37,6 @@ const canEdit =
|
|||
authStore.permissions.includes(RolePermission.ManageEmojis);
|
||||
|
||||
const deleteAll = async () => {
|
||||
if (!authStore.isSignedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { confirmed } = await confirmModalService.confirm({
|
||||
title: m.tense_quick_cod_favor(),
|
||||
message: m.next_hour_jurgen_sprout({
|
||||
|
|
|
|||
|
|
@ -50,10 +50,6 @@ const { emoji } = defineProps<{
|
|||
const authStore = useAuthStore();
|
||||
|
||||
const editName = async () => {
|
||||
if (!authStore.isSignedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await confirmModalService.confirm({
|
||||
title: m.slimy_awful_florian_sail(),
|
||||
defaultValue: emoji.shortcode,
|
||||
|
|
@ -83,10 +79,6 @@ const editName = async () => {
|
|||
};
|
||||
|
||||
const _delete = async () => {
|
||||
if (!authStore.isSignedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { confirmed } = await confirmModalService.confirm({
|
||||
title: m.tense_quick_cod_favor(),
|
||||
message: m.honest_factual_carp_aspire(),
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ const columns: ColumnDef<z.infer<typeof CustomEmoji>>[] = [
|
|||
src={row.getValue("url")}
|
||||
alt={`:${row.getValue("shortcode")}:`}
|
||||
title={row.getValue("shortcode")}
|
||||
class="h-[1lh] align-middle inline not-prose hover:scale-110 transition-transform duration-75 ease-in-out"
|
||||
class="h-lh align-middle inline not-prose hover:scale-110 transition-transform duration-75 ease-in-out"
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
|
@ -108,7 +108,7 @@ const columns: ColumnDef<z.infer<typeof CustomEmoji>>[] = [
|
|||
return (
|
||||
<Button
|
||||
variant="link"
|
||||
class="!p-0 !h-auto"
|
||||
class="p-0! h-auto!"
|
||||
// @ts-expect-error types don't include onClick
|
||||
onClick={() =>
|
||||
column.toggleSorting(column.getIsSorted() === "asc")
|
||||
|
|
@ -135,7 +135,7 @@ const columns: ColumnDef<z.infer<typeof CustomEmoji>>[] = [
|
|||
return (
|
||||
<Button
|
||||
variant="link"
|
||||
class="!p-0 !h-auto"
|
||||
class="p-0! h-auto!"
|
||||
// @ts-expect-error types don't include onClick
|
||||
onClick={() =>
|
||||
column.toggleSorting(column.getIsSorted() === "asc")
|
||||
|
|
@ -164,7 +164,7 @@ const columns: ColumnDef<z.infer<typeof CustomEmoji>>[] = [
|
|||
return (
|
||||
<Button
|
||||
variant="link"
|
||||
class="!p-0 !h-auto"
|
||||
class="p-0! h-auto!"
|
||||
// @ts-expect-error types don't include onClick
|
||||
onClick={() => {
|
||||
const filter = column.getFilterValue();
|
||||
|
|
|
|||
|
|
@ -203,25 +203,21 @@ const formSchema = toTypedSchema(
|
|||
.refine(
|
||||
(v) =>
|
||||
v.size <=
|
||||
(authStore.instance?.configuration.emojis
|
||||
.emoji_size_limit ?? Number.POSITIVE_INFINITY),
|
||||
authStore.instance.configuration.emojis.emoji_size_limit,
|
||||
m.orange_weird_parakeet_hug({
|
||||
count:
|
||||
authStore.instance?.configuration.emojis
|
||||
.emoji_size_limit ?? Number.POSITIVE_INFINITY,
|
||||
count: authStore.instance.configuration.emojis
|
||||
.emoji_size_limit,
|
||||
}),
|
||||
),
|
||||
shortcode: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(
|
||||
authStore.instance?.configuration.emojis
|
||||
.max_shortcode_characters ?? Number.POSITIVE_INFINITY,
|
||||
authStore.instance.configuration.emojis
|
||||
.max_shortcode_characters,
|
||||
m.solid_inclusive_owl_hug({
|
||||
count:
|
||||
authStore.instance?.configuration.emojis
|
||||
.max_shortcode_characters ??
|
||||
Number.POSITIVE_INFINITY,
|
||||
count: authStore.instance.configuration.emojis
|
||||
.max_shortcode_characters,
|
||||
}),
|
||||
)
|
||||
.regex(emojiValidator),
|
||||
|
|
@ -238,13 +234,11 @@ const formSchema = toTypedSchema(
|
|||
alt: z
|
||||
.string()
|
||||
.max(
|
||||
authStore.instance?.configuration.emojis
|
||||
.max_description_characters ?? Number.POSITIVE_INFINITY,
|
||||
authStore.instance.configuration.emojis
|
||||
.max_description_characters,
|
||||
m.key_ago_hound_emerge({
|
||||
count:
|
||||
authStore.instance?.configuration.emojis
|
||||
.max_description_characters ??
|
||||
Number.POSITIVE_INFINITY,
|
||||
count: authStore.instance.configuration.emojis
|
||||
.max_description_characters,
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
|
|
@ -255,10 +249,6 @@ const { isSubmitting, handleSubmit, values, setFieldValue } = useForm({
|
|||
});
|
||||
|
||||
const submit = handleSubmit(async (values) => {
|
||||
if (!authStore.isSignedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
const id = toast.loading(m.factual_gray_mouse_believe());
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
<FormField v-slot="{ setValue }" name="avatar">
|
||||
<TextInput :title="m.safe_icy_bulldog_quell()">
|
||||
<ImageUploader
|
||||
v-model:image="authStore.account!.avatar"
|
||||
v-model:image="authStore.account.avatar"
|
||||
@submit-file="(file) => setValue(file)"
|
||||
@submit-url="(url) => setValue(url)"
|
||||
/>
|
||||
|
|
@ -143,10 +143,6 @@ const dirty = computed(() => form.meta.value.dirty);
|
|||
const submitting = ref(false);
|
||||
const authStore = useAuthStore();
|
||||
|
||||
if (!(authStore.instance && authStore.account)) {
|
||||
throw new Error("Not signed in.");
|
||||
}
|
||||
|
||||
const schema = formSchema(authStore.instance);
|
||||
|
||||
const form = useForm({
|
||||
|
|
@ -167,7 +163,7 @@ const form = useForm({
|
|||
});
|
||||
|
||||
const save = form.handleSubmit(async (values) => {
|
||||
if (submitting.value || !authStore.account) {
|
||||
if (submitting.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +194,7 @@ const save = form.handleSubmit(async (values) => {
|
|||
: values.discoverable,
|
||||
// Can't compare two arrays directly in JS, so we need to check if all fields are the same
|
||||
fields_attributes: values.fields.every((field) =>
|
||||
authStore.account?.source?.fields?.some(
|
||||
authStore.account.source?.fields?.some(
|
||||
(f) => f.name === field.name && f.value === field.value,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue