Skip to content

Commit

Permalink
implemented saving of data
Browse files Browse the repository at this point in the history
  • Loading branch information
jzakotnik committed Aug 2, 2021
1 parent 4e38047 commit edb33ec
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nextjs/mwe/pages/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function Admin(props) {
const defaultLunchProfile = {
mon: true,
tue: true,
wed: false,
wed: true,
thu: true,
fri: true,
};
Expand Down
6 changes: 5 additions & 1 deletion nextjs/mwe/pages/api/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export default function handler(req, res) {
console.log("Got request for the database");
console.log(req.query.id);
db.get(req.query.id, function (err, value) {
if (err) return console.log("DB request failed", err); // likely the key was not found
if (err) {
db.close();
res.end(value);
return console.log("DB request failed", err);
} // likely the key was not found
console.log(value);
db.close();
res.end(value);
Expand Down
7 changes: 6 additions & 1 deletion nextjs/mwe/pages/lunchprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default function LunchProfile(props) {
fri: true,
});

const readOnly = !props.admin;
const authid = props.authid;
const readerid = props.reader;

useEffect(() => {
console.log("Use Effect with props:");
console.log(props);
Expand All @@ -54,7 +58,8 @@ export default function LunchProfile(props) {
const handleSubmit = (event) => {
event.preventDefault();
//console.log(event);
const data = dayselection;

const data = { dayselection, authid: { admin: authid, reader: readerid } };
console.log("Saving..");
console.log(JSON.stringify(data));

Expand Down
4 changes: 3 additions & 1 deletion nextjs/mwe/pages/profile/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const Profile = (data) => {
const router = useRouter();
const { id } = router.query;
console.log("Rendering data");
console.log(data);
console.log(data, id);

return (
<LunchProfile
lunchdata={data.lunchprofile}
authid={id}
reader={data.reader}
admin={data.admin}
userName="Jure"
/>
Expand Down

0 comments on commit edb33ec

Please sign in to comment.