Files
supabase/apps/learn/context/framework-context.tsx
Terry Sutton dda0b526ac Feat/learn (#41566)
wip

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

# Release Notes

* **New Features**
* Added a new Learn application offering foundational Supabase courses
with interactive documentation
* Courses include Architecture, Authentication, Data Fundamentals,
Security, Storage, Realtime, and Edge Functions
  * Chapter tracking and progress indicators for course completions
  * Responsive sidebar navigation with search/command menu
  * Theme switching support (light, dark, classic dark modes)
  * Mobile-friendly course interface

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alan Daniel <stylesshjs@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-04 21:36:24 -03:30

47 lines
1.4 KiB
TypeScript

'use client'
import { createContext, useContext, useEffect, useState } from 'react'
type Course = 'foundations' | 'smart-office' | 'performance-scaling' | 'debugging-operations'
type CourseContextType = {
course: Course
setCourse: (course: Course) => void
}
const CourseContext = createContext<CourseContextType | undefined>(undefined)
export function FrameworkProvider({ children }: { children: React.ReactNode }) {
const [course, setCourseState] = useState<Course>('foundations')
// Initialize from localStorage on mount (client-side only)
useEffect(() => {
const storedCourse = localStorage.getItem('preferredCourse')
const validCourses: Course[] = [
'foundations',
'smart-office',
'performance-scaling',
'debugging-operations',
]
if (storedCourse && validCourses.includes(storedCourse as Course)) {
setCourseState(storedCourse as Course)
}
}, [])
// Update localStorage when framework changes
const setCourse = (newCourse: Course) => {
setCourseState(newCourse)
localStorage.setItem('preferredCourse', newCourse)
}
return <CourseContext.Provider value={{ course, setCourse }}>{children}</CourseContext.Provider>
}
// Custom hook to use the framework context
export function useCourse() {
const context = useContext(CourseContext)
if (context === undefined) {
throw new Error('useCourse must be used within a CourseProvider')
}
return context
}