-
Notifications
You must be signed in to change notification settings - Fork 1
Dropdown menu implementation #434
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8d19a82
Merge branch 'stage' of https://github.com/UTDallasEPICS/Reading-MLK …
AidanLoran 6705704
poster to user relation and removal of redundant "admin" boolean attr…
AidanLoran e4240e4
oops fixed the migration
AidanLoran 5ce4fa9
dropdown implementation
nevins321 f7a340e
if user is admin it should send them to the universal-admin page
nevins321 f0742e8
Merge branch 'stage' of https://github.com/UTDallasEPICS/Reading-MLK …
AidanLoran 28ebdc0
aidan fixes
nevins321 58b55fa
aidan fixes
nevins321 908a8ee
seperate classContextSelect into 2 files
nevins321 4af0c64
Merge branch 'renaming' into dropdown-menu-implementation
nevins321 003ddc6
Merge branch 'stage' into dropdown-menu-implementation
nevins321 8311efc
small bug fix
nevins321 1fcec14
fixed
nevins321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| <script setup lang="ts"> | ||
| import { authClient } from '../utils/auth-client' | ||
|
|
||
| type ClassOption = { | ||
| id: string | ||
| name: string | ||
| } | ||
|
|
||
| const route = useRoute() | ||
| const router = useRouter() | ||
| const selectedClassId = useCookie<string | null>('selected-class-id', { | ||
| sameSite: 'lax', | ||
| }) | ||
| const { data: session } = await authClient.useSession(useFetch) | ||
|
|
||
| const { data: classes, status: classesStatus } = await useFetch<ClassOption[]>( | ||
| '/api/universal-admin/classes', | ||
| { | ||
| key: 'universal-admin-classes', | ||
| default: () => [], | ||
| } | ||
| ) | ||
|
|
||
| function getRouteClassId() { | ||
| const classQuery = route.query.class | ||
| return Array.isArray(classQuery) ? classQuery[0] : classQuery | ||
| } | ||
|
|
||
| function getCurrentContext() { | ||
| if (route.path === '/universal-admin/create-class') { | ||
| return 'create-class' | ||
| } | ||
|
|
||
| if (route.path.startsWith('/admin')) { | ||
| const classId = getRouteClassId() || selectedClassId.value | ||
| return classId ? `class:${classId}` : 'admin' | ||
| } | ||
|
|
||
| return 'admin' | ||
| } | ||
|
|
||
| const selectedContext = ref(getCurrentContext()) | ||
| const isRedirecting = ref(false) | ||
| const canAccessUniversalAdmin = computed(() => session.value?.user?.role === 'admin') | ||
| const canManageClasses = computed( | ||
| () => session.value?.user?.role === 'admin' || session.value?.user?.role === 'poster' | ||
| ) | ||
|
|
||
| watch( | ||
| () => [route.path, route.query.class, selectedClassId.value], | ||
| () => { | ||
| selectedContext.value = getCurrentContext() | ||
| } | ||
| ) | ||
|
|
||
| watch( | ||
| [ | ||
| classesStatus, | ||
| () => classes.value.length, | ||
| () => route.path, | ||
| () => route.query.class, | ||
| () => selectedClassId.value, | ||
| canAccessUniversalAdmin, | ||
| canManageClasses, | ||
| ], | ||
| async () => { | ||
| if (!canManageClasses.value || isRedirecting.value) { | ||
| return | ||
| } | ||
|
|
||
| isRedirecting.value = true | ||
|
|
||
| try { | ||
| if (classesStatus.value !== 'success') { | ||
| return | ||
| } | ||
|
|
||
| if (classes.value.length === 0 && route.path !== '/universal-admin/create-class') { | ||
| selectedClassId.value = null | ||
| await router.replace('/universal-admin/create-class') | ||
| return | ||
| } | ||
|
|
||
| if (route.path.startsWith('/admin')) { | ||
| const classId = getRouteClassId() || selectedClassId.value | ||
| const classExists = classes.value.some((classroom) => classroom.id === classId) | ||
|
|
||
| if (!classId || !classExists) { | ||
| selectedClassId.value = null | ||
|
|
||
| if (canAccessUniversalAdmin.value) { | ||
| await router.replace('/universal-admin') | ||
| return | ||
| } | ||
|
|
||
| const firstClass = classes.value[0] | ||
|
|
||
| if (firstClass) { | ||
| selectedClassId.value = firstClass.id | ||
| await router.replace({ | ||
| path: '/admin', | ||
| query: { class: firstClass.id }, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } finally { | ||
| isRedirecting.value = false | ||
| } | ||
| }, | ||
| { immediate: true } | ||
| ) | ||
|
|
||
| async function changeContext() { | ||
| if (selectedContext.value === 'admin') { | ||
| if (!canAccessUniversalAdmin.value) { | ||
| selectedContext.value = getCurrentContext() | ||
| return | ||
| } | ||
|
|
||
| selectedClassId.value = null | ||
| await router.push('/universal-admin') | ||
| return | ||
| } | ||
|
|
||
| if (selectedContext.value === 'create-class') { | ||
| await router.push('/universal-admin/create-class') | ||
| return | ||
| } | ||
|
|
||
| const classId = selectedContext.value.replace(/^class:/, '') | ||
|
nevins321 marked this conversation as resolved.
Outdated
|
||
| selectedClassId.value = classId | ||
| await router.push({ | ||
| path: '/admin', | ||
| query: { class: classId }, | ||
| }) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="class-context-select"> | ||
| <label for="class-context">Managing</label> | ||
|
|
||
| <select id="class-context" v-model="selectedContext" @change="changeContext"> | ||
| <option v-if="canAccessUniversalAdmin" value="admin">Admin</option> | ||
|
|
||
| <option v-if="classesStatus === 'pending'" disabled>Loading classes…</option> | ||
|
|
||
| <option v-for="classroom in classes" :key="classroom.id" :value="`class:${classroom.id}`"> | ||
| {{ classroom.name }} | ||
| </option> | ||
|
|
||
| <option value="create-class">+ Create New Class</option> | ||
| </select> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style scoped> | ||
|
AidanLoran marked this conversation as resolved.
Outdated
|
||
| .class-context-select { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.75rem; | ||
| } | ||
|
|
||
| label { | ||
| color: #64748b; | ||
| font-size: 0.75rem; | ||
| font-weight: 700; | ||
| letter-spacing: 0.08em; | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| select { | ||
| min-width: 15rem; | ||
| padding: 0.7rem 0.9rem; | ||
| background: #f8fafc; | ||
| border: 1px solid #cbd5e1; | ||
| border-radius: 0.65rem; | ||
| color: #1e293b; | ||
| cursor: pointer; | ||
| font: inherit; | ||
| font-size: 0.9rem; | ||
| font-weight: 700; | ||
| } | ||
|
|
||
| select:focus { | ||
| border-color: #4f46e5; | ||
| outline: none; | ||
| box-shadow: 0 0 0 3px rgb(79 70 229 / 12%); | ||
| } | ||
|
|
||
| @media (max-width: 800px) { | ||
| .class-context-select { | ||
| width: 100%; | ||
| } | ||
|
|
||
| select { | ||
| min-width: 0; | ||
| flex: 1; | ||
| } | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
AidanLoran marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.