-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MOC-56] waiting until update finishes before showing rec list #70
Changes from 7 commits
5274d5c
68c41b7
97abe78
fb61a03
64ff21a
6317e68
807175d
701f74c
3aad6fd
059e284
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,18 +25,22 @@ const EditToast = ({ state, onChangeState }: EditToastProps) => { | |||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const handleClose = async () => { | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
const recordingId = await loadRecordingId(); | ||||||||||||||||||||||||||||||
setEditorMode(false, recordingId); | ||||||||||||||||||||||||||||||
await setEditorMode(false, recordingId); | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||
<Toast className={"mt-3 min-w-64 p-3 flex flex-row items-center gap-6"}> | ||||||||||||||||||||||||||||||
<div | ||||||||||||||||||||||||||||||
className="cursor-pointer" | ||||||||||||||||||||||||||||||
onClick={handleClose} | ||||||||||||||||||||||||||||||
onClick={() => { | ||||||||||||||||||||||||||||||
setEditorMode(false); | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor to remove redundant code. The + const resetEditorAndChangeState = async () => {
+ try {
+ await setEditorMode(false);
+ onChangeState(RecordingState.CREATE);
+ } catch (error) {
+ console.error('Error resetting editor and changing state:', error);
+ }
+ };
- onClick={() => {
- setEditorMode(false);
- onChangeState(RecordingState.CREATE);
- }}
+ onClick={resetEditorAndChangeState} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
onKeyUp={async (event) => { | ||||||||||||||||||||||||||||||
if (event.key === "Escape") { | ||||||||||||||||||||||||||||||
handleClose(); | ||||||||||||||||||||||||||||||
setEditorMode(false); | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||
|
@@ -59,15 +63,15 @@ const EditToast = ({ state, onChangeState }: EditToastProps) => { | |||||||||||||||||||||||||||||
<div | ||||||||||||||||||||||||||||||
className="cursor-pointer text-[#009875]" | ||||||||||||||||||||||||||||||
onClick={async () => { | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
const recordingId = await loadRecordingId(); | ||||||||||||||||||||||||||||||
setEditorMode(false, recordingId); | ||||||||||||||||||||||||||||||
await setEditorMode(false, recordingId); | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistent error handling and refactoring suggestion. This |
||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||
onKeyUp={async (event) => { | ||||||||||||||||||||||||||||||
if (event.key === "Enter") { | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
const recordingId = await loadRecordingId(); | ||||||||||||||||||||||||||||||
setEditorMode(false, recordingId); | ||||||||||||||||||||||||||||||
await setEditorMode(false, recordingId); | ||||||||||||||||||||||||||||||
onChangeState(RecordingState.CREATE); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistent error handling and refactoring suggestion. The |
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,12 +74,17 @@ export const saveModification = ( | |
saveModificationCommand.execute(); | ||
}; | ||
|
||
export const persistModifications = (recordingId: string) => { | ||
export const persistModifications = async (recordingId: string) => { | ||
const alterations: Alteration[] = buildAlterations(domainModifications); | ||
chrome.storage.local.set({ | ||
[MOCKSI_MODIFICATIONS]: JSON.stringify(domainModifications), | ||
}); | ||
const updated_timestamp = new Date(); | ||
await updateRecordingsStorage({ | ||
uuid: recordingId, | ||
updated_timestamp, | ||
alterations, | ||
}); | ||
sendMessage("updateDemo", { | ||
id: recordingId, | ||
recording: { updated_timestamp, alterations }, | ||
|
@@ -274,6 +279,29 @@ export const getRecordingsStorage = async (): Promise<Recording[]> => { | |
} | ||
}; | ||
|
||
export const updateRecordingsStorage = async ({ | ||
uuid, | ||
updated_timestamp, | ||
alterations, | ||
}: { uuid: string; updated_timestamp: Date; alterations: Alteration[] }) => { | ||
try { | ||
const recordingsFromStorage = await getRecordingsStorage(); | ||
const modifiedRecordings = recordingsFromStorage.map((recording) => | ||
recording.uuid === uuid | ||
? { ...recording, uuid, updated_timestamp, alterations } | ||
: recording, | ||
); | ||
const sorted = modifiedRecordings.sort((a: Recording, b: Recording) => | ||
a.updated_timestamp > b.updated_timestamp ? -1 : 0, | ||
); | ||
const recordingsStringified = JSON.stringify(sorted); | ||
console.log("modified", recordingsFromStorage, sorted); | ||
chrome.storage.local.set({ recordings: recordingsStringified }); | ||
} catch (err) { | ||
console.error("Failed to save modifications from LS:", err); | ||
throw err; | ||
} | ||
}; | ||
Comment on lines
+282
to
+304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Unit tests for The search results indicate that the
Analysis chainNew Feature: Added This addition is significant as it centralizes the logic for updating recordings in storage, which can improve maintainability and testing. The function also handles errors robustly, which is crucial for reliability. Ensure that this function is covered by unit tests to verify its behavior under various scenarios. Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Verify if unit tests cover the new `updateRecordingsStorage` function.
rg --type typescript -g '*test.ts' 'updateRecordingsStorage'
Length of output: 95 Script: #!/bin/bash
# Verify if unit tests cover the new `updateRecordingsStorage` function.
rg --type ts -g '*test.ts' 'updateRecordingsStorage'
Length of output: 52 Script: #!/bin/bash
# Find all test files in the repository
fd --type f --extension ts --exec rg 'updateRecordingsStorage' {}
Length of output: 148 Script: #!/bin/bash
# Find all test files in the repository and their occurrences of `updateRecordingsStorage`
fd --type f --extension ts --exec rg --with-filename --line-number 'updateRecordingsStorage' {}
Length of output: 241 |
||
export const loadRecordingId = async () => { | ||
return new Promise<string | undefined>((resolve) => { | ||
chrome.storage.local.get([MOCKSI_RECORDING_ID], (result) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling in asynchronous calls.
The
handleClose
function now awaits thesetEditorMode
before changing the recording state. This is a good change for ensuring the sequence of operations, but it's crucial to handle potential errors that might arise from these asynchronous operations to prevent the UI from being in an inconsistent state.Committable suggestion