From b510782a30baf3c89aff9a21d03b2f07aeb4f157 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 28 Aug 2025 07:41:51 +0200 Subject: [PATCH] refactor: :recycle: Rewrite state system to use Pinia for composer and auth --- app/app.vue | 39 +-- app/components/composer/buttons.vue | 5 +- app/components/composer/composer.ts | 240 ---------------- app/components/composer/composer.vue | 56 ++-- app/components/composer/dialog.vue | 6 +- app/components/composer/file-preview.vue | 68 ++--- app/components/composer/files.vue | 10 +- app/components/composer/visibilities.ts | 35 +++ app/components/composer/visibility-picker.vue | 3 +- app/components/editor/bubble-menu.vue | 3 +- app/components/editor/content.vue | 5 +- app/components/editor/emojis-list.vue | 5 +- app/components/editor/suggestion.ts | 8 +- app/components/errors/AuthRequired.vue | 15 +- app/components/navigation/timelines.vue | 6 +- app/components/notes/actions.vue | 21 +- app/components/notes/menu.vue | 12 +- .../notes/reactions/picker/index.vue | 5 +- app/components/notes/reactions/reaction.vue | 11 +- app/components/notes/thread.vue | 2 +- .../notifications/follow-request.vue | 7 +- app/components/oauth/login.vue | 2 +- app/components/preferences/developer.vue | 14 +- app/components/preferences/dialog.vue | 27 +- .../preferences/emojis/batch-dropdown.vue | 18 +- .../preferences/emojis/dropdown.vue | 28 +- app/components/preferences/emojis/index.vue | 12 +- .../preferences/emojis/uploader.vue | 27 +- app/components/preferences/profile.ts | 30 +- app/components/preferences/profile.vue | 54 ++-- app/components/profiles/profile-actions.vue | 18 +- app/components/profiles/profile-badges.vue | 5 +- .../profiles/profile-relationship-actions.vue | 11 +- .../sidebars/account/account-manager.vue | 45 ++- .../sidebars/footer/footer-actions.vue | 9 +- .../sidebars/instance/instance-header.vue | 4 +- app/components/sidebars/left-sidebar.vue | 4 +- app/components/sidebars/sidebar.vue | 3 +- app/components/timelines/account.vue | 2 +- app/components/timelines/global.vue | 2 +- app/components/timelines/home.vue | 6 +- app/components/timelines/local.vue | 2 +- app/components/timelines/notifications.vue | 2 +- app/components/timelines/public.vue | 2 +- app/composables/AccountAcct.ts | 13 +- app/composables/AccountTimeline.ts | 10 +- app/composables/AppData.ts | 13 - app/composables/CacheRefresh.ts | 67 ++--- app/composables/Client.ts | 33 --- app/composables/EventBus.ts | 2 - app/composables/ExtendedDescription.ts | 15 +- app/composables/GlobalTimeline.ts | 8 +- app/composables/HomeTimeline.ts | 8 +- app/composables/Identities.ts | 104 ------- app/composables/Instance.ts | 4 - app/composables/LocalTimeline.ts | 8 +- app/composables/Note.ts | 14 +- app/composables/NoteContext.ts | 14 +- app/composables/NotificationTimeline.ts | 7 +- app/composables/Permissions.ts | 3 - app/composables/PublicTimeline.ts | 8 +- app/composables/Relationship.ts | 21 +- app/composables/SSOConfig.ts | 10 - app/composables/Timeline.ts | 19 +- app/layouts/app.vue | 7 +- app/layouts/auth.vue | 11 + app/layouts/default.vue | 4 +- app/pages/[username]/[uuid].vue | 4 +- app/pages/[username]/index.vue | 2 +- app/pages/callback.vue | 43 +++ app/pages/index.vue | 5 +- app/pages/oauth/reset.vue | 13 +- app/pages/register/index.vue | 8 +- app/stores/auth.ts | 221 +++++++++++++++ app/stores/composer.ts | 260 ++++++++++++++++++ app/utils/auth.ts | 140 ---------- app/utils/urls.ts | 6 +- bun.lock | 11 + nuxt.config.ts | 2 + package.json | 3 + 80 files changed, 999 insertions(+), 1011 deletions(-) delete mode 100644 app/components/composer/composer.ts create mode 100644 app/components/composer/visibilities.ts delete mode 100644 app/composables/AppData.ts delete mode 100644 app/composables/Client.ts delete mode 100644 app/composables/Identities.ts delete mode 100644 app/composables/Permissions.ts delete mode 100644 app/composables/SSOConfig.ts create mode 100644 app/layouts/auth.vue create mode 100644 app/pages/callback.vue create mode 100644 app/stores/auth.ts create mode 100644 app/stores/composer.ts diff --git a/app/app.vue b/app/app.vue index ae09ed7..afaee3d 100644 --- a/app/app.vue +++ b/app/app.vue @@ -24,14 +24,10 @@ import { TooltipProvider } from "./components/ui/tooltip"; //import "~/styles/mcdonalds.css"; const lang = useLanguage(); +const authStore = useAuthStore(); overwriteGetLocale(() => lang.value); -const code = useRequestURL().searchParams.get("code"); -const origin = useRequestURL().searchParams.get("origin"); -const appData = useAppData(); -const instance = useInstance(); -const description = useExtendedDescription(client); -const route = useRoute(); +const description = useExtendedDescription(); // Theme switcher const colorMode = useColorMode(); @@ -62,13 +58,13 @@ useSeoMeta({ titleTemplate: (titleChunk) => { return titleChunk ? `${titleChunk} ยท Versia` : "Versia"; }, - title: computed(() => instance.value?.title ?? ""), - ogImage: computed(() => instance.value?.banner?.url), - twitterTitle: computed(() => instance.value?.title ?? ""), + title: computed(() => authStore.instance?.title ?? ""), + ogImage: computed(() => authStore.instance?.banner?.url), + twitterTitle: computed(() => authStore.instance?.title ?? ""), twitterDescription: computed(() => convert(description.value?.content ?? ""), ), - twitterImage: computed(() => instance.value?.banner?.url), + twitterImage: computed(() => authStore.instance?.banner?.url), description: computed(() => convert(description.value?.content ?? "")), ogDescription: computed(() => convert(description.value?.content ?? "")), ogSiteName: "Versia", @@ -82,28 +78,7 @@ useHead({ }, }); -if (code && origin && appData.value && route.path !== "/oauth/code") { - const newOrigin = new URL( - URL.canParse(origin) ? origin : `https://${origin}`, - ); - - signInWithCode(code, appData.value, newOrigin); -} - -if (origin && !code) { - const newOrigin = new URL( - URL.canParse(origin) ? origin : `https://${origin}`, - ); - - signIn(appData, newOrigin); -} - -useListen("identity:change", (newIdentity) => { - identity.value = newIdentity; - window.location.pathname = "/"; -}); - -useCacheRefresh(client); +useCacheRefresh(); diff --git a/app/components/navigation/timelines.vue b/app/components/navigation/timelines.vue index 1adcffa..d8812bd 100644 --- a/app/components/navigation/timelines.vue +++ b/app/components/navigation/timelines.vue @@ -2,7 +2,7 @@ {{ timeline.name }} @@ -47,12 +47,12 @@ const timelines = [ }, ]; -const { beforeEach } = useRouter(); const { path } = useRoute(); +const authStore = useAuthStore(); const current = computed(() => { if (path === "/") { - return identity.value ? "home" : "public"; + return authStore.isSignedIn ? "home" : "public"; } const timeline = timelines.find((i) => i.url === path); diff --git a/app/components/notes/actions.vue b/app/components/notes/actions.vue index c7ab867..52b7ae4 100644 --- a/app/components/notes/actions.vue +++ b/app/components/notes/actions.vue @@ -1,17 +1,17 @@