Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dependencies": {
"firebase": "^11.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"uuid": "^11.1.0"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
Expand Down
11 changes: 11 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@
overflow-y: auto;
}

textarea {
width: 450px;
height: 300px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 13px;
resize: none;
}

.logBox {
display: flex;
justify-content: space-between;
Expand Down
39 changes: 35 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useEffect, useState } from "react";
import { v4 as uuidv4 } from 'uuid';
import "./App.css";
import { getResultPath, getLocationDict, getDocById, getFirebaseRecipe, getJobStatus } from "./firebase";
import { getResultPath, getLocationDict, getDocById, getFirebaseRecipe, getJobStatus, updateRecipe } from "./firebase";
import {
getSubmitPackingUrl,
JobStatus,
} from "./constants/awsBatch";
import {
FIRESTORE_COLLECTIONS
FIRESTORE_COLLECTIONS,
FIRESTORE_FIELDS,
} from "./constants/firebaseConstants";
import { SIMULARIUM_EMBED_URL } from "./constants/urls";
import {
Expand Down Expand Up @@ -36,11 +38,40 @@ function App() {
return new Promise((resolve) => setTimeout(resolve, ms));
};

const recipeHasChanged = async (): Promise<boolean> => {
const originalRecipe = await getFirebaseRecipe(selectedRecipe);
return !(originalRecipe == recipeStr);
}

const recipeToFirebase = (recipe: string, path: string): object => {
const recipeJson = JSON.parse(recipe);
if (recipeJson.bounding_box) {
let flattened_array = Object.assign({}, recipeJson.bounding_box);
recipeJson.bounding_box = flattened_array;
}
recipeJson[FIRESTORE_FIELDS.RECIPE_PATH] = path;
return recipeJson;
}

const submitRecipe = async () => {
setResultUrl("");
setRunTime(0);
const firebaseRecipe = "firebase:recipes/" + selectedRecipe
let firebaseRecipe = "firebase:recipes/" + selectedRecipe;
const firebaseConfig = "firebase:configs/" + selectedConfig;
let recipeChanged: boolean = await recipeHasChanged();
if (recipeChanged) {
const recipeId = uuidv4();
firebaseRecipe = "firebase:recipes_edited/" + recipeId;
const recipeJson = recipeToFirebase(recipeStr, firebaseRecipe);
try {
await updateRecipe(recipeId, recipeJson);
} catch(e) {
setJobStatus(JobStatus.FAILED);
setJobLogs(String(e));
return;
}

}
const url = getSubmitPackingUrl(firebaseRecipe, firebaseConfig);
const request: RequestInfo = new Request(url, { method: "POST" });
start = Date.now();
Expand Down Expand Up @@ -201,7 +232,7 @@ function App() {
<button type="button" className="collapsible" onClick={toggleRecipe}>Recipe</button>
<div className="recipeJSON">
{viewRecipe && (
<pre>{recipeStr}</pre>
<textarea value={recipeStr} onChange={e => setRecipeStr(e.target.value)}/>
)}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/constants/firebaseConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const FIRESTORE_COLLECTIONS = {
GRADIENTS: "gradients",
COMPOSITION: "composition",
EXAMPLE_RECIPES: "example_recipes",
EDITED_RECIPES: "recipes_edited",
JOB_STATUS: "job_status",
};

Expand Down
10 changes: 8 additions & 2 deletions src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
where,
documentId,
QuerySnapshot,
DocumentData
DocumentData,
setDoc,
doc,
} from "firebase/firestore";
import {
FIREBASE_CONFIG,
Expand Down Expand Up @@ -268,4 +270,8 @@ const getFirebaseRecipe = async (name: string): Promise<string> => {
return unpackedRecipe;
}

export { db, getResultPath, getLocationDict, getDocById, getFirebaseRecipe, getJobStatus };
const updateRecipe = async (id: string, data: object) => {
await setDoc(doc(db, FIRESTORE_COLLECTIONS.EDITED_RECIPES, id), data);
}

export { db, getLocationDict, getDocById, getFirebaseRecipe, getJobStatus, getResultPath, updateRecipe };