Files
homeschool-dashboard/frontend/src/views/TVView.vue
T
derekcandClaude Sonnet 4.6 d724262e27 Add Rules & Expectations feature with TV overlay and dashboard layout updates
- Add Rules & Expectations admin section with drag-to-reorder, add/edit/delete
- Add Overlays card to Dashboard with Rules/Expectations toggle button (LIVE badge when active)
- Add full-screen rules overlay on TV view (green theme, numbered list, tap to dismiss)
- Backend: new RuleItem model, /api/rules CRUD + bulk reorder, /api/overlays WS broadcast endpoints
- Schedule store handles show_rules / hide_rules WebSocket events
- Rearrange Dashboard top row: TV Dashboard | 3 Strikes | Overlays (3-col, mobile stacks)
- Put Today's Session and Today's Schedule side-by-side at 50/50 width (mobile stacks)
- Update README with all new features, setup steps, WS events, and project structure

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-03-19 07:21:50 -07:00

718 lines
20 KiB
Vue

<template>
<div class="tv-root">
<!-- Header bar -->
<header class="tv-header">
<div class="tv-child-name-wrap">
<div class="tv-child-name">{{ scheduleStore.child?.name || 'Loading...' }}</div>
<div class="tv-strikes" v-if="scheduleStore.child?.strikes > 0">
<span
v-for="i in scheduleStore.child.strikes"
:key="i"
class="tv-strike-x"
>✕</span>
</div>
</div>
<div class="tv-clock">{{ clockDisplay }}</div>
<div class="tv-date">{{ dateDisplay }}</div>
</header>
<!-- Day progress bar — full width, always visible when day hours are set -->
<div class="tv-day-progress" v-if="scheduleStore.blocks.length > 0">
<div class="tv-day-progress-meta">
<span class="tv-day-start">🟢 Start</span>
<span class="tv-day-pct">{{ dayProgressPercent }}% through the day</span>
<span class="tv-day-end">Finish 🏁</span>
</div>
<ProgressBar :percent="dayProgressPercent" />
</div>
<!-- No session state -->
<div v-if="!scheduleStore.session" class="tv-idle">
<div class="tv-idle-icon">🌟</div>
<div class="tv-idle-text">No active school session today</div>
</div>
<!-- Active session -->
<div v-else class="tv-main">
<!-- Left: timer -->
<div class="tv-timer-col tv-greeting-col" v-if="!scheduleStore.currentBlock">
<div class="tv-greeting">Good Morning!</div>
<div class="tv-greeting-sub">Ready to start school?</div>
<div v-if="firstBlockCountdown !== null" class="tv-countdown-wrap">
<div class="tv-countdown-label">First block starts in</div>
<div class="tv-countdown">{{ firstBlockCountdown }}</div>
</div>
</div>
<div class="tv-timer-col" v-else>
<!-- Break mode badge -->
<template v-if="scheduleStore.isBreakMode">
<div class="tv-subject-badge tv-break-badge">
☕ Break Time
</div>
<TimerDisplay
:block="tvBreakBlock"
:session="scheduleStore.session"
:is-paused="!scheduleStore.breakStartedAt"
:block-started-at="scheduleStore.breakStartedAt"
:block-elapsed-offset="scheduleStore.breakElapsedOffset"
/>
</template>
<!-- Normal subject timer -->
<template v-else>
<div class="tv-subject-badge" :style="{ background: currentSubjectColor }">
{{ currentSubjectIcon }} {{ currentSubjectName }}
</div>
<TimerDisplay
:block="scheduleStore.currentBlock"
:session="scheduleStore.session"
:is-paused="scheduleStore.isPaused"
:block-started-at="scheduleStore.blockStartedAt"
:block-elapsed-offset="scheduleStore.blockElapsedOffset"
/>
<div class="tv-block-notes" v-if="scheduleStore.currentBlock.notes">
{{ scheduleStore.currentBlock.notes }}
</div>
</template>
</div>
<!-- Center: subject options / break message / morning routine -->
<div
class="tv-options-col"
:style="scheduleStore.isBreakMode
? { background: '#451a0322', borderColor: '#f59e0b' }
: scheduleStore.currentBlock
? { background: currentSubjectColor + '22', borderColor: currentSubjectColor }
: { background: '#1e293b', borderColor: '#334155' }"
>
<!-- Break time panel -->
<template v-if="scheduleStore.isBreakMode">
<div class="tv-options-title" style="color: #f59e0b;">Break Activities</div>
<div v-if="scheduleStore.breakActivities.length" class="tv-options-list">
<div v-for="(item, i) in scheduleStore.breakActivities" :key="i" class="tv-option-item">
{{ item }}
</div>
</div>
<div v-else class="tv-options-empty">No break activities added yet.</div>
</template>
<!-- Morning routine during greeting state -->
<template v-else-if="!scheduleStore.currentBlock">
<div class="tv-options-title">Activities</div>
<div v-if="scheduleStore.morningRoutine.length" class="tv-options-list">
<div v-for="(item, i) in scheduleStore.morningRoutine" :key="i" class="tv-option-item">
{{ item }}
</div>
</div>
<div v-else class="tv-options-empty">No morning routine items added yet.</div>
</template>
<!-- Subject options during active block -->
<template v-else>
<div class="tv-options-title">Activities</div>
<div v-if="currentSubjectOptions.length" class="tv-options-list">
<div v-for="opt in currentSubjectOptions" :key="opt.id" class="tv-option-item">
{{ opt.text }}
</div>
</div>
<div v-else class="tv-options-empty">No activities listed for this subject.</div>
</template>
</div>
<!-- Right: schedule list -->
<div class="tv-sidebar">
<div class="tv-schedule-list">
<ScheduleBlock
v-for="block in scheduleStore.blocks"
:key="block.id"
:block="block"
:is-current="block.id === scheduleStore.session?.current_block_id"
:is-completed="scheduleStore.completedBlockIds.includes(block.id)"
:elapsed-seconds="blockElapsed(block)"
compact
/>
</div>
</div>
</div>
<!-- WS connection indicator -->
<div class="tv-ws-status" :class="{ connected: wsConnected }">
{{ wsConnected ? '● Live' : '○ Reconnecting...' }}
</div>
<!-- Meeting corner toasts (5-min / 1-min warnings) -->
<div class="tv-meeting-toasts">
<transition-group name="toast">
<div v-for="alert in meetingAlerts.dashboardAlerts.value" :key="alert.id" class="tv-meeting-toast">
<div class="tv-toast-icon">📅</div>
<div class="tv-toast-body">
<div class="tv-toast-title">Upcoming Meeting</div>
<div class="tv-toast-label">{{ alert.label }}</div>
<div class="tv-toast-countdown">Starts in {{ meetingAlerts.alertCountdown(alert) }}</div>
</div>
<button class="tv-toast-dismiss" @click="meetingAlerts.dismissDashboardAlert(alert.id)">✕</button>
</div>
</transition-group>
</div>
<!-- Meeting full-screen alert overlay -->
<transition name="tv-alert">
<div v-if="meetingAlerts.tvAlert.value" class="tv-meeting-overlay" @click="meetingAlerts.dismissTvAlert()">
<div class="tv-meeting-box">
<div class="tv-meeting-icon">📅</div>
<div class="tv-meeting-title">Meeting Starting Now</div>
<div class="tv-meeting-label">{{ meetingAlerts.tvAlert.value.label }}</div>
<div class="tv-meeting-dismiss-hint">Tap anywhere to dismiss &bull; Auto-closing in {{ meetingAlerts.tvCountdown.value }}s</div>
</div>
</div>
</transition>
<!-- Rules/Expectations full-screen overlay -->
<transition name="tv-alert">
<div v-if="scheduleStore.showRulesOverlay" class="tv-rules-overlay" @click="scheduleStore.showRulesOverlay = false">
<div class="tv-rules-box">
<div class="tv-rules-header">
<span class="tv-rules-icon">📋</span>
<span class="tv-rules-title">Rules &amp; Expectations</span>
</div>
<ol class="tv-rules-list">
<li v-for="(rule, i) in scheduleStore.rulesOverlayItems" :key="i" class="tv-rules-item">
{{ rule }}
</li>
</ol>
<div class="tv-rules-dismiss-hint">Tap anywhere to dismiss</div>
</div>
</div>
</transition>
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { useScheduleStore } from '@/stores/schedule'
import { useWebSocket } from '@/composables/useWebSocket'
import { useMeetingAlerts } from '@/composables/useMeetingAlerts'
import TimerDisplay from '@/components/TimerDisplay.vue'
import ProgressBar from '@/components/ProgressBar.vue'
import ScheduleBlock from '@/components/ScheduleBlock.vue'
const route = useRoute()
const scheduleStore = useScheduleStore()
const childId = parseInt(route.params.childId)
const meetingAlerts = useMeetingAlerts()
// Read timezone from localStorage (set by the parent in Admin → Settings)
const tz = localStorage.getItem('tz') || undefined
// Clock
const now = ref(new Date())
setInterval(() => { now.value = new Date() }, 1000)
const clockDisplay = computed(() =>
now.value.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: tz })
)
const dateDisplay = computed(() =>
now.value.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric', timeZone: tz })
)
// Day progress helpers
function formatDayTime(str) {
if (!str) return ''
const [h, m] = str.split(':').map(Number)
const period = h >= 12 ? 'PM' : 'AM'
const hour = h % 12 || 12
return `${hour}:${String(m).padStart(2, '0')} ${period}`
}
const dayProgressPercent = computed(() => {
const allBlocks = scheduleStore.blocks
if (!allBlocks.length) return 0
const totalSeconds = allBlocks.reduce((sum, b) => sum + (b.duration_minutes || 0) * 60, 0)
if (totalSeconds === 0) return 0
const remainingSeconds = allBlocks.reduce((sum, b) => {
if (scheduleStore.completedBlockIds.includes(b.id)) return sum
const blockTotal = (b.duration_minutes || 0) * 60
const elapsed = blockElapsed(b)
return sum + Math.max(0, blockTotal - elapsed)
}, 0)
return Math.max(0, Math.min(100, Math.round((totalSeconds - remainingSeconds) / totalSeconds * 100)))
})
// Countdown to first block
const firstBlockCountdown = computed(() => {
const first = scheduleStore.blocks[0]
if (!first?.time_start) return null
const [h, m, s] = first.time_start.split(':').map(Number)
const target = new Date(now.value)
target.setHours(h, m, s || 0, 0)
const diffMs = target - now.value
if (diffMs <= 0) return null
const totalSec = Math.floor(diffMs / 1000)
const hours = Math.floor(totalSec / 3600)
const mins = Math.floor((totalSec % 3600) / 60)
const secs = totalSec % 60
if (hours > 0) return `${hours}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`
return `${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`
})
// Virtual block for break timer display on TV.
// We don't re-check break_time_enabled here — if isBreakMode is true we always
// want to show a timer. Fall back to the block's own duration when
// break_time_minutes is not set.
const tvBreakBlock = computed(() => {
const block = scheduleStore.currentBlock
if (!block) return null
return {
...block,
duration_minutes: block.break_time_minutes ?? null,
subject: { color: '#f59e0b' },
}
})
// Subject display helpers
const currentSubjectColor = computed(() => {
const block = scheduleStore.currentBlock
return block?.subject?.color || '#4F46E5'
})
const currentSubjectIcon = computed(() => scheduleStore.currentBlock?.subject?.icon || '📚')
const currentSubjectName = computed(() =>
scheduleStore.currentBlock?.label || scheduleStore.currentBlock?.subject?.name || 'Current Block'
)
const currentSubjectOptions = computed(() =>
scheduleStore.currentBlock?.subject?.options || []
)
function blockElapsed(block) {
const currentId = scheduleStore.session?.current_block_id
if (block.id === currentId && scheduleStore.blockStartedAt && !scheduleStore.isPaused) {
return scheduleStore.blockElapsedOffset + Math.floor((now.value - scheduleStore.blockStartedAt) / 1000)
}
return scheduleStore.blockElapsedCache[block.id] || 0
}
// WebSocket
const { connected: wsConnected } = useWebSocket(childId, (msg) => {
scheduleStore.applyWsEvent(msg)
})
// Initial data load
onMounted(async () => {
await scheduleStore.fetchDashboard(childId)
})
</script>
<style scoped>
.tv-root {
min-height: 100vh;
background: #0f172a;
color: #f1f5f9;
display: flex;
flex-direction: column;
padding: 2rem;
gap: 2rem;
}
.tv-header {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 2px solid #1e293b;
padding-bottom: 1rem;
}
.tv-child-name-wrap {
display: flex;
align-items: center;
gap: 1rem;
}
.tv-child-name {
font-size: 2.5rem;
font-weight: 700;
color: #818cf8;
}
.tv-strikes {
display: flex;
gap: 0.4rem;
}
.tv-strike-x {
font-size: 2rem;
font-weight: 700;
color: #ef4444;
line-height: 1;
}
.tv-clock {
font-size: 3rem;
font-weight: 300;
font-variant-numeric: tabular-nums;
color: #f8fafc;
}
.tv-date {
font-size: 1.25rem;
color: #94a3b8;
text-align: right;
}
.tv-idle {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 1rem;
}
.tv-idle-icon { font-size: 5rem; }
.tv-idle-text { font-size: 2rem; color: #64748b; }
.tv-main {
flex: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
min-height: 0;
}
.tv-timer-col {
display: flex;
flex-direction: column;
gap: 1.5rem;
align-items: center;
justify-content: center;
}
.tv-subject-badge {
font-size: 1.4rem;
font-weight: 600;
padding: 0.6rem 1.5rem;
border-radius: 999px;
color: #fff;
text-align: center;
}
.tv-break-badge {
background: #92400e;
color: #fde68a;
}
.tv-greeting-col {
justify-content: center;
gap: 1rem;
}
.tv-greeting {
font-size: 3rem;
font-weight: 700;
color: #818cf8;
text-align: center;
}
.tv-greeting-sub {
font-size: 1.6rem;
color: #64748b;
text-align: center;
}
.tv-countdown-wrap {
margin-top: 1.5rem;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.4rem;
}
.tv-countdown-label {
font-size: 1rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: #475569;
}
.tv-countdown {
font-size: 4rem;
font-weight: 300;
font-variant-numeric: tabular-nums;
color: #c7d2fe;
letter-spacing: 0.05em;
}
.tv-block-notes {
font-size: 1rem;
color: #94a3b8;
text-align: center;
}
.tv-options-col {
display: flex;
flex-direction: column;
gap: 1rem;
justify-content: center;
border: 2px solid;
border-radius: 1rem;
padding: 1.5rem 2rem;
}
.tv-options-title {
font-size: 1rem;
text-transform: uppercase;
letter-spacing: 0.1em;
color: #475569;
}
.tv-options-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.tv-option-item {
font-size: 2rem;
font-weight: 500;
color: #e2e8f0;
padding: 0.6rem 0;
border-bottom: 1px solid #1e293b;
line-height: 1.3;
}
.tv-options-empty {
font-size: 1.1rem;
color: #334155;
font-style: italic;
}
.tv-day-progress {
background: #1e293b;
border-radius: 1rem;
padding: 1rem 1.5rem 1.25rem;
}
.tv-day-progress-meta {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 0.6rem;
}
.tv-day-start,
.tv-day-end {
font-size: 1rem;
color: #64748b;
font-variant-numeric: tabular-nums;
}
.tv-day-pct {
font-size: 1.1rem;
font-weight: 600;
color: #94a3b8;
letter-spacing: 0.02em;
}
.tv-sidebar {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.tv-schedule-list {
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 0.75rem;
max-height: 60vh;
}
/* Expand timer to fill the column */
.tv-timer-col :deep(.timer-wrap) {
width: min(100%, 420px);
height: min(100%, 420px);
}
.tv-timer-col :deep(.timer-time) { font-size: 5.5rem; }
.tv-timer-col :deep(.timer-label) { font-size: 1.4rem; }
/* Make schedule block text larger for TV viewing */
.tv-schedule-list :deep(.block-title) { font-size: 1.2rem; }
.tv-schedule-list :deep(.block-time) { font-size: 1rem; }
.tv-schedule-list :deep(.block-card) { padding: 0.85rem 1rem; }
.tv-ws-status {
position: fixed;
bottom: 1rem;
right: 1rem;
font-size: 0.75rem;
color: #ef4444;
opacity: 0.7;
}
.tv-ws-status.connected {
color: #22c55e;
}
/* Meeting corner toasts */
.tv-meeting-toasts {
position: fixed;
bottom: 2rem;
right: 2rem;
z-index: 9998;
display: flex;
flex-direction: column;
gap: 1rem;
align-items: flex-end;
}
.tv-meeting-toast {
display: flex;
align-items: flex-start;
gap: 1rem;
background: #1c1a07;
border: 2px solid #f59e0b;
border-radius: 1rem;
padding: 1.2rem 1.5rem;
width: 380px;
box-shadow: 0 4px 30px rgba(0,0,0,0.7);
}
.tv-toast-icon { font-size: 2.2rem; flex-shrink: 0; }
.tv-toast-body { flex: 1; min-width: 0; }
.tv-toast-title { font-size: 0.85rem; font-weight: 700; color: #fbbf24; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.2rem; }
.tv-toast-label { font-size: 1.3rem; font-weight: 700; color: #f1f5f9; margin-bottom: 0.3rem; }
.tv-toast-countdown { font-size: 1.6rem; font-weight: 800; color: #fbbf24; font-variant-numeric: tabular-nums; }
.tv-toast-dismiss { background: none; border: none; color: #64748b; cursor: pointer; font-size: 1.4rem; padding: 0; flex-shrink: 0; line-height: 1; }
.tv-toast-dismiss:hover { color: #f1f5f9; }
.toast-enter-active { transition: all 0.3s ease; }
.toast-leave-active { transition: all 0.3s ease; }
.toast-enter-from { opacity: 0; transform: translateX(100%); }
.toast-leave-to { opacity: 0; transform: translateX(100%); }
/* Meeting full-screen alert */
.tv-meeting-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.75);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
cursor: pointer;
}
.tv-meeting-box {
background: #1e1b4b;
border: 3px solid #6366f1;
border-radius: 2rem;
padding: 4rem 5rem;
text-align: center;
max-width: 700px;
width: 90%;
box-shadow: 0 0 80px rgba(99, 102, 241, 0.4);
}
.tv-meeting-icon { font-size: 5rem; margin-bottom: 1rem; }
.tv-meeting-title {
font-size: 2.5rem;
font-weight: 800;
color: #a5b4fc;
margin-bottom: 0.5rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.tv-meeting-label {
font-size: 3.5rem;
font-weight: 900;
color: #f1f5f9;
margin-bottom: 2rem;
}
.tv-meeting-dismiss-hint {
font-size: 1.1rem;
color: #64748b;
}
.tv-alert-enter-active { transition: all 0.4s ease; }
.tv-alert-leave-active { transition: all 0.3s ease; }
.tv-alert-enter-from { opacity: 0; transform: scale(0.9); }
.tv-alert-leave-to { opacity: 0; transform: scale(1.05); }
/* Rules/Expectations full-screen overlay */
.tv-rules-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.85);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
cursor: pointer;
}
.tv-rules-box {
background: #0f172a;
border: 3px solid #10b981;
border-radius: 2rem;
padding: 3.5rem 4.5rem;
max-width: 800px;
width: 90%;
max-height: 85vh;
overflow-y: auto;
box-shadow: 0 0 80px rgba(16, 185, 129, 0.3);
display: flex;
flex-direction: column;
gap: 2rem;
}
.tv-rules-header {
display: flex;
align-items: center;
gap: 1rem;
justify-content: center;
}
.tv-rules-icon { font-size: 3rem; }
.tv-rules-title {
font-size: 2.5rem;
font-weight: 800;
color: #34d399;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.tv-rules-list {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 1.25rem;
counter-reset: rules-counter;
}
.tv-rules-item {
counter-increment: rules-counter;
display: flex;
align-items: flex-start;
gap: 1.25rem;
font-size: 2rem;
font-weight: 500;
color: #f1f5f9;
line-height: 1.3;
padding-bottom: 1.25rem;
border-bottom: 1px solid #1e293b;
}
.tv-rules-item:last-child { border-bottom: none; padding-bottom: 0; }
.tv-rules-item::before {
content: counter(rules-counter);
display: flex;
align-items: center;
justify-content: center;
min-width: 2.5rem;
height: 2.5rem;
background: #064e3b;
border: 2px solid #10b981;
border-radius: 50%;
font-size: 1.2rem;
font-weight: 800;
color: #34d399;
flex-shrink: 0;
margin-top: 0.1rem;
}
.tv-rules-dismiss-hint {
font-size: 1rem;
color: #475569;
text-align: center;
margin-top: 0.5rem;
}
</style>