Initial commit — AI-powered coding tutor (Professor)
Next.js 16, React 19, Monaco editor, Anthropic SDK, multi-provider AI, Wandbox Python execution, iframe HTML preview, SQLite auth + session persistence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
36
lib/localSession.ts
Normal file
36
lib/localSession.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { Task, Message, ExecutionResult } from '@/types';
|
||||
|
||||
const STORAGE_KEY = 'professor_session';
|
||||
|
||||
export interface LocalSession {
|
||||
topicId: string;
|
||||
task: Task;
|
||||
code: string;
|
||||
messages: Message[];
|
||||
executionResult: ExecutionResult | null;
|
||||
}
|
||||
|
||||
export function saveLocalSession(session: LocalSession): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(session));
|
||||
} catch {
|
||||
// Ignore quota errors
|
||||
}
|
||||
}
|
||||
|
||||
export function loadLocalSession(): LocalSession | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
return JSON.parse(raw) as LocalSession;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearLocalSession(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
Reference in New Issue
Block a user