Skip to content

Commit

Permalink
refactor: save progress continue GM
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Nov 9, 2023
1 parent 5d295da commit 491d69e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
4 changes: 4 additions & 0 deletions src/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ if (process.contextIsolated) {
isFile: async (filepath) => {
const fsStatsObj = await fs.stat(filepath);
return fsStatsObj.isFile();
},
readFile: async (filepath, encoding) => {
let result = await fs.readFile(filepath, encoding)
return JSON.parse(result)
}
})
contextBridge.exposeInMainWorld('process', {
Expand Down
32 changes: 10 additions & 22 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import lottie from "lottie-web"
import {dragDrop} from '../../assets/lotties/lotties'
import Swal from "sweetalert2"
import Tagify from "@yaireo/tagify";
import tippy from "tippy.js";
import DragSort from '@yaireo/dragsort'
import 'jstree'

Expand Down Expand Up @@ -2591,7 +2592,7 @@ for (const infoDropdown of Array.from(infoDropdowns)) {
});
}

const guidedSaveAndExit = async () => {
window.guidedSaveAndExit = async () => {
if (!window.sodaJSONObj["digital-metadata"]["name"]) {
// If a progress file has not been created, then we don't need to save anything
guidedTransitionToHome();
Expand Down Expand Up @@ -2855,27 +2856,13 @@ const saveGuidedProgress = async (guidedProgressFileName) => {
};

const readDirAsync = async (path) => {
return new Promise((resolve, reject) => {
window.fs.readdir(path, (error, result) => {
if (error) {
throw new Error(error);
} else {
resolve(result);
}
});
});
let result = await window.fs.readdir(path)
return result
};

const readFileAsync = async (path) => {
return new Promise((resolve, reject) => {
window.fs.readFile(path, "utf-8", (error, result) => {
if (error) {
throw new Error(error);
} else {
resolve(JSON.parse(result));
}
});
});
let result = await window.fs.readFile(path, "utf-8")
return result
};

const getAllProgressFileData = async (progressFiles) => {
Expand Down Expand Up @@ -3025,7 +3012,7 @@ const generateProgressCardElement = (progressFileJSONObj) => {
return `
<button
class="ui positive button ${buttonClass}"
onClick="guidedResumeProgress('${progressFileName}')"
onClick="window.guidedResumeProgress('${progressFileName}')"
>
${buttonText}
</button>
Expand Down Expand Up @@ -3101,6 +3088,7 @@ const generateProgressCardElement = (progressFileJSONObj) => {
};

const guidedRenderProgressCards = async () => {
console.log("Loading the render progress cards func")
const progressCardsContainer = document.getElementById("guided-container-progress-cards");
const progressCardLoadingDiv = document.getElementById("guided-section-loading-progress-cards");

Expand Down Expand Up @@ -7461,7 +7449,7 @@ const patchPreviousGuidedModeVersions = async () => {
};

//Loads UI when continue curation button is pressed
const guidedResumeProgress = async (datasetNameToResume) => {
window.guidedResumeProgress = async (datasetNameToResume) => {
const loadingSwal = Swal.fire({
title: "Resuming where you last left off",
html: `
Expand Down Expand Up @@ -14715,7 +14703,7 @@ $("#guided-back-button").on("click", async () => {
// If the target page when clicking the back button does not exist, then we are on the first not skipped page.
// In this case, we want to save and exit guided mode.
if (!targetPage) {
await guidedSaveAndExit();
await window.guidedSaveAndExit();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5833,7 +5833,7 @@ <h5 class="guided--dataset-description">Review status:</h5>
class="ui secondary basic button save-and-exit-button"
id="guided-button-save-and-exit"
style="width: 200px !important; font-family: Poppins"
onclick="guidedSaveAndExit()"
onclick="window.guidedSaveAndExit()"
>
<i class="far fa-save" style="margin-right: 10px"></i>
Save and Exit
Expand Down Expand Up @@ -5861,7 +5861,7 @@ <h5 class="guided--dataset-description">Review status:</h5>
class="ui secondary basic button save-and-exit-button"
id="guided-button-sub-page-save-and-exit"
style="width: 165px !important; font-family: Poppins"
onclick="guidedSaveAndExit()"
onclick="window.guidedSaveAndExit()"
>
<i class="far fa-save" style="margin-right: 10px"></i>
Save and Exit
Expand Down

0 comments on commit 491d69e

Please sign in to comment.