fix: set format after error

This commit is contained in:
AykutSarac 2023-06-19 19:38:58 +03:00
parent c281b232df
commit b874fbef30
No known key found for this signature in database

View File

@ -100,11 +100,12 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
try {
const contentJson = await contentToJson(get().contents, get().format);
const jsonContent = await jsonToContent(JSON.stringify(contentJson, null, 2), format);
set({ format });
get().setContents({ contents: jsonContent, hasChanges: false });
} catch (error) {
get().clear();
console.info("The content was unable to be converted, so it was cleared instead.");
} finally {
set({ format });
}
},
setContents: async ({ contents, hasChanges = true, skipUpdate = false }) => {