Skip to content

Commit 12d48d0

Browse files
feat(ScenarioInfo): improve styling, add edit modal (#322)
* experimenting wiht the grid system * re wrote everything in tailwind * experimenting with some changes * make search inline, made thumbnail 16:9 * added username for display * code style changes * made some requested visual changes * added the desc and est time update system * added the title editbale changes * ran lint and prettier * made some requested backend changes * made some backend cahnges one how the items are being saved * ran lint and prettier
1 parent 5d2f9f6 commit 12d48d0

File tree

9 files changed

+453
-500
lines changed

9 files changed

+453
-500
lines changed

backend/src/db/daos/scenarioDao.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,23 @@ const addThumbs = async (scenarios) => {
2222
const scenarioData = await Promise.all(
2323
scenarios.map(async (scenario) => {
2424
if (!scenario.scenes || !scenario.scenes[0])
25-
return { _id: scenario._id, name: scenario.name };
25+
return {
26+
_id: scenario._id,
27+
name: scenario.name,
28+
description: scenario.description,
29+
estimatedTime: scenario.estimatedTime,
30+
};
2631
const thumbnail = await Scene.findById(scenario.scenes[0], {
2732
components: 1,
2833
_id: 0,
2934
}).lean();
30-
return { _id: scenario._id, name: scenario.name, thumbnail };
35+
return {
36+
_id: scenario._id,
37+
name: scenario.name,
38+
thumbnail,
39+
description: scenario.description,
40+
estimatedTime: scenario.estimatedTime,
41+
};
3142
})
3243
);
3344
return scenarioData;
@@ -41,7 +52,7 @@ const addThumbs = async (scenarios) => {
4152
const retrieveScenarioList = async (uid) => {
4253
const scenarios = await Scenario.find(
4354
{ uid },
44-
{ name: 1, scenes: { $slice: 1 } }
55+
{ name: 1, scenes: { $slice: 1 }, description: 1, estimatedTime: 1 }
4556
)
4657
.sort({ _id: 1 })
4758
.lean();
@@ -66,7 +77,7 @@ const retrieveScenario = async (scenarioId) => {
6677
const retrieveScenarios = async (scenarioIds) => {
6778
const scenarios = await Scenario.find(
6879
{ _id: { $in: scenarioIds } },
69-
{ name: 1, scenes: { $slice: 1 } }
80+
{ name: 1, scenes: { $slice: 1 }, description: 1, estimatedTime: 1 }
7081
);
7182
return addThumbs(scenarios);
7283
};
@@ -84,23 +95,22 @@ const retrieveRoleList = async (scenarioId) => {
8495
/**
8596
* Updates the name of a scenario in the database
8697
* @param {String} scenarioId MongoDB ID of scenario
87-
* @param {{name: String}} updatedScenario updated scenario object
98+
* @param {{name: String, description: String, estimatedTime: String}} updatedScenario updated scenario object
8899
* @returns updated database scenario object
89100
*/
90101
const updateScenario = async (scenarioId, updatedScenario) => {
91102
const scenario = await Scenario.findById(scenarioId);
92103

93-
// define temperary variable to store old name incase new name is empty
94-
const previousName = scenario.name;
95-
scenario.name = updatedScenario.name;
104+
if (updatedScenario.name?.trim()) {
105+
scenario.name = updatedScenario.name;
106+
}
107+
108+
if (updatedScenario.description !== undefined) {
109+
scenario.description = updatedScenario.description;
110+
}
96111

97-
// if new name is empty, set name to old name
98-
if (
99-
scenario.name === "" ||
100-
scenario.name == null ||
101-
scenario.name.trim() === ""
102-
) {
103-
scenario.name = previousName;
112+
if (updatedScenario.estimatedTime !== undefined) {
113+
scenario.estimatedTime = updatedScenario.estimatedTime;
104114
}
105115

106116
await scenario.save();

backend/src/db/models/scenario.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const scenarioSchema = new Schema({
2828
type: Object,
2929
},
3030
],
31+
description: {
32+
type: String,
33+
default: "",
34+
},
35+
estimatedTime: {
36+
type: String,
37+
default: "",
38+
},
3139
});
3240

3341
// before removal of a scenario from the database, first remove all its scenes

backend/src/routes/api/scenario.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ router.get("/:scenarioId", async (req, res) => {
6565

6666
// Update a scenario by a user
6767
router.put("/:scenarioId", async (req, res) => {
68-
const { name, duration } = req.body;
68+
const { name, duration, description, estimatedTime } = req.body;
6969
let scenario = await updateScenario(req.params.scenarioId, {
7070
name,
71+
description,
72+
estimatedTime,
7173
});
7274

7375
scenario = await updateDurations(req.params.scenarioId, {
@@ -77,6 +79,15 @@ router.put("/:scenarioId", async (req, res) => {
7779
res.status(HTTP_OK).json(scenario);
7880
});
7981

82+
router.patch("/:scenarioId", async (req, res) => {
83+
const { name, description, estimatedTime } = req.body;
84+
85+
const updates = { name, description, estimatedTime };
86+
87+
const scenario = await updateScenario(req.params.scenarioId, updates);
88+
res.status(HTTP_OK).json(scenario);
89+
});
90+
8091
// Delete a scenario of a user
8192
router.delete("/:scenarioId", async (req, res) => {
8293
const deleted = await deleteScenario(req.params.scenarioId);

0 commit comments

Comments
 (0)