Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LocaleProvider } from '@/lib/i18n'
import { getLocale } from '@/lib/i18n/server'
import { ThemeProvider, themeInitScript } from '@/lib/theme'
import { cn } from '@/lib/utils'
import { Analytics } from '@vercel/analytics/next'
Expand Down Expand Up @@ -37,14 +38,15 @@ export const metadata: Metadata = {
'A coding environment where the AI never hands you the answer. It makes you find it. For devs who want to actually learn in the AI era.',
}

export default function RootLayout({
export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
}>) {
const locale = await getLocale()
return (
<html
lang='en'
lang={locale === 'pt' ? 'pt-BR' : 'en'}
suppressHydrationWarning
className={cn(
'h-full antialiased',
Expand All @@ -61,7 +63,7 @@ export default function RootLayout({
>
<script dangerouslySetInnerHTML={{ __html: themeInitScript }} />
<ThemeProvider>
<LocaleProvider>{children}</LocaleProvider>
<LocaleProvider initialLocale={locale}>{children}</LocaleProvider>
</ThemeProvider>
<Analytics />
</body>
Expand Down
18 changes: 7 additions & 11 deletions src/features/challenges/components/custom-challenge-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client'

import { STACKS as DOMAIN_STACKS } from '@/domain/stacks'
import { getAccessToken } from '@/lib/api/client'
import { useT } from '@/lib/i18n'
import { cn } from '@/lib/utils'
import {
Expand All @@ -15,17 +17,13 @@ import { AnimatePresence, motion } from 'motion/react'
import { useRouter } from 'next/navigation'
import * as React from 'react'
import { generateChallenge, getTrainingRecommendation } from '../actions'
import { getAccessToken } from '@/lib/api/client'

type Kind = 'code' | 'design'
type Level = 'beginner' | 'intermediate' | 'advanced'

const LEVEL_IDS: Level[] = ['beginner', 'intermediate', 'advanced']

const STACKS = [
{ id: 'javascript', label: 'JavaScript' },
{ id: 'typescript', label: 'TypeScript' },
]
const STACKS = DOMAIN_STACKS.map((s) => ({ id: s.id, label: s.label }))

const MAX_PROMPT = 500

Expand Down Expand Up @@ -225,9 +223,7 @@ export function CustomChallengeDialog({
<PenLine className='size-3' />
{t.badge}
</div>
<h2 className='type-h3 mb-2'>
{t.heading}
</h2>
<h2 className='type-h3 mb-2'>{t.heading}</h2>
<p className='mb-6 text-sm text-muted-foreground'>
{t.subheading}
</p>
Expand Down Expand Up @@ -351,7 +347,7 @@ export function CustomChallengeDialog({
</div>

{error && (
<div className='border-destructive/30 bg-destructive/5 text-destructive rounded-lg border px-4 py-3 text-sm'>
<div className='rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive'>
{error}
</div>
)}
Expand All @@ -361,15 +357,15 @@ export function CustomChallengeDialog({
<button
type='button'
onClick={onClose}
className='border-border text-muted-foreground hover:bg-muted hover:text-ink flex-1 cursor-pointer rounded-full border px-5 py-2.5 text-sm font-medium transition-colors'
className='flex-1 cursor-pointer rounded-full border border-border px-5 py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-ink'
>
{t.cancel}
</button>
<button
type='button'
onClick={submit}
disabled={prompt.trim().length < 10}
className='group bg-ink hover:bg-primary inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-full px-5 py-2.5 text-sm font-medium tracking-tight text-background transition-colors disabled:cursor-not-allowed disabled:opacity-50'
className='group inline-flex flex-1 cursor-pointer items-center justify-center gap-2 rounded-full bg-ink px-5 py-2.5 text-sm font-medium tracking-tight text-background transition-colors hover:bg-primary disabled:cursor-not-allowed disabled:opacity-50'
>
<PenLine className='size-4' />
{t.generate}
Expand Down
14 changes: 10 additions & 4 deletions src/features/challenges/hooks/use-socratic-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import { getHintBalance } from '@/features/hints/actions'
import type { ChatMsg } from '@/lib/ai/types'
import { track } from '@/lib/analytics'
import { apiFetch, getAccessToken } from '@/lib/api/client'
import { useT } from '@/lib/i18n'
import * as React from 'react'
import { completeSession, startSession } from '../actions'
import { loadDraft, saveDraft } from '../draft'

const copy = {
en: { buyFailed: "Couldn't start checkout." },
pt: { buyFailed: 'Não foi possível iniciar a compra.' },
}

export function useSocraticSession<TWork>(opts: {
challenge: { id: string } | null
initialWork: TWork
Expand All @@ -18,6 +24,7 @@ export function useSocraticSession<TWork>(opts: {
}) {
const { challenge, initialWork, initialMessages, paused = false } = opts
const { user, loading: authLoading } = useUser()
const t = useT(copy)

const [messages, setMessages] = React.useState<ChatMsg[]>([])
const [input, setInput] = React.useState('')
Expand Down Expand Up @@ -170,8 +177,7 @@ export function useSocraticSession<TWork>(opts: {
text += decoder.decode(value, { stream: true })
patchLast(text)
}
} catch {
}
} catch {}
if (!text.trim() && opts?.fallback) patchLast(opts.fallback)
return text
}
Expand Down Expand Up @@ -212,7 +218,7 @@ export function useSocraticSession<TWork>(opts: {
mock?: boolean
error?: string
}
if (!res.ok) throw new Error(data.error || 'Não foi possível iniciar a compra.')
if (!res.ok) throw new Error(data.error || t.buyFailed)
if (data.url) {
track('checkout_started', { challenge_id: challenge?.id })
window.location.href = data.url
Expand All @@ -226,7 +232,7 @@ export function useSocraticSession<TWork>(opts: {
track('hints_purchased', { remaining: b.remaining })
setTimeout(() => setBought(false), 2500)
} catch (e) {
setBuyError(e instanceof Error ? e.message : '')
setBuyError(e instanceof Error ? e.message : t.buyFailed)
setTimeout(() => setBuyError(null), 5000)
} finally {
buyingRef.current = false
Expand Down
23 changes: 22 additions & 1 deletion src/features/dashboard/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import { computeIndependence } from '@/domain/scoring'
import { authActionUser } from '@/lib/api/guard'
import { supabaseAdmin } from '@/lib/supabase/server'
import {
independenceTrend,
skillBreakdown,
type SkillSession,
} from './independence'
import { calcStreak } from './streak'
import type { Stats } from './types'

Expand Down Expand Up @@ -50,7 +55,7 @@ export async function getDashboardStats(
supabaseAdmin
.from('sessions')
.select(
'id, status, started_at, completed_at, challenge_id, independence',
'id, status, started_at, completed_at, challenge_id, independence, challenges(stack, kind)',
)
.eq('user_id', userId),
supabaseAdmin
Expand Down Expand Up @@ -116,12 +121,28 @@ export async function getDashboardStats(
const streak = calcStreak(completed.map((s) => s.started_at))
const weekProgress = buildWeekProgress(weekSessions.map((s) => s.started_at))

const skillSessions: SkillSession[] = completed.map((s) => {
const challenge = (
s as { challenges: { stack: string; kind: string | null } | null }
).challenges
return {
challengeId: s.challenge_id,
independence:
s.independence ?? computeIndependence(hintsBySession.get(s.id) ?? []),
completedAt: s.completed_at ?? s.started_at,
stack: challenge?.stack ?? null,
kind: challenge?.kind ?? null,
}
})

return {
total_completed: completedCount,
total_hints: totalHints,
avg_hints_per_session: avgHintsPerSession,
independence_score: independenceScore,
streak_days: streak,
week_progress: weekProgress,
skill_breakdown: skillBreakdown(skillSessions),
independence_trend: independenceTrend(skillSessions),
}
}
Loading
Loading