mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 03:29:16 +01:00
refactor: ♻️ Rewrite state system to use Pinia for composer and auth
This commit is contained in:
parent
a6db9e059d
commit
b510782a30
80 changed files with 999 additions and 1011 deletions
|
|
@ -1,17 +1,17 @@
|
|||
<template>
|
||||
<div class="flex flex-row w-full max-w-sm items-stretch justify-between">
|
||||
<ActionButton :icon="Reply" @click="emit('reply')" :title="m.drab_tense_turtle_comfort()" :disabled="!identity">
|
||||
<ActionButton :icon="Reply" @click="emit('reply')" :title="m.drab_tense_turtle_comfort()" :disabled="!authStore.isSignedIn">
|
||||
{{ numberFormat(replyCount) }}
|
||||
</ActionButton>
|
||||
<ActionButton :icon="Heart" @click="liked ? unlike() : like()" :title="liked ? m.vexed_fluffy_clownfish_dance() : m.royal_close_samuel_scold()" :disabled="!identity" :class="liked && '*:fill-red-600 *:text-red-600'">
|
||||
<ActionButton :icon="Heart" @click="liked ? unlike() : like()" :title="liked ? m.vexed_fluffy_clownfish_dance() : m.royal_close_samuel_scold()" :disabled="!authStore.isSignedIn" :class="liked && '*:fill-red-600 *:text-red-600'">
|
||||
{{ numberFormat(likeCount) }}
|
||||
</ActionButton>
|
||||
<ActionButton :icon="Repeat" @click="reblogged ? unreblog() : reblog()" :title="reblogged ? m.lime_neat_ox_stab() : m.aware_helpful_marlin_drop()" :disabled="!identity" :class="reblogged && '*:text-green-600'">
|
||||
<ActionButton :icon="Repeat" @click="reblogged ? unreblog() : reblog()" :title="reblogged ? m.lime_neat_ox_stab() : m.aware_helpful_marlin_drop()" :disabled="!authStore.isSignedIn" :class="reblogged && '*:text-green-600'">
|
||||
{{ numberFormat(reblogCount) }}
|
||||
</ActionButton>
|
||||
<ActionButton :icon="Quote" @click="emit('quote')" :title="m.true_shy_jackal_drip()" :disabled="!identity" />
|
||||
<ActionButton :icon="Quote" @click="emit('quote')" :title="m.true_shy_jackal_drip()" :disabled="!authStore.isSignedIn" />
|
||||
<Picker @pick="react">
|
||||
<ActionButton :icon="Smile" :title="m.bald_cool_kangaroo_jump()" :disabled="!identity" />
|
||||
<ActionButton :icon="Smile" :title="m.bald_cool_kangaroo_jump()" :disabled="!authStore.isSignedIn" />
|
||||
</Picker>
|
||||
<Menu :api-note-string="apiNoteString" :url="url" :remote-url="remoteUrl" :is-remote="isRemote" :author-id="authorId" @edit="emit('edit')" :note-id="noteId" @delete="emit('delete')">
|
||||
<ActionButton :icon="Ellipsis" :title="m.busy_merry_cowfish_absorb()" />
|
||||
|
|
@ -54,6 +54,7 @@ const emit = defineEmits<{
|
|||
react: [];
|
||||
}>();
|
||||
const { play } = useAudio();
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const like = async () => {
|
||||
if (preferences.confirm_actions.value.includes("like")) {
|
||||
|
|
@ -71,7 +72,7 @@ const like = async () => {
|
|||
|
||||
play("like");
|
||||
const id = toast.loading(m.slimy_candid_tiger_read());
|
||||
const { data } = await client.value.favouriteStatus(noteId);
|
||||
const { data } = await authStore.client.favouriteStatus(noteId);
|
||||
toast.dismiss(id);
|
||||
toast.success(m.mealy_slow_buzzard_commend());
|
||||
useEvent("note:edit", data);
|
||||
|
|
@ -92,7 +93,7 @@ const unlike = async () => {
|
|||
}
|
||||
|
||||
const id = toast.loading(m.busy_active_leopard_strive());
|
||||
const { data } = await client.value.unfavouriteStatus(noteId);
|
||||
const { data } = await authStore.client.unfavouriteStatus(noteId);
|
||||
toast.dismiss(id);
|
||||
toast.success(m.fresh_direct_bear_affirm());
|
||||
useEvent("note:edit", data);
|
||||
|
|
@ -113,7 +114,7 @@ const reblog = async () => {
|
|||
}
|
||||
|
||||
const id = toast.loading(m.late_sunny_cobra_scold());
|
||||
const { data } = await client.value.reblogStatus(noteId);
|
||||
const { data } = await authStore.client.reblogStatus(noteId);
|
||||
toast.dismiss(id);
|
||||
toast.success(m.weird_moving_hawk_lift());
|
||||
useEvent(
|
||||
|
|
@ -137,7 +138,7 @@ const unreblog = async () => {
|
|||
}
|
||||
|
||||
const id = toast.loading(m.white_sharp_gorilla_embrace());
|
||||
const { data } = await client.value.unreblogStatus(noteId);
|
||||
const { data } = await authStore.client.unreblogStatus(noteId);
|
||||
toast.dismiss(id);
|
||||
toast.success(m.royal_polite_moose_catch());
|
||||
useEvent("note:edit", data);
|
||||
|
|
@ -149,7 +150,7 @@ const react = async (emoji: z.infer<typeof CustomEmoji> | UnicodeEmoji) => {
|
|||
? (emoji as UnicodeEmoji).unicode
|
||||
: `:${(emoji as z.infer<typeof CustomEmoji>).shortcode}:`;
|
||||
|
||||
const { data } = await client.value.createEmojiReaction(noteId, text);
|
||||
const { data } = await authStore.client.createEmojiReaction(noteId, text);
|
||||
|
||||
toast.dismiss(id);
|
||||
toast.success(m.main_least_turtle_fall());
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ const emit = defineEmits<{
|
|||
}>();
|
||||
|
||||
const { copy } = useClipboard();
|
||||
const loggedIn = !!identity.value;
|
||||
const authorIsMe = loggedIn && authorId === identity.value?.account.id;
|
||||
const authStore = useAuthStore();
|
||||
const authorIsMe = authStore.isSignedIn && authorId === authStore.account?.id;
|
||||
|
||||
const copyText = (text: string) => {
|
||||
copy(text);
|
||||
|
|
@ -47,7 +47,7 @@ const copyText = (text: string) => {
|
|||
|
||||
const blockUser = async (userId: string) => {
|
||||
const id = toast.loading(m.top_cute_bison_nudge());
|
||||
await client.value.blockAccount(userId);
|
||||
await authStore.client.blockAccount(userId);
|
||||
toast.dismiss(id);
|
||||
|
||||
toast.success(m.main_weary_racoon_peek());
|
||||
|
|
@ -68,7 +68,7 @@ const _delete = async () => {
|
|||
}
|
||||
|
||||
const id = toast.loading(m.new_funny_fox_boil());
|
||||
await client.value.deleteStatus(noteId);
|
||||
await authStore.client.deleteStatus(noteId);
|
||||
toast.dismiss(id);
|
||||
|
||||
toast.success(m.green_tasty_bumblebee_beam());
|
||||
|
|
@ -122,8 +122,8 @@ const _delete = async () => {
|
|||
{{ m.tense_quick_cod_favor() }}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator v-if="loggedIn && !authorIsMe" />
|
||||
<DropdownMenuGroup v-if="loggedIn && !authorIsMe">
|
||||
<DropdownMenuSeparator v-if="authStore.isSignedIn && !authorIsMe" />
|
||||
<DropdownMenuGroup v-if="authStore.isSignedIn && !authorIsMe">
|
||||
<DropdownMenuItem as="button" :disabled="true">
|
||||
<Flag />
|
||||
{{ m.great_few_jaguar_rise() }}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ const emit = defineEmits<{
|
|||
pick: [emoji: z.infer<typeof CustomEmoji> | UnicodeEmoji];
|
||||
}>();
|
||||
|
||||
const authStore = useAuthStore();
|
||||
const open = ref(false);
|
||||
const selectedEmoji = ref<z.infer<typeof CustomEmoji> | UnicodeEmoji | null>(
|
||||
null,
|
||||
|
|
@ -59,12 +60,10 @@ const selectedEmoji = ref<z.infer<typeof CustomEmoji> | UnicodeEmoji | null>(
|
|||
const emojiContainer = useTemplateRef<HTMLDivElement>("emojiContainer");
|
||||
const filter = ref("");
|
||||
|
||||
const customEmojis = computed(() => identity.value?.emojis ?? []);
|
||||
|
||||
const customEmojiCategories = computed(() => {
|
||||
const categories: Record<string, z.infer<typeof CustomEmoji>[]> = {};
|
||||
|
||||
for (const emoji of customEmojis.value) {
|
||||
for (const emoji of authStore.emojis) {
|
||||
const categoryName = emoji.category || "Uncategorized";
|
||||
|
||||
if (!categories[categoryName]) {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ const { reaction, emoji, statusId } = defineProps<{
|
|||
emoji?: z.infer<typeof CustomEmoji>;
|
||||
}>();
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const formatNumber = (number: number) =>
|
||||
new Intl.NumberFormat(getLocale(), {
|
||||
notation: "compact",
|
||||
|
|
@ -63,12 +65,13 @@ const formatNumber = (number: number) =>
|
|||
const accounts = ref<z.infer<typeof Account>[] | null>(null);
|
||||
|
||||
const refreshReactions = async () => {
|
||||
const { data } = await client.value.getStatusReactions(statusId);
|
||||
const { data } = await authStore.client.getStatusReactions(statusId);
|
||||
const accountIds =
|
||||
data.find((r) => r.name === reaction.name)?.account_ids.slice(0, 10) ??
|
||||
[];
|
||||
|
||||
const { data: accountsData } = await client.value.getAccounts(accountIds);
|
||||
const { data: accountsData } =
|
||||
await authStore.client.getAccounts(accountIds);
|
||||
|
||||
accounts.value = accountsData;
|
||||
};
|
||||
|
|
@ -76,7 +79,7 @@ const refreshReactions = async () => {
|
|||
const react = async () => {
|
||||
const id = toast.loading(m.gray_stale_antelope_roam());
|
||||
|
||||
const { data } = await client.value.createEmojiReaction(
|
||||
const { data } = await authStore.client.createEmojiReaction(
|
||||
statusId,
|
||||
reaction.name,
|
||||
);
|
||||
|
|
@ -89,7 +92,7 @@ const react = async () => {
|
|||
const unreact = async () => {
|
||||
const id = toast.loading(m.many_weary_bat_intend());
|
||||
|
||||
const { data } = await client.value.deleteEmojiReaction(
|
||||
const { data } = await authStore.client.deleteEmojiReaction(
|
||||
statusId,
|
||||
reaction.name,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -25,5 +25,5 @@ const { note } = defineProps<{
|
|||
note: z.infer<typeof Status>;
|
||||
}>();
|
||||
|
||||
const parent = useNote(client, note.in_reply_to_id);
|
||||
const parent = useNote(note.in_reply_to_id);
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue