Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions app/components/ClassContextSelect.vue
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 = {
joinToken: string
name: string
}

const route = useRoute()
const router = useRouter()
const selectedClassToken = useCookie<string | null>('selected-class-token', {
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 getRouteClassToken() {
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 classToken = getRouteClassToken() || selectedClassToken.value
return classToken ? `class:${classToken}` : '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, selectedClassToken.value],
() => {
selectedContext.value = getCurrentContext()
}
)

watch(
[
classesStatus,
() => classes.value.length,
() => route.path,
() => route.query.class,
() => selectedClassToken.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') {
selectedClassToken.value = null
await router.replace('/universal-admin/create-class')
return
}

if (route.path.startsWith('/admin')) {
const classToken = getRouteClassToken() || selectedClassToken.value
const classExists = classes.value.some((classroom) => classroom.joinToken === classToken)

if (!classToken || !classExists) {
selectedClassToken.value = null

if (canAccessUniversalAdmin.value) {
await router.replace('/universal-admin')
return
}

const firstClass = classes.value[0]

if (firstClass) {
selectedClassToken.value = firstClass.joinToken
await router.replace({
path: '/admin',
query: { class: firstClass.joinToken },
})
}
}
}
} finally {
isRedirecting.value = false
}
},
{ immediate: true }
)

async function changeContext() {
if (selectedContext.value === 'admin') {
if (!canAccessUniversalAdmin.value) {
selectedContext.value = getCurrentContext()
return
}

selectedClassToken.value = null
await router.push('/universal-admin')
return
}

if (selectedContext.value === 'create-class') {
await router.push('/universal-admin/create-class')
return
}

const classToken = selectedContext.value.replace(/^class:/, '')
selectedClassToken.value = classToken
await router.push({
path: '/admin',
query: { class: classToken },
})
}
</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.joinToken" :value="`class:${classroom.joinToken}`">
{{ classroom.name }}
</option>

<option value="create-class">+ Create New Class</option>
</select>
</div>
</template>

<style scoped>
Comment thread
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>
26 changes: 26 additions & 0 deletions app/components/LogoutButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script setup lang="ts">
import { authClient } from '~/utils/auth-client'

const isLoggingOut = ref(false)

async function logout() {
const confirmed = confirm('Are you sure you want to log out?')
if (!confirmed || isLoggingOut.value) return

isLoggingOut.value = true

try {
await authClient.signOut()
window.location.href = '/auth'
Comment thread
AidanLoran marked this conversation as resolved.
Outdated
} catch (error) {
isLoggingOut.value = false
console.error('Logout failed:', error)
}
}
</script>

<template>
<button type="button" :disabled="isLoggingOut" @click="logout">
<slot>⎋ Logout</slot>
</button>
</template>
35 changes: 23 additions & 12 deletions app/layouts/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ html, body { margin: 0; padding: 0; height: 100%; }
display: flex;
height: 100vh;
overflow: hidden;
background: #f8fafc;
background: #eef2f7;
font-family: 'Quicksand', system-ui, sans-serif;
color: #1e293b;
}
Expand All @@ -15,8 +15,8 @@ html, body { margin: 0; padding: 0; height: 100%; }
.rh-sidebar {
width: 18rem;
flex-shrink: 0;
background: #ffffff;
border-right: 1px solid #e2e8f0;
background: #f8fafc;
border-right: 1px solid #dbe3ec;
display: flex;
flex-direction: column;
overflow-y: auto;
Expand All @@ -27,32 +27,43 @@ html, body { margin: 0; padding: 0; height: 100%; }
.rh-logo-icon { width:40px; height:40px; background:#4f46e5; border-radius:8px; display:flex; align-items:center; justify-content:center; color:white; font-weight:700; font-size:1.25rem; }
.rh-logo-name { font-weight:700; font-size:1.1rem; color:#0f172a; line-height:1; }
.rh-logo-accent { color:#4f46e5; }
.rh-logo-sub { font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:.1em; color:#2dd4bf; margin-top:2px; }
.rh-logo-sub { font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:.1em; color:#14b8a6; margin-top:2px; }

.rh-nav-label { font-size:12px; font-weight:500; color:#94a3b8; text-transform:uppercase; letter-spacing:.1em; margin-bottom:16px; }
.rh-nav-label { font-size:12px; font-weight:600; color:#94a3b8; text-transform:uppercase; letter-spacing:.1em; margin-bottom:16px; }
.rh-nav { display:flex; flex-direction:column; gap:4px; }

.rh-nav-btn {
display:flex; align-items:center; width:100%;
padding:12px 16px; font-weight:500; font-size:15px;
padding:12px 16px; font-weight:600; font-size:15px;
border-radius:0 12px 12px 0; border-left:4px solid transparent;
color:#64748b; cursor:pointer; transition:all .15s;
background:transparent; text-align:left;
border-top:none; border-right:none; border-bottom:none;
}
.rh-nav-btn:hover { background:#f8fafc; }
.rh-nav-active { background:#eef2ff !important; color:#4338ca !important; border-left-color:#4f46e5 !important; font-weight:600 !important; }
.rh-nav-btn:hover { background:#eef2f7; color:#334155; }
.rh-nav-active { background:#e7eafe !important; color:#4338ca !important; border-left-color:#4f46e5 !important; font-weight:600 !important; }

.rh-sidebar-footer { padding:24px; }
.rh-back-link { font-size:14px; color:#94a3b8; font-weight:500; text-decoration:none; }
.rh-back-link { font-size:14px; color:#94a3b8; font-weight:600; text-decoration:none; }
.rh-back-link:hover { color:#64748b; }
.rh-logout-link { display:block; margin-top:12px; font-size:14px; color:#94a3b8; font-weight:500; background:none; border:none; padding:0; cursor:pointer; font-family:inherit; }
.rh-logout-link { display:block; margin-top:12px; font-size:14px; color:#94a3b8; font-weight:600; background:none; border:none; padding:0; cursor:pointer; font-family:inherit; }
.rh-logout-link:hover { color:#ef4444; }

/* ── Main ── */
.rh-main { flex:1; overflow-y:auto; padding:24px 32px; }
.rh-workspace { min-width:0; flex:1; display:flex; flex-direction:column; overflow:hidden; }
.rh-header { min-height:5.5rem; flex-shrink:0; display:flex; align-items:center; justify-content:space-between; gap:1.5rem; padding:1rem 2rem; background:#f8fafc; border-bottom:1px solid #dbe3ec; }
.rh-header-label { margin:0 0 .2rem; color:#94a3b8; font-size:.7rem; font-weight:700; letter-spacing:.1em; text-transform:uppercase; }
.rh-header-title { margin:0; color:#0f172a; font-size:1.35rem; font-weight:600; }
.rh-main { min-height:0; flex:1; overflow-y:auto; padding:24px 32px; }
.rh-tab-content { max-width:56rem; margin:0 auto; }

@media (max-width:800px) {
.rh-admin-wrap { height:auto; min-height:100vh; flex-direction:column; overflow:visible; }
.rh-sidebar { width:100%; }
.rh-workspace { overflow:visible; }
.rh-header { align-items:flex-start; flex-direction:column; }
}

/* ── Spacing helpers ── */
.rh-space-y-3 > * + * { margin-top:12px; }
.rh-space-y-4 > * + * { margin-top:16px; }
Expand Down Expand Up @@ -234,4 +245,4 @@ html, body { margin: 0; padding: 0; height: 100%; }

/* ── Transitions ── */
.rh-fade-enter-active, .rh-fade-leave-active { transition:opacity .25s ease; }
.rh-fade-enter-from, .rh-fade-leave-to { opacity:0; }
.rh-fade-enter-from, .rh-fade-leave-to { opacity:0; }
Loading