-
-
Notifications
You must be signed in to change notification settings - Fork 565
feat(web): redirect logged-in users from root to /threads (opt-in) #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
888d6af
dfadea6
5e5066c
b8c922d
7a34522
753d999
01605f7
d0af493
6cfe7e7
935a985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <script setup lang="ts"> | ||
| import { mdiClose, mdiArrowRight } from '@mdi/js' | ||
|
|
||
| const route = useRoute() | ||
| const authStore = useAuthStore() | ||
| const redirectStore = useRedirectPreferenceStore() | ||
|
|
||
| const showPopover = computed( | ||
| () => | ||
| route.name === 'index' && | ||
| authStore.authUser !== null && | ||
| !redirectStore.enabled && | ||
| !redirectStore.dismissedThisSession, | ||
| ) | ||
| </script> | ||
|
|
||
| <template> | ||
| <v-card | ||
| v-if="showPopover" | ||
| class="redirect-prompt pa-4" | ||
| elevation="8" | ||
| rounded="lg" | ||
| max-width="280" | ||
| > | ||
| <div class="d-flex align-center justify-space-between"> | ||
| <span class="text-body-1">Skip this page next time?</span> | ||
| <v-btn | ||
| :icon="mdiClose" | ||
| variant="text" | ||
| size="small" | ||
| color="warning" | ||
| density="comfortable" | ||
| aria-label="Dismiss" | ||
| @click="redirectStore.dismiss()" | ||
| /> | ||
| </div> | ||
| <a | ||
| class="text-primary text-decoration-none hover:text-decoration-underline d-inline-flex align-center mt-1" | ||
| href="#" | ||
| @click.prevent="redirectStore.enable()" | ||
| > | ||
| Always open dashboard | ||
| <v-icon :icon="mdiArrowRight" size="small" class="ml-1" /> | ||
| </a> | ||
| </v-card> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
| .redirect-prompt { | ||
| position: absolute; | ||
| right: 0; | ||
| top: 100%; | ||
| margin-top: 8px; | ||
| z-index: 10; | ||
| } | ||
| </style> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export default defineNuxtRouteMiddleware(() => { | ||
| try { | ||
| if (localStorage.getItem('httpsms_redirect_to_threads') === 'true') { | ||
| return navigateTo('/threads', { replace: true }) | ||
| } | ||
| } catch (error) { | ||
| console.error(error) | ||
| } | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import { | |
|
|
||
| definePageMeta({ | ||
| layout: 'website', | ||
| middleware: ['redirect-to-threads'], | ||
| }) | ||
|
|
||
| useSeoMeta({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { defineStore } from 'pinia' | ||
| import { ref } from 'vue' | ||
|
|
||
| const STORAGE_KEY = 'httpsms_redirect_to_threads' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| function readFlag(): boolean { | ||
| try { | ||
| return localStorage.getItem(STORAGE_KEY) === 'true' | ||
| } catch (error) { | ||
| console.error(error) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| export const useRedirectPreferenceStore = defineStore( | ||
|
Check warning on line 15 in web/app/stores/redirectPreference.ts
|
||
| 'redirectPreference', | ||
| () => { | ||
| const enabled = ref(readFlag()) | ||
| const dismissedThisSession = ref(false) | ||
|
|
||
| function enable() { | ||
| enabled.value = true | ||
| try { | ||
| localStorage.setItem(STORAGE_KEY, 'true') | ||
| } catch (error) { | ||
| console.error(error) | ||
| } | ||
| navigateTo('/threads', { replace: true }) | ||
| } | ||
|
Comment on lines
+21
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| function dismiss() { | ||
| dismissedThisSession.value = true | ||
| } | ||
|
|
||
| function resetState() { | ||
| enabled.value = false | ||
| dismissedThisSession.value = false | ||
| try { | ||
| localStorage.removeItem(STORAGE_KEY) | ||
| } catch (error) { | ||
| console.error(error) | ||
| } | ||
| } | ||
|
|
||
| return { enabled, dismissedThisSession, enable, dismiss, resetState } | ||
| }, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STORAGE_KEY. If the key ever needs to change, this file won't be caught by a simple search-and-replace on the constant, and the redirect middleware will silently stop working while the store continues writing the new key.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!