-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new UX for submitting changes #224
Changes from 2 commits
85925a5
ae4d806
65fbd8a
6e597f7
0d5d7d1
bd330f5
c53ab42
976577e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Alert, Box, Button, Snackbar, Typography } from "@mui/material"; | ||
import { Alert, Box, Snackbar, Typography, Fab } from "@mui/material"; | ||
import SaveIcon from "@mui/icons-material/Save"; | ||
import { useEffect, useState } from "react"; | ||
import useFetch from "../../components/useFetch"; | ||
import ListEntryParents from "./ListEntryParents"; | ||
|
@@ -29,8 +30,19 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
errorMessage, | ||
} = useFetch(url); | ||
const [nodeObject, setNodeObject] = useState(null); // Storing updates to node | ||
const [originalNodeObject, setOriginalNodeObject] = useState(null); // For tracking changes | ||
const [updateChildren, setUpdateChildren] = useState([]); // Storing updates of children in node | ||
const [open, setOpen] = useState(false); // Used for Dialog component | ||
const [changesMade, setChangesMade] = useState(false); // Used for displaying Fab | ||
|
||
// Tracking changes | ||
useEffect(() => { | ||
if (nodeObject && originalNodeObject) { | ||
const changesMade = | ||
JSON.stringify(nodeObject) !== JSON.stringify(originalNodeObject); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSON.stringify does not ensure that the strings will have the same shape. Let's use https://www.npmjs.com/package/fast-deep-equal for this. Also, no need for this to be a state, it can be a derived value |
||
setChangesMade(changesMade); | ||
} | ||
}, [nodeObject, originalNodeObject]); | ||
|
||
// Setting state of node after fetch | ||
useEffect(() => { | ||
|
@@ -54,6 +66,7 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
}); | ||
} | ||
setNodeObject(duplicateNode); | ||
setOriginalNodeObject(JSON.parse(JSON.stringify(duplicateNode))); // Deep copy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the |
||
}, [node]); | ||
|
||
// Displaying error messages if any | ||
|
@@ -145,14 +158,18 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
/>{" "} | ||
</> | ||
)} | ||
{/* Button for submitting edits */} | ||
<Button | ||
variant="contained" | ||
onClick={handleSubmit} | ||
sx={{ ml: 4, mt: 2, width: 130, mb: 2 }} | ||
> | ||
Submit | ||
</Button> | ||
{/* Fab for submitting edits */} | ||
{changesMade && ( | ||
<Fab | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add some background color for the Fab, just so that the button is not floating on top of the content? |
||
variant="extended" | ||
onClick={handleSubmit} | ||
color="primary" | ||
sx={{ position: "fixed", bottom: 16, left: 16 }} | ||
> | ||
<SaveIcon sx={{ mr: 1 }} /> | ||
Save Changes | ||
</Fab> | ||
)} | ||
{/* Snackbar for acknowledgment of update */} | ||
<Snackbar | ||
anchorOrigin={{ vertical: "top", horizontal: "right" }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably name this to
isNewChange
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about
hasChanges