Skip to content

Commit

Permalink
CSV goes to mongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
GodYazza committed Sep 2, 2023
1 parent 86b2180 commit d8fdd30
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
13 changes: 13 additions & 0 deletions frontend/src/components/newUID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

Check warning on line 1 in frontend/src/components/newUID.js

View workflow job for this annotation

GitHub Actions / Run linters frontend

'React' is defined but never used

export default function generateUID() {
const charset =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const uidLength = 28;
let uid = "";
for (let i = 0; i < uidLength; i += 1) {
const randomIndex = Math.floor(Math.random() * charset.length);
uid += charset.charAt(randomIndex);
}
return uid;
}
2 changes: 1 addition & 1 deletion frontend/src/containers/pages/ScenarioSelectionPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from "react";
import React, { useContext, useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import SideBar from "../../components/SideBar";
import ListContainer from "../../components/ListContainer";
Expand Down
42 changes: 32 additions & 10 deletions frontend/src/containers/pages/SceneSelectionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import AuthoringToolContextProvider from "../../context/AuthoringToolContextProv
import AuthenticationContext from "../../context/AuthenticationContext";
import HelpButton from "../../components/HelpButton";
import AccessLevel from "../../enums/route.access.level";
import generateUID from "../../components/newUID";

/**
* Page that shows the scenes belonging to a scenario.
Expand All @@ -43,8 +44,25 @@ export function SceneSelectionPage({ data = null }) {
Papa.parse(selectedFile, {
header: true,
skipEmptyLines: true,
complete(results) {
console.log(results.data);
complete: async (results) => {
const usersData = results.data;
usersData.forEach(async (userData) => {
const { name, email } = userData;
const uid = generateUID(); // Implement your UID generation logic
const pictureURL = "null"; // Set the picture URL if available
const newUser = await usePost(

Check warning on line 53 in frontend/src/containers/pages/SceneSelectionPage.js

View workflow job for this annotation

GitHub Actions / Run linters frontend

'newUser' is assigned a value but never used
`/api/user/`,
{
name,
uid,
email,
pictureURL,
},
getUserIdToken
);
console.log(`User ${name} uploaded to MongoDB.`);
});
console.log("CSV data uploaded to MongoDB.");
},
});
};
Expand Down Expand Up @@ -202,14 +220,18 @@ export function SceneSelectionPage({ data = null }) {
>
Share
</Button>
<Button
className="btn top contained white"
color="default"
variant="outlined"
onClick={() => handCSVClick(true)}
>
Upload CSV
</Button>
{VpsUser.role === AccessLevel.USER ? (
<Button
className="btn top contained white"
color="default"
variant="outlined"
onClick={() => handCSVClick(true)}
>
Upload CSV
</Button>
) : (
""
)}
<input
type="file"
ref={fileInputRef}
Expand Down

0 comments on commit d8fdd30

Please sign in to comment.