From af1de3f97868da090aba4f9003b1029f065396aa Mon Sep 17 00:00:00 2001 From: ELiuHub Date: Sun, 20 Nov 2022 16:45:52 -0800 Subject: [PATCH] bug fix --- src/Pages/form.js | 2 +- src/Pages/upload.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Pages/form.js b/src/Pages/form.js index dd66001..b0aaebc 100644 --- a/src/Pages/form.js +++ b/src/Pages/form.js @@ -31,7 +31,7 @@ function Form(props) { let isAdmin = await AdminStatus(); let forms; if (isAdmin) { - forms = await API.graphql(graphqlOperation(listForms)); + forms = await API.graphql(graphqlOperation(listForms, {filter: {owner: {eq: user.username}}})); } else { forms = await API.graphql(graphqlOperation(listForms, {filter: {otherUser: {eq: user.username}}})); } diff --git a/src/Pages/upload.js b/src/Pages/upload.js index 5e494b8..358f6e6 100644 --- a/src/Pages/upload.js +++ b/src/Pages/upload.js @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react'; import { Collapse, Alert, Button, Box, Stack, TextField, Tabs, Tab, FormControl, InputLabel, Select, MenuItem } from "@mui/material"; import { UploadFile } from "@mui/icons-material"; -import { API, graphqlOperation } from 'aws-amplify'; +import { API, graphqlOperation, Auth } from 'aws-amplify'; import axios from 'axios'; import { createForm } from '../graphql/mutations'; import { listForms, getFormByName } from '../graphql/queries'; @@ -29,7 +29,8 @@ export default function Upload(props) { useEffect(() => { async function existingForms() { try { - let forms = await API.graphql(graphqlOperation(listForms)); + let user = await Auth.currentAuthenticatedUser(); + let forms = await API.graphql(graphqlOperation(listForms, {filter: {owner: {eq: user.username}}})); let formNames = [...new Set(forms.data.listForms.items.map((form)=>form.name))]; setAvailableForms(formNames); } catch (error) { @@ -54,6 +55,7 @@ export default function Upload(props) { async function handleFormUpload(e) { e.preventDefault(); + let user = await Auth.currentAuthenticatedUser(); let uploadedFile = document.getElementById('uploadFile'); if (formTitle === '') { setFieldError(true); @@ -77,6 +79,7 @@ export default function Upload(props) { name: formTitle, version: 1, otherUser: formUser, + owner: user.username, formID: response.data.id } };