Skip to content

Commit

Permalink
Add resume item functionality, fix #76 and #78
Browse files Browse the repository at this point in the history
  • Loading branch information
cassidoo committed Feb 25, 2020
1 parent 0844268 commit b6b8665
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 63 deletions.
23 changes: 17 additions & 6 deletions src/components/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { useAppReducer } from "../AppContext";
import styles from "./Item.module.scss";

// Individial todo item
// Individual todo item
function Item({ item }) {
const dispatch = useAppReducer();
let text = item.text;
Expand All @@ -18,22 +18,33 @@ function Item({ item }) {
dispatch({ type: "UPDATE_ITEM", item: pausedItem });
}

function resumeItem() {
const pendingItem = { ...item, status: "pending" };
dispatch({ type: "UPDATE_ITEM", item: pendingItem });
}

function completeItem() {
const completedItem = { ...item, status: "completed" };
dispatch({ type: "UPDATE_ITEM", item: completedItem });
}

return (
<div
className={`${styles.item} ${paused ? styles.pausedItem : ""}`}
tabIndex="0"
>
<div className={styles.item} tabIndex="0">
<div className={styles.itemName}>{text}</div>
<div className={styles.buttons}>
<div
className={`${styles.buttons} ${completed ? styles.completedButtons : ""}`}
>
<button className={styles.delete} onClick={deleteItem} tabIndex="0"></button>
{!paused && !completed && (
<button className={styles.pause} onClick={pauseItem} tabIndex="0"></button>
)}
{paused && !completed && (
<button
className={styles.resume}
onClick={resumeItem}
tabIndex="0"
></button>
)}
{!completed && (
<button
className={styles.complete}
Expand Down
99 changes: 55 additions & 44 deletions src/components/Item.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
@media (max-width: 600px) {
margin: 20px auto;
}
&.pausedItem {
.itemName {
width: calc(100% - 80px);
}
}
.itemName {
width: calc(100% - 110px);
overflow: auto;
Expand All @@ -42,51 +37,67 @@
border-radius: 3px;
}
}
.buttons button {
position: relative;
margin: 0 0 0 10px;
height: 24px;
border: none;
&.delete {
width: 24px;
background: no-repeat url("../img/x.svg");
&:after {
background: $red;
}
.buttons {
display: flex;
justify-content: space-between;
width: 100px;

&.completedButtons {
justify-content: flex-end;
}
&.pause {
width: 24px;
background: no-repeat url("../img/pause.svg");
&:after {
background: $yellow;

button {
position: relative;
height: 24px;
border: none;
&.delete {
width: 24px;
background: no-repeat url("../img/x.svg");
&:after {
background: $red;
}
}
}
&.complete {
width: 30px;
background: no-repeat url("../img/check.svg");
&:after {
background: $green;
&.pause {
width: 24px;
background: no-repeat url("../img/pause.svg");
&:after {
background: $yellow;
}
}
&.resume {
width: 24px;
background: no-repeat url("../img/resume.svg");
&:after {
background: $yellow;
}
}
&.complete {
width: 30px;
background: no-repeat url("../img/check.svg");
&:after {
background: $green;
}
}
}
&:after {
display: block;
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 100%;
width: 0;
height: 0;
}
&:focus {
outline: 1px solid $item-color;
&:after {
display: block;
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 100%;
width: 0;
height: 0;
}
&:focus {
outline: 1px solid $item-color;
&:after {
animation: click 0.5s;
}
}
&:hover:after {
animation: click 0.5s;
}
}
&:hover:after {
animation: click 0.5s;
}
}
}
18 changes: 5 additions & 13 deletions src/img/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/img/resume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6b8665

Please sign in to comment.