Skip to content

Commit a6f9f05

Browse files
committed
Translate the revert last checkpoint command and improve task editing behavior to prevent accidental deletion of tasks with content
- when editing task, focus-out should remove it (if it doesnt have any children) - when task is saved but the value was removed, restore it as we don't allow empty tasks. - fix [Fragment] - fix [Pasted text], make sure translations are quite concise as it is used in tooltip - fix [Pasted text], make sure translations are quite concise as it is used in tooltip
1 parent dde372d commit a6f9f05

4 files changed

Lines changed: 56 additions & 12 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export const Home: React.FC<Props> = (props) => {
197197
{props.has_temp_checkpoint && (
198198
<UiIconButton
199199
codicon_icon="discard"
200-
title={'command.checkpoints.revert-last'}
200+
title={t('command.checkpoints.revert-last')}
201201
on_click={(e) => {
202202
e.stopPropagation()
203203
props.on_restore_temp_checkpoint()

‎apps/editor/src/views/panel/frontend/i18n/translations/checkpoints.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,24 @@ export const checkpoints = {
160160
cs: 'Před obnovením kontrolního bodu',
161161
hu: 'Ellenőrzőpont visszaállítása előtt',
162162
bg: 'Преди възстановяване на контролна точка'
163+
},
164+
'command.checkpoints.revert-last': {
165+
en: 'Revert last restored checkpoint',
166+
pl: 'Cofnij ostatnie przywrócenie',
167+
'zh-cn': '撤销上次恢复',
168+
ja: '最後の復元を元に戻す',
169+
'zh-tw': '撤銷上次還原',
170+
de: 'Wiederherstellung rückgängig machen',
171+
es: 'Deshacer última restauración',
172+
fr: 'Annuler la dernière restauration',
173+
'pt-br': 'Desfazer última restauração',
174+
ru: 'Отменить последнее восстановление',
175+
ko: '마지막 복원 취소',
176+
it: 'Annulla ultimo ripristino',
177+
tr: 'Son geri yüklemeyi geri al',
178+
cs: 'Vrátit poslední obnovení',
179+
hu: 'Visszaállítás visszavonása',
180+
bg: 'Отмяна на възстановяването'
163181
}
164182
} as const
183+

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,35 @@ export const Tasks: React.FC<Props> = (props) => {
5858
const [editing_timestamp, set_editing_timestamp] = useState<number | null>(
5959
null
6060
)
61+
const [editing_initial_text, set_editing_initial_text] = useState<string>('')
6162
const [forwarded_timestamp, set_forwarded_timestamp] = useState<
6263
number | null
6364
>(null)
6465
const [copied_timestamp, set_copied_timestamp] = useState<number | null>(null)
6566
const prevent_edit_ref = useRef(false)
6667

67-
use_auto_focus_new_task(props.tasks, set_editing_timestamp)
68+
const handle_set_editing = (timestamp: number | null, text?: string) => {
69+
set_editing_timestamp(timestamp)
70+
if (text !== undefined) {
71+
set_editing_initial_text(text)
72+
}
73+
}
74+
75+
use_auto_focus_new_task(props.tasks, handle_set_editing)
76+
77+
const handle_stop_editing = (task: Task) => {
78+
if (editing_timestamp !== task.created_at) return
79+
set_editing_timestamp(null)
80+
if (!task.text.trim()) {
81+
const has_children = task.children && task.children.length > 0
82+
if (!editing_initial_text.trim() && !has_children) {
83+
props.on_delete(task.created_at)
84+
} else if (editing_initial_text.trim()) {
85+
const { id, ...rest } = task as any
86+
props.on_change({ ...rest, text: editing_initial_text })
87+
}
88+
}
89+
}
6890

6991
const tree = useMemo(() => add_ids(props.tasks), [props.tasks])
7092

@@ -200,11 +222,13 @@ export const Tasks: React.FC<Props> = (props) => {
200222
on_mouse_down={
201223
is_editing ? (e) => e.preventDefault() : undefined
202224
}
203-
on_click={() =>
204-
set_editing_timestamp(
205-
is_editing ? null : params.task.created_at
206-
)
207-
}
225+
on_click={() => {
226+
if (is_editing) {
227+
handle_stop_editing(params.task)
228+
} else {
229+
handle_set_editing(params.task.created_at, params.task.text)
230+
}
231+
}}
208232
title={is_editing ? 'Done' : 'Edit'}
209233
/>
210234
<IconButton
@@ -226,11 +250,12 @@ export const Tasks: React.FC<Props> = (props) => {
226250
props.on_change({ ...rest, text: value })
227251
}}
228252
autofocus
229-
on_blur={() => set_editing_timestamp(null)}
253+
on_blur={() => {
254+
handle_stop_editing(params.task)
255+
}}
230256
on_key_down={(e) => {
231257
if (e.key == 'Enter' && !e.shiftKey) {
232258
e.preventDefault()
233-
set_editing_timestamp(null)
234259
}
235260
}}
236261
/>
@@ -253,7 +278,7 @@ export const Tasks: React.FC<Props> = (props) => {
253278
}}
254279
onClick={() => {
255280
if (prevent_edit_ref.current) return
256-
set_editing_timestamp(params.task.created_at)
281+
handle_set_editing(params.task.created_at, params.task.text)
257282
}}
258283
>
259284
{params.task.text || props.placeholder}

‎packages/ui/src/components/editor/panel/Tasks/hooks/use-auto-focus-new-task.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Task } from '@shared/types/task'
33

44
export const use_auto_focus_new_task = (
55
tasks: Task[],
6-
set_editing_timestamp: (timestamp: number | null) => void
6+
set_editing_timestamp: (timestamp: number | null, text?: string) => void
77
) => {
88
const prev_ids_ref = useRef<Set<number>>(new Set())
99
const is_first_render = useRef(true)
@@ -34,7 +34,7 @@ export const use_auto_focus_new_task = (
3434
if (added_ids.length == 1) {
3535
const new_task = id_to_task.get(added_ids[0])
3636
if (new_task && new_task.text == '') {
37-
set_editing_timestamp(added_ids[0])
37+
set_editing_timestamp(added_ids[0], '')
3838
}
3939
}
4040

0 commit comments

Comments
 (0)