Skip to content

Commit

Permalink
fix: fix multiplayer scenarios not displaying in home page. (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjin-lee authored Sep 17, 2024
1 parent a00f548 commit ef45396
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions backend/src/db/daos/userDao.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import User from "../models/user";
import Scenario from "../models/scenario";
import Groups from "../models/group";
import { retrieveScenarios } from "./scenarioDao";

/**
Expand Down Expand Up @@ -76,6 +77,12 @@ const deleteUser = async (uid) => {
};

/**
* @deprecated 17/09/2024
* We currently do not support play history - a larger refactor is likely required, at which point,
* we should support both single and multiplayer
*
* Not removing as there are possible regressions not accounted for.
*
* Appendings new object "newPlayed" to user's played array and adds the users uid to scenario's user array
* @param {String} uid user's unique id
* @param {{scenarioId: String, path: Object[]}} newPlayed user's new played object
Expand Down Expand Up @@ -135,9 +142,16 @@ const assignScenarioToUsers = async (scenarioId, newAssignees) => {
*/
const retrieveAssignedScenarioList = async (userId) => {
const user = await User.findOne({ uid: userId });
if (!user.assigned || !user.assigned.length) return [];
if (!user.assigned) return []; // even if list is empty, we may have groups this user is a part of.

return retrieveScenarios(user.assigned);
const multiplayerScenarios = await Groups.find(
{ "users.email": user.email },
{ scenarioId: 1, _id: 0 }
);

return retrieveScenarios(
user.assigned.concat(multiplayerScenarios.map((doc) => doc.scenarioId))
);
};

const fetchScene = async (email, scenarioId) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListContainer/ListContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function ListContainer({
: null}
</ImageList>

{assignedScenarios ? (
{assignedScenarios.length ? (
<>
{!sceneSelectionPage && (
<h1 className="text-3xl font-bold my-3">Assigned scenarios</h1>
Expand Down

0 comments on commit ef45396

Please sign in to comment.