Skip to content

Commit 95f1c0f

Browse files
committed
Update tasks component and home view to support customizable add new text via translations
- when there are no tasks, should show the 'new' item that appears at the very end when there are some tasks. remove text 'No tasks created yet.' - should show text 'Add new...' on the 'add' item (next to plus icon) - Tasks should use translations prop ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ ├── Home │ │ └── Home.tsx │ └── i18n │ └── translations │ └── home.ts └── packages └── ui └── src └── components └── editor └── prompt ├── Configurations │ └── Configurations.tsx └── Tasks ├── Tasks.module.scss ├── Tasks.stories.tsx ├── Tasks.tsx ├── components │ └── TaskGroup.tsx ├── hooks │ └── use-auto-focus-new-task.ts └── index.ts
1 parent bd8b4ad commit 95f1c0f

8 files changed

Lines changed: 92 additions & 75 deletions

File tree

‎apps/editor/src/views/prompt/frontend/Home/Home.module.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
&__left {
3333
display: flex;
3434
align-items: center;
35-
gap: 6px;
35+
gap: 7px;
3636
}
3737

3838
&__right {

‎apps/editor/src/views/prompt/frontend/Home/Home.tsx‎

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const Home: React.FC<Props> = (props) => {
6161
const active_root =
6262
active_workspace_root && roots.includes(active_workspace_root)
6363
? active_workspace_root
64-
: roots[0]
64+
: roots[0] || active_workspace_root || ''
6565

6666
const { container_ref, compact_step } = use_compacting()
6767

@@ -277,46 +277,38 @@ export const Home: React.FC<Props> = (props) => {
277277

278278
<UiSeparator height={4} />
279279

280-
{roots.length == 0 && (
281-
<div className={styles.inner__empty}>{t('home.tasks.empty')}</div>
282-
)}
283-
{active_root && (
284-
<div className={styles.inner__tasks}>
285-
{tasks[active_root].length == 0 ? (
286-
<div className={styles.inner__empty}>
287-
{t('home.tasks.empty')}
288-
</div>
289-
) : (
290-
<UiTasks
291-
tasks={tasks[active_root]}
292-
on_reorder={(new_tasks) =>
293-
handle_reorder(active_root, new_tasks)
294-
}
295-
on_change={(updated_task) => {
296-
handle_change(
297-
active_root,
298-
tasks[active_root],
299-
updated_task
300-
)
301-
}}
302-
on_add={() => {
303-
handle_add(active_root, tasks[active_root])
304-
}}
305-
on_add_subtask={(parent_task) => {
306-
handle_add_subtask(
307-
active_root,
308-
tasks[active_root],
309-
parent_task
310-
)
311-
}}
312-
on_delete={(timestamp) => {
313-
handle_delete(active_root, timestamp)
314-
}}
315-
placeholder={t('home.tasks.placeholder')}
316-
/>
317-
)}
318-
</div>
319-
)}
280+
<div className={styles.inner__tasks}>
281+
<UiTasks
282+
tasks={tasks[active_root] || []}
283+
on_reorder={(new_tasks) =>
284+
handle_reorder(active_root, new_tasks)
285+
}
286+
on_change={(updated_task) => {
287+
handle_change(
288+
active_root,
289+
tasks[active_root] || [],
290+
updated_task
291+
)
292+
}}
293+
on_add={() => {
294+
handle_add(active_root, tasks[active_root] || [])
295+
}}
296+
on_add_subtask={(parent_task) => {
297+
handle_add_subtask(
298+
active_root,
299+
tasks[active_root] || [],
300+
parent_task
301+
)
302+
}}
303+
on_delete={(timestamp) => {
304+
handle_delete(active_root, timestamp)
305+
}}
306+
translations={{
307+
placeholder: t('home.tasks.placeholder'),
308+
add_new: t('home.tasks.add-new')
309+
}}
310+
/>
311+
</div>
320312
</div>
321313

322314
<div className={styles['bottom-wrapper']}>

‎apps/editor/src/views/prompt/frontend/i18n/translations/home.ts‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,6 @@ export const home = {
1717
hu: 'Feladatok',
1818
bg: 'Задачи'
1919
},
20-
'home.tasks.empty': {
21-
en: 'No tasks created yet.',
22-
pl: 'Nie utworzono jeszcze żadnych zadań.',
23-
'zh-cn': '尚未创建任务。',
24-
ja: 'まだタスクは作成されていません。',
25-
'zh-tw': '尚未建立任務。',
26-
de: 'Noch keine Aufgaben erstellt.',
27-
es: 'Aún no se han creado tareas.',
28-
fr: 'Aucune tâche créée pour le moment.',
29-
'pt-br': 'Nenhuma tarefa criada ainda.',
30-
ru: 'Задачи еще не созданы.',
31-
ko: '아직 생성된 작업이 없습니다.',
32-
it: 'Nessuna attività ancora creata.',
33-
tr: 'Henüz görev oluşturulmadı.',
34-
cs: 'Zatím nebyly vytvořeny žádné úkoly.',
35-
hu: 'Még nincsenek feladatok létrehozva.',
36-
bg: 'Все още няма създадени задачи.'
37-
},
3820
'home.tasks.add': {
3921
en: 'Add Task',
4022
pl: 'Dodaj zadanie',
@@ -53,6 +35,24 @@ export const home = {
5335
hu: 'Feladat hozzáadása',
5436
bg: 'Добавяне на задача'
5537
},
38+
'home.tasks.add-new': {
39+
en: 'Add new...',
40+
pl: 'Dodaj nowe...',
41+
'zh-cn': '添加新...',
42+
ja: '新しく追加...',
43+
'zh-tw': '新增...',
44+
de: 'Neu hinzufügen...',
45+
es: 'Añadir nuevo...',
46+
fr: 'Ajouter nouveau...',
47+
'pt-br': 'Adicionar novo...',
48+
ru: 'Добавить новое...',
49+
ko: '새로 추가...',
50+
it: 'Aggiungi nuovo...',
51+
tr: 'Yeni ekle...',
52+
cs: 'Přidat nové...',
53+
hu: 'Új hozzáadása...',
54+
bg: 'Добавяне на ново...'
55+
},
5656
'home.tasks.placeholder': {
5757
en: 'Click to add text...',
5858
pl: 'Kliknij, aby dodać tekst...',

‎packages/ui/src/components/editor/prompt/Configurations/Configurations.module.scss‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@
115115
}
116116

117117
.empty {
118-
padding: 0 16px 0 38px;
118+
padding: 0 16px;
119119
color: var(--cwc-text-color-dimmed);
120120

121121
:global([data-modern-ui='true']) & {
122-
padding: 0 12px 0 34px;
122+
padding: 0 12px;
123123
}
124124
}
125125

‎packages/ui/src/components/editor/prompt/Tasks/Tasks.module.scss‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@
167167
.add-row {
168168
position: relative;
169169
display: flex;
170+
align-items: center;
171+
cursor: pointer;
170172

171173
:global([data-modern-ui='true']) & {
172174
margin: 0 4px;
@@ -196,3 +198,9 @@
196198
);
197199
pointer-events: none;
198200
}
201+
202+
.add-text {
203+
color: var(--cwc-text-color-dimmed);
204+
margin-left: 6px;
205+
user-select: none;
206+
}

‎packages/ui/src/components/editor/prompt/Tasks/Tasks.stories.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ export const Default = () => {
151151
on_add={handle_add}
152152
on_add_subtask={handle_add_subtask}
153153
on_delete={handle_delete}
154-
placeholder="Click to add text..."
154+
translations={{
155+
placeholder: 'Click to add text...',
156+
add_new: 'Add new...'
157+
}}
155158
/>
156159
</div>
157160
)
@@ -178,7 +181,10 @@ export const NoReorder = () => {
178181
on_add={() => {}}
179182
on_add_subtask={() => {}}
180183
on_delete={() => {}}
181-
placeholder="Click to add text..."
184+
translations={{
185+
placeholder: 'Click to add text...',
186+
add_new: 'Add new...'
187+
}}
182188
/>
183189
</div>
184190
)

‎packages/ui/src/components/editor/prompt/Tasks/Tasks.tsx‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ import { use_auto_focus_new_task } from './hooks/use-auto-focus-new-task'
1414

1515
dayjs.extend(relativeTime)
1616

17-
type Props = {
18-
tasks: Task[]
19-
on_reorder: (tasks: Task[]) => void
20-
on_change: (task: Task) => void
21-
on_add: () => void
22-
on_add_subtask?: (parent_task: Task) => void
23-
on_delete: (created_at: number) => void
24-
placeholder: string
17+
export namespace Tasks {
18+
export type Props = {
19+
tasks: Task[]
20+
on_reorder: (tasks: Task[]) => void
21+
on_change: (task: Task) => void
22+
on_add: () => void
23+
on_add_subtask?: (parent_task: Task) => void
24+
on_delete: (created_at: number) => void
25+
translations: {
26+
placeholder: string
27+
add_new: string
28+
}
29+
}
2530
}
2631

2732
const add_ids = (tasks: Task[]): SortableTask[] => {
@@ -51,7 +56,7 @@ const get_structure_signature = (tasks: Task[]): string => {
5156
.join(',')
5257
}
5358

54-
export const Tasks: React.FC<Props> = (props) => {
59+
export const Tasks: React.FC<Tasks.Props> = (props) => {
5560
use_periodic_re_render(60 * 1000)
5661
use_dayjs_locale()
5762
const [editing_timestamp, set_editing_timestamp] = useState<number | null>(
@@ -277,7 +282,7 @@ export const Tasks: React.FC<Props> = (props) => {
277282
handle_set_editing(params.task.created_at, params.task.text)
278283
}}
279284
>
280-
{params.task.text || props.placeholder}
285+
{params.task.text || props.translations.placeholder}
281286
</div>
282287
)}
283288
</div>
@@ -294,6 +299,7 @@ export const Tasks: React.FC<Props> = (props) => {
294299
className={styles.tasks}
295300
on_add={props.on_add}
296301
get_on_add_subtask={(parent) => () => props.on_add_subtask?.(parent)}
302+
add_text={props.translations.add_new}
297303
/>
298304
</div>
299305
)

‎packages/ui/src/components/editor/prompt/Tasks/components/TaskGroup.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type TaskGroupProps = {
2222
get_on_add_subtask?: (parent: Task) => () => void
2323
parent_checked?: boolean
2424
depth?: number
25+
add_text?: string
2526
}
2627

2728
export const TaskGroup: React.FC<TaskGroupProps> = (props) => {
@@ -72,6 +73,7 @@ export const TaskGroup: React.FC<TaskGroupProps> = (props) => {
7273
get_on_add_subtask={props.get_on_add_subtask}
7374
parent_checked={is_visually_checked}
7475
depth={depth + 1}
76+
add_text={props.add_text}
7577
/>
7678
)}
7779
</div>
@@ -98,8 +100,11 @@ export const TaskGroup: React.FC<TaskGroupProps> = (props) => {
98100
depth * 20
99101
}px)`
100102
}}
101-
title="Add task"
103+
title={props.add_text || 'Add task'}
102104
/>
105+
{props.add_text && (
106+
<span className={styles['add-text']}>{props.add_text}</span>
107+
)}
103108
</div>
104109
)}
105110
</>

0 commit comments

Comments
 (0)