Skip to content
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

Final time choice #11

Merged
merged 3 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions components/MarkChoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { MarkedProps } from "../models/poll";

const MarkChoices = (props: {
sortedChoices: number[];
newUserMarked: MarkedProps;
setNewUserMarked: Dispatch<MarkedProps>;
newMarked: MarkedProps;
setNewMarked: Dispatch<MarkedProps>;
}): JSX.Element => {
const { sortedChoices, newUserMarked, setNewUserMarked } = props;
const { sortedChoices, newMarked, setNewMarked } = props;

const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
const { value } = e.target;
setNewUserMarked({ ...newUserMarked, userID: value });
setNewMarked({ ...newMarked, userID: value });
};

const handleChoiceChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
const { value, checked } = e.target;
if (checked) {
const newChoices = newUserMarked.choices;
const newChoices = newMarked.choices;
newChoices.push(parseInt(value, 10));
setNewUserMarked({ ...newUserMarked, choices: newChoices });
setNewMarked({ ...newMarked, choices: newChoices });
} else {
const newChoices = newUserMarked.choices;
const newChoices = newMarked.choices;
newChoices.splice(newChoices.indexOf(parseInt(value, 10)), 1); // remove the unchecked element from array
setNewUserMarked({ ...newUserMarked, choices: newChoices });
setNewMarked({ ...newMarked, choices: newChoices });
}
};

Expand Down
8 changes: 4 additions & 4 deletions components/SubmitChoices.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Button } from "react-bootstrap";
import { MarkedProps } from "../models/poll";

const SubmitChoices = (props: { newUserMarked: MarkedProps }): JSX.Element => {
const { newUserMarked } = props;
const SubmitChoices = (props: { newMarked: MarkedProps }): JSX.Element => {
const { newMarked } = props;

const handleSubmit = (): void => {
// PUT newUserMarked at v1/poll/{pollID}
// PUT newMarked at v1/poll/:pollID
};

return (
<Button
variant="primary"
type="submit"
disabled={!newUserMarked.userID || newUserMarked.choices.length === 0}
disabled={!newMarked.userID || newMarked.choices.length === 0}
onClick={handleSubmit}
>
Mark your choice
Expand Down
6 changes: 5 additions & 1 deletion components/SubmitFinalChoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const SubmitFinalChoice = (props: {
const { finalChoice } = props;

const handleSubmit = (): void => {
// PUT finalChoice at v1/user/poll/{pollID}
const markFinalChoice = {
finalChoice,
open: false,
};
// PUT markFinalChoice at v1/user/poll/:pollid
};

return (
Expand Down
20 changes: 15 additions & 5 deletions pages/poll/haha.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Poll = (): JSX.Element => {

const sortedChoices = pollFromDB.choices.sort((a, b) => a - b);

const [newUserMarked, setNewUserMarked] = useState<MarkedProps>({
const [newMarked, setNewMarked] = useState<MarkedProps>({
userID: "",
choices: [],
});
Expand All @@ -77,7 +77,17 @@ const Poll = (): JSX.Element => {
participants
</th>
{sortedChoices.map((idx) => (
<th key={idx}>{dayjs(idx).format("llll")}</th>
<th
key={idx}
className={
idx === pollFromDB.finalChoice
? "slot-final-chosen-cell"
: ""
}
>
{dayjs(idx).format("llll")} -{" "}
{dayjs(idx + pollFromDB.interval).format("LT")}
</th>
))}
</tr>
</thead>
Expand All @@ -103,8 +113,8 @@ const Poll = (): JSX.Element => {
currentLoggedInUserID !== pollFromDB.userID && (
<MarkChoices
sortedChoices={sortedChoices}
newUserMarked={newUserMarked}
setNewUserMarked={setNewUserMarked}
newMarked={newMarked}
setNewMarked={setNewMarked}
/>
)}
{pollFromDB.open &&
Expand All @@ -117,7 +127,7 @@ const Poll = (): JSX.Element => {
</tbody>
</Table>
{pollFromDB.open && currentLoggedInUserID !== pollFromDB.userID && (
<SubmitChoices newUserMarked={newUserMarked} />
<SubmitChoices newMarked={newMarked} />
)}
{pollFromDB.open && currentLoggedInUserID === pollFromDB.userID && (
<SubmitFinalChoice finalChoice={finalChoice} />
Expand Down
4 changes: 4 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ h3 {
.slot-checkbox input[type="radio"] {
width: 1.8em;
height: 1.8em;
}

.slot-final-chosen-cell {
background-color: #FFBB12;
}