Skip to content

Commit 1065c9a

Browse files
committed
Implement a central event emitter to synchronize checkpoint updates across the application and update the revert-last translation and date formatting
- when reverting last restored checkpoint from `apps/editor/src/commands/checkpoints-command.ts`, panel UI is not updated. Should use event emitter. - the checkpionts quick pick should not use relative time
1 parent d1ba216 commit 1065c9a

5 files changed

Lines changed: 40 additions & 27 deletions

File tree

apps/editor/src/commands/checkpoints-command.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '../constants/state-keys'
66
import { WorkspaceProvider } from '../context/providers/workspace/workspace-provider'
77
import dayjs from 'dayjs'
8-
import relativeTime from 'dayjs/plugin/relativeTime'
8+
import localizedFormat from 'dayjs/plugin/localizedFormat'
99
import { t } from '@/i18n'
1010
import type { Checkpoint } from '@/features/checkpoints/types'
1111
import {
@@ -21,8 +21,9 @@ import {
2121
import { PanelProvider } from '@/views/panel/backend/panel-provider'
2222
import { get_checkpoint_path } from '@/features/checkpoints/utils'
2323
import { dictionary } from '@shared/constants/dictionary'
24+
import { checkpoints_emitter } from '@/features/checkpoints/events'
2425

25-
dayjs.extend(relativeTime)
26+
dayjs.extend(localizedFormat)
2627

2728
export type { Checkpoint } from '@/features/checkpoints/types'
2829

@@ -132,7 +133,7 @@ export const checkpoints_command = (params: {
132133
return {
133134
id: c.timestamp.toString(),
134135
label: c.is_starred ? `$(star-full) ${labelText}` : labelText,
135-
description: dayjs(c.timestamp).fromNow(),
136+
description: dayjs(c.timestamp).format('LT'),
136137
detail: c.description,
137138
checkpoint: c,
138139
index,
@@ -258,15 +259,16 @@ export const checkpoints_command = (params: {
258259
panel_provider: params.panel_provider
259260
})
260261
// After reverting, delete the temp checkpoint and clear state.
262+
await params.context.workspaceState.update(
263+
TEMPORARY_CHECKPOINT_STATE_KEY,
264+
undefined
265+
)
261266
await delete_checkpoint({
262267
context: params.context,
263268
checkpoint_to_delete: temp_checkpoint,
264269
panel_provider: params.panel_provider
265270
})
266-
await params.context.workspaceState.update(
267-
TEMPORARY_CHECKPOINT_STATE_KEY,
268-
undefined
269-
)
271+
checkpoints_emitter.emit('checkpoints-updated')
270272
} else if (selected.checkpoint) {
271273
quick_pick.hide()
272274
await restore_checkpoint({

apps/editor/src/features/checkpoints/actions/restore-checkpoint.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ongoing_preview_cleanup_promise } from '@/commands/apply-chat-response-
2222
import { dictionary } from '@shared/constants/dictionary'
2323
import { get_git_info } from '../utils/git-utils'
2424
import { PromptsForCommitMessagesUtils } from '@/utils/prompts-for-commit-messages-utils'
25+
import { checkpoints_emitter } from '../events'
2526

2627
export const restore_checkpoint = async (params: {
2728
checkpoint: Checkpoint
@@ -562,6 +563,7 @@ export const restore_checkpoint = async (params: {
562563
command: 'HIDE_PROGRESS'
563564
})
564565
}
566+
checkpoints_emitter.emit('checkpoints-updated')
565567
}
566568

567569
const message = params.options?.skip_confirmation
@@ -591,15 +593,16 @@ export const restore_checkpoint = async (params: {
591593
panel_provider: params.panel_provider,
592594
options: { skip_confirmation: true, use_native_progress: true }
593595
})
596+
await params.context.workspaceState.update(
597+
TEMPORARY_CHECKPOINT_STATE_KEY,
598+
undefined
599+
)
594600
await delete_checkpoint({
595601
context: params.context,
596602
checkpoint_to_delete: temp_check,
597603
panel_provider: params.panel_provider
598604
})
599-
await params.context.workspaceState.update(
600-
TEMPORARY_CHECKPOINT_STATE_KEY,
601-
undefined
602-
)
605+
checkpoints_emitter.emit('checkpoints-updated')
603606
}
604607
} else {
605608
vscode.window.showInformationMessage(message)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { EventEmitter } from 'events'
2+
3+
export const checkpoints_emitter = new EventEmitter()

apps/editor/src/i18n/translations/commands/checkpoints.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ export const translations = {
5454
bg: 'Изчистване на всички контролни точки'
5555
},
5656
'command.checkpoints.revert-last': {
57-
en: 'Revert to before last chat change',
58-
pl: 'Przywróć do stanu przed ostatnią zmianą w czacie',
59-
'zh-cn': '还原至最后一次聊天更改之前',
60-
ja: '最後のチャットの変更前を元に戻す',
61-
'zh-tw': '還原至最後一次聊天變更之前',
62-
de: 'Zurücksetzen vor der letzten Chat-Änderung',
63-
es: 'Revertir antes del último cambio de chat',
64-
fr: 'Revenir avant le dernier changement de chat',
65-
'pt-br': 'Reverter para antes da última alteração no chat',
66-
ru: 'Вернуться к состоянию до последнего изменения в чате',
67-
ko: '마지막 채팅 변경 전으로 되돌리기',
68-
it: "Ripristina prima dell'ultima modifica della chat",
69-
tr: 'Son sohbet değişikliğinden öncesine dön',
70-
cs: 'Vrátit se před poslední změnu chatu',
71-
hu: 'Visszatérés a legutóbbi csevegési változtatás elé',
72-
bg: 'Връщане преди последната промяна в чата'
57+
en: 'Revert last restored checkpoint',
58+
pl: 'Cofnij ostatnie przywrócenie',
59+
'zh-cn': '撤销上次恢复',
60+
ja: '最後の復元を元に戻す',
61+
'zh-tw': '撤銷上次還原',
62+
de: 'Wiederherstellung rückgängig machen',
63+
es: 'Deshacer última restauración',
64+
fr: 'Annuler la dernière restauration',
65+
'pt-br': 'Desfazer última restauração',
66+
ru: 'Отменить последнее восстановление',
67+
ko: '마지막 복원 취소',
68+
it: 'Annulla ultimo ripristino',
69+
tr: 'Son geri yüklemeyi geri al',
70+
cs: 'Vrátit poslední obnovení',
71+
hu: 'Visszaállítás visszavonása',
72+
bg: 'Отмяна на възстановяването'
7373
},
7474
'command.checkpoints.new': {
7575
en: 'Create New Checkpoint',

apps/editor/src/views/panel/backend/panel-provider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ import { ModelProvidersManager } from '@/services/model-providers-manager'
135135
import { SharedContextState } from '@/context/shared-context-state'
136136
import { Checkpoint } from '@/features/checkpoints/types'
137137
import { webview_html } from '@/views/shared/utils/webview-html'
138+
import { checkpoints_emitter } from '@/features/checkpoints/events'
138139

139140
export class PanelProvider implements vscode.WebviewViewProvider {
140141
public readonly extension_uri: vscode.Uri
@@ -531,6 +532,10 @@ export class PanelProvider implements vscode.WebviewViewProvider {
531532
}
532533
})
533534

535+
checkpoints_emitter.on('checkpoints-updated', () => {
536+
this.send_checkpoints()
537+
})
538+
534539
this.context.subscriptions.push(this._config_listener)
535540

536541
const update_editor_state = () => {

0 commit comments

Comments
 (0)