Skip to content

Commit

Permalink
Save changes to days to graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Birdsong committed Oct 20, 2023
1 parent 2aa1384 commit 2969f78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions app/components/ChartModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ import { useState } from "react";
import Graph from "./Graph";
import { getCharts } from "../charts";

export default function ChartModal({ user }) {
export default function ChartModal({ user, updateUser }) {
const [show, setShow] = useState(false);
const [daysToGraph, setDaysToGraph] = useState(30);
const [daysToGraph, setDaysToGraph] = useState(user.daysToGraph ? user.daysToGraph : 30);
const [daysToAverage, setDaysToAverage] = useState(user.daysToAverage ? user.daysToAverage : 7);

const data = [];
var entries = [];

var changeDaysToGraph = (e) => {
var newDaysToGraph = parseInt(e.target.value);
setDaysToGraph(newDaysToGraph);
updateUser({
...user,
daysToGraph: newDaysToGraph
});
};

if (daysToGraph && daysToAverage) {
const lastDayEntries = user.entries.slice(0, daysToGraph);
entries = sortEntries(lastDayEntries, true);
Expand Down Expand Up @@ -87,7 +96,7 @@ export default function ChartModal({ user }) {
<>
<Stack style={{ marginBottom: 15 }} margin={2} spacing={2}>
<TextField
onChange={(e) => setDaysToGraph(parseInt(e.target.value))}
onChange={changeDaysToGraph}
name="steps"
type="number"
label="Number of Days to show on Graph"
Expand Down
2 changes: 1 addition & 1 deletion app/user/[id]/ClientContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function ClientContainer({ userId }) {
<>
<Header user={user} updateUser={updateUser} />

<ChartModal user={user} />
<ChartModal user={user} updateUser={updateUser} />

<Container sx={{ padding: 2 }}>
{user.entries.map(e => <DayEntryView
Expand Down

0 comments on commit 2969f78

Please sign in to comment.