Skip to content

Commit 54bae42

Browse files
committed
refactor: improve code formatting and readability across multiple components
1 parent 6d7c159 commit 54bae42

File tree

6 files changed

+150
-76
lines changed

6 files changed

+150
-76
lines changed

frontend/src/components/CustomScenarioEditor.tsx

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import {
7-
Button,
8-
Dialog,
9-
DialogActions,
10-
DialogBody,
11-
DialogContent,
12-
DialogSurface,
13-
DialogTitle,
14-
DialogTrigger,
15-
Field,
16-
Input,
17-
Text,
18-
Textarea,
19-
makeStyles,
20-
tokens,
7+
Button,
8+
Dialog,
9+
DialogActions,
10+
DialogBody,
11+
DialogContent,
12+
DialogSurface,
13+
DialogTitle,
14+
DialogTrigger,
15+
Field,
16+
Input,
17+
Text,
18+
Textarea,
19+
makeStyles,
20+
tokens,
2121
} from '@fluentui/react-components'
2222
import {
23-
Add24Regular,
24-
ArrowDownload24Regular,
25-
ArrowUpload24Regular,
26-
Delete24Regular,
27-
Edit24Regular,
23+
Add24Regular,
24+
ArrowDownload24Regular,
25+
ArrowUpload24Regular,
26+
Delete24Regular,
27+
Edit24Regular,
2828
} from '@fluentui/react-icons'
2929
import { useRef, useState } from 'react'
3030
import { customScenarioService } from '../services/customScenarios'
@@ -60,7 +60,11 @@ const useStyles = makeStyles({
6060

6161
interface CustomScenarioEditorProps {
6262
scenario?: CustomScenario | null
63-
onSave: (name: string, description: string, scenarioData: CustomScenarioData) => void
63+
onSave: (
64+
name: string,
65+
description: string,
66+
scenarioData: CustomScenarioData
67+
) => void
6468
onDelete?: (id: string) => void
6569
trigger?: React.ReactNode
6670
}
@@ -141,7 +145,7 @@ export function CustomScenarioEditor({
141145
if (!file) return
142146

143147
const reader = new FileReader()
144-
reader.onload = (e) => {
148+
reader.onload = e => {
145149
try {
146150
const content = e.target?.result as string
147151
const data = JSON.parse(content) as CustomScenarioData
@@ -217,12 +221,14 @@ export function CustomScenarioEditor({
217221
</Field>
218222

219223
<Text className={styles.helpText}>
220-
The system prompt defines how the AI will behave during the role-play.
221-
Include character background, behavioral guidelines, and key topics to address.
224+
The system prompt defines how the AI will behave during the
225+
role-play. Include character background, behavioral guidelines,
226+
and key topics to address.
222227
</Text>
223228

224229
<Text className={styles.helpText}>
225-
💾 Custom scenarios are stored locally in your browser and won't sync across devices.
230+
💾 Custom scenarios are stored locally in your browser and won't
231+
sync across devices.
226232
</Text>
227233

228234
{error && <Text className={styles.errorText}>{error}</Text>}

frontend/src/components/ScenarioList.tsx

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import {
1919
import { Edit24Regular } from '@fluentui/react-icons'
2020
import { useState } from 'react'
2121
import { api } from '../services/api'
22-
import { AVATAR_OPTIONS, CustomScenario, CustomScenarioData, DEFAULT_AVATAR, Scenario } from '../types'
22+
import {
23+
AVATAR_OPTIONS,
24+
CustomScenario,
25+
CustomScenarioData,
26+
DEFAULT_AVATAR,
27+
Scenario,
28+
} from '../types'
2329
import { CustomScenarioEditor } from './CustomScenarioEditor'
2430

2531
const useStyles = makeStyles({
@@ -119,8 +125,17 @@ interface Props {
119125
onSelect: (id: string) => void
120126
onStart: (avatarValue: string) => void
121127
onScenarioGenerated?: (scenario: Scenario) => void
122-
onAddCustomScenario: (name: string, description: string, data: CustomScenarioData) => void
123-
onUpdateCustomScenario: (id: string, updates: Partial<Pick<CustomScenario, 'name' | 'description' | 'scenarioData'>>) => void
128+
onAddCustomScenario: (
129+
name: string,
130+
description: string,
131+
data: CustomScenarioData
132+
) => void
133+
onUpdateCustomScenario: (
134+
id: string,
135+
updates: Partial<
136+
Pick<CustomScenario, 'name' | 'description' | 'scenarioData'>
137+
>
138+
) => void
124139
onDeleteCustomScenario: (id: string) => void
125140
}
126141

@@ -170,8 +185,17 @@ export function ScenarioList({
170185
? [...scenarios.filter(s => !s.is_graph_scenario), generatedScenario]
171186
: scenarios
172187

173-
const handleEditCustomScenario = (scenario: CustomScenario, name: string, description: string, data: CustomScenarioData) => {
174-
onUpdateCustomScenario(scenario.id, { name, description, scenarioData: data })
188+
const handleEditCustomScenario = (
189+
scenario: CustomScenario,
190+
name: string,
191+
description: string,
192+
data: CustomScenarioData
193+
) => {
194+
onUpdateCustomScenario(scenario.id, {
195+
name,
196+
description,
197+
scenarioData: data,
198+
})
175199
}
176200

177201
return (
@@ -230,14 +254,13 @@ export function ScenarioList({
230254
<Divider style={{ marginTop: tokens.spacingVerticalL }} />
231255

232256
<div className={styles.sectionHeader}>
233-
<CustomScenarioEditor
234-
onSave={onAddCustomScenario}
235-
/>
257+
<CustomScenarioEditor onSave={onAddCustomScenario} />
236258
</div>
237259

238260
{customScenarios.length === 0 ? (
239261
<Text className={styles.emptyCustom} size={200}>
240-
No custom scenarios yet. Create one to practice with your own role-play situations.
262+
No custom scenarios yet. Create one to practice with your own
263+
role-play situations.
241264
</Text>
242265
) : (
243266
<div className={styles.cardsGrid}>
@@ -251,17 +274,23 @@ export function ScenarioList({
251274
onClick={() => onSelect(scenario.id)}
252275
>
253276
<CardHeader
254-
header={
255-
<Text weight="semibold">
256-
{scenario.name}
257-
</Text>
258-
}
277+
header={<Text weight="semibold">{scenario.name}</Text>}
259278
description={<Text size={200}>{scenario.description}</Text>}
260279
action={
261-
<div className={styles.cardActions} onClick={e => e.stopPropagation()}>
280+
<div
281+
className={styles.cardActions}
282+
onClick={e => e.stopPropagation()}
283+
>
262284
<CustomScenarioEditor
263285
scenario={scenario}
264-
onSave={(name, description, data) => handleEditCustomScenario(scenario, name, description, data)}
286+
onSave={(name, description, data) =>
287+
handleEditCustomScenario(
288+
scenario,
289+
name,
290+
description,
291+
data
292+
)
293+
}
265294
onDelete={onDeleteCustomScenario}
266295
trigger={
267296
<Button
@@ -287,7 +316,10 @@ export function ScenarioList({
287316
<Dropdown
288317
id="avatar-select"
289318
className={styles.avatarDropdown}
290-
value={AVATAR_OPTIONS.find(opt => opt.value === selectedAvatar)?.label || ''}
319+
value={
320+
AVATAR_OPTIONS.find(opt => opt.value === selectedAvatar)?.label ||
321+
''
322+
}
291323
selectedOptions={[selectedAvatar]}
292324
onOptionSelect={(_, data) => {
293325
if (data.optionValue) {

frontend/src/hooks/useScenarios.ts

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,62 @@ export function useScenarios() {
3030
const scenarios: Scenario[] = [...serverScenarios, ...customScenarios]
3131

3232
// Get a specific custom scenario by ID
33-
const getCustomScenario = useCallback((id: string): CustomScenario | null => {
34-
return customScenarios.find(s => s.id === id) || null
35-
}, [customScenarios])
33+
const getCustomScenario = useCallback(
34+
(id: string): CustomScenario | null => {
35+
return customScenarios.find(s => s.id === id) || null
36+
},
37+
[customScenarios]
38+
)
3639

3740
// Add a new custom scenario
38-
const addCustomScenario = useCallback((
39-
name: string,
40-
description: string,
41-
scenarioData: CustomScenarioData
42-
): CustomScenario => {
43-
const newScenario = customScenarioService.save(name, description, scenarioData)
44-
setCustomScenarios(prev => [...prev, newScenario])
45-
return newScenario
46-
}, [])
41+
const addCustomScenario = useCallback(
42+
(
43+
name: string,
44+
description: string,
45+
scenarioData: CustomScenarioData
46+
): CustomScenario => {
47+
const newScenario = customScenarioService.save(
48+
name,
49+
description,
50+
scenarioData
51+
)
52+
setCustomScenarios(prev => [...prev, newScenario])
53+
return newScenario
54+
},
55+
[]
56+
)
4757

4858
// Update a custom scenario
49-
const updateCustomScenario = useCallback((
50-
id: string,
51-
updates: Partial<Pick<CustomScenario, 'name' | 'description' | 'scenarioData'>>
52-
): CustomScenario | null => {
53-
const updated = customScenarioService.update(id, updates)
54-
if (updated) {
55-
setCustomScenarios(prev => prev.map(s => s.id === id ? updated : s))
56-
}
57-
return updated
58-
}, [])
59+
const updateCustomScenario = useCallback(
60+
(
61+
id: string,
62+
updates: Partial<
63+
Pick<CustomScenario, 'name' | 'description' | 'scenarioData'>
64+
>
65+
): CustomScenario | null => {
66+
const updated = customScenarioService.update(id, updates)
67+
if (updated) {
68+
setCustomScenarios(prev => prev.map(s => (s.id === id ? updated : s)))
69+
}
70+
return updated
71+
},
72+
[]
73+
)
5974

6075
// Delete a custom scenario
61-
const deleteCustomScenario = useCallback((id: string): boolean => {
62-
const deleted = customScenarioService.delete(id)
63-
if (deleted) {
64-
setCustomScenarios(prev => prev.filter(s => s.id !== id))
65-
if (selectedScenario === id) {
66-
setSelectedScenario(null)
76+
const deleteCustomScenario = useCallback(
77+
(id: string): boolean => {
78+
const deleted = customScenarioService.delete(id)
79+
if (deleted) {
80+
setCustomScenarios(prev => prev.filter(s => s.id !== id))
81+
if (selectedScenario === id) {
82+
setSelectedScenario(null)
83+
}
6784
}
68-
}
69-
return deleted
70-
}, [selectedScenario])
85+
return deleted
86+
},
87+
[selectedScenario]
88+
)
7189

7290
return {
7391
scenarios,

frontend/src/services/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
* Licensed under the MIT License. See LICENSE in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Assessment, AVATAR_OPTIONS, CustomScenarioData, Scenario } from '../types'
6+
import {
7+
Assessment,
8+
AVATAR_OPTIONS,
9+
CustomScenarioData,
10+
Scenario,
11+
} from '../types'
712

813
export interface AvatarConfig {
914
character: string

frontend/src/services/customScenarios.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export const customScenarioService = {
3636
/**
3737
* Save a new custom scenario
3838
*/
39-
save(name: string, description: string, scenarioData: CustomScenarioData): CustomScenario {
39+
save(
40+
name: string,
41+
description: string,
42+
scenarioData: CustomScenarioData
43+
): CustomScenario {
4044
const scenarios = this.getAll()
4145
const now = new Date().toISOString()
4246
const id = `custom-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`
@@ -59,7 +63,12 @@ export const customScenarioService = {
5963
/**
6064
* Update an existing custom scenario
6165
*/
62-
update(id: string, updates: Partial<Pick<CustomScenario, 'name' | 'description' | 'scenarioData'>>): CustomScenario | null {
66+
update(
67+
id: string,
68+
updates: Partial<
69+
Pick<CustomScenario, 'name' | 'description' | 'scenarioData'>
70+
>
71+
): CustomScenario | null {
6372
const scenarios = this.getAll()
6473
const index = scenarios.findIndex(s => s.id === id)
6574

frontend/src/types/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export interface AvatarOption {
7070
}
7171

7272
export const AVATAR_OPTIONS: AvatarOption[] = [
73-
{ value: 'lisa-casual-sitting', label: 'Lisa (Casual Sitting)', isPhotoAvatar: false },
73+
{
74+
value: 'lisa-casual-sitting',
75+
label: 'Lisa (Casual Sitting)',
76+
isPhotoAvatar: false,
77+
},
7478
{ value: 'riya', label: 'Riya (Photo)', isPhotoAvatar: true },
7579
{ value: 'simone', label: 'Simone (Photo)', isPhotoAvatar: true },
7680
]

0 commit comments

Comments
 (0)