Skip to content

Commit 3d83ed7

Browse files
committed
fix incorrect reference causing error in state
1 parent bf24b54 commit 3d83ed7

File tree

2 files changed

+83
-62
lines changed

2 files changed

+83
-62
lines changed

src/components/ColourPicker.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from "react";
2+
import { compose, withState } from "recompose";
3+
import styled from "styled-components";
4+
import Button from "@material-ui/core/Button";
5+
import ColorLens from "@material-ui/icons/ColorLens";
6+
7+
const ColourPickerList = styled.ul`
8+
list-style: none;
9+
padding: 0;
10+
margin: 0;
11+
z-index: 12;
12+
`;
13+
const ColourOffering = styled.li`
14+
border-radius: 50%;
15+
height: 56px;
16+
width: 56px;
17+
background: blue;
18+
position: absolute;
19+
text-indent: 100%;
20+
overflow: hidden;
21+
`;
22+
const ColourOfferingYellow = ColourOffering.extend`
23+
background: yellow;
24+
left: 0;
25+
`;
26+
const ColourOfferingGreen = ColourOffering.extend`
27+
background: green;
28+
left: 30px;
29+
`;
30+
const ColourOfferingPink = ColourOffering.extend`
31+
background: pink;
32+
left: 60px;
33+
`;
34+
const ToggleListButton = styled(Button)`
35+
position: absolute !important;
36+
bottom: 10px;
37+
left: 10px;
38+
`;
39+
const ColourPicker = ({
40+
isColorPickerShown,
41+
toggleColourPicker,
42+
setPostitColour
43+
}) => {
44+
return (
45+
<div>
46+
<ToggleListButton
47+
onClick={() => toggleColourPicker(!isColorPickerShown)}
48+
title="change color"
49+
color="primary"
50+
aria-label="change color"
51+
variant="fab"
52+
>
53+
<ColorLens />
54+
</ToggleListButton>
55+
{isColorPickerShown && (
56+
<ColourPickerList>
57+
<ColourOfferingYellow onClick={() => setPostitColour("yellow")}>
58+
yellow
59+
</ColourOfferingYellow>
60+
<ColourOfferingGreen onClick={() => setPostitColour("green")}>
61+
green
62+
</ColourOfferingGreen>
63+
<ColourOfferingPink onClick={() => setPostitColour("pink")}>
64+
pink
65+
</ColourOfferingPink>
66+
</ColourPickerList>
67+
)}
68+
</div>
69+
);
70+
};
71+
72+
const enhance = compose(
73+
withState("isColorPickerShown", "toggleColourPicker", false)
74+
);
75+
export default enhance(ColourPicker);

src/components/Postit.js

+8-62
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import styled from "styled-components";
33
import { compose, withState, withHandlers } from "recompose";
44
import Button from "@material-ui/core/Button";
55
import Delete from "@material-ui/icons/Delete";
6-
import ColorLens from "@material-ui/icons/ColorLens";
6+
7+
import ColourPicker from "./ColourPicker";
78

89
const StyledButton = styled(Button)`
910
position: absolute !important;
@@ -15,44 +16,13 @@ const Postit = styled.li`
1516
color: #333;
1617
position: relative;
1718
width: 300px;
19+
min-height: 300px;
1820
margin: 0 auto;
1921
transform: rotate(2deg);
2022
padding: 40px 0 0 40px;
2123
box-shadow: 0 10px 10px 2px rgba(0, 0, 0, 0.3);
2224
`;
23-
const ToggleListButton = styled(Button)`
24-
position: absolute !important;
25-
bottom: 10px;
26-
left: 10px;
27-
`;
2825

29-
const ColourPicker = styled.ul`
30-
list-style: none;
31-
padding: 0;
32-
margin: 0;
33-
z-index: 12;
34-
`;
35-
const ColourOffering = styled.li`
36-
border-radius: 50%;
37-
height: 56px;
38-
width: 56px;
39-
background: blue;
40-
position: absolute;
41-
text-indent: 100%;
42-
overflow: hidden;
43-
`;
44-
const ColourOfferingYellow = ColourOffering.extend`
45-
background: yellow;
46-
left: 0;
47-
`;
48-
const ColourOfferingGreen = ColourOffering.extend`
49-
background: green;
50-
left: 30px;
51-
`;
52-
const ColourOfferingPink = ColourOffering.extend`
53-
background: pink;
54-
left: 60px;
55-
`;
5626
const Textarea = styled.textarea`
5727
border: none;
5828
background: none;
@@ -68,7 +38,6 @@ const Posit = ({
6838
setPostitColour,
6939
removeNote,
7040
toggleColourPicker,
71-
isColorPickerShown,
7241
isPostitActive,
7342
handleInputChange,
7443
highLightPostit
@@ -96,41 +65,18 @@ const Posit = ({
9665
>
9766
<Delete />
9867
</StyledButton>
99-
<ToggleListButton
100-
onClick={() => toggleColourPicker(!isColorPickerShown)}
101-
title="change color"
102-
color="primary"
103-
aria-label="change color"
104-
variant="fab"
105-
>
106-
<ColorLens />
107-
</ToggleListButton>
108-
{isColorPickerShown && (
109-
<ColourPicker>
110-
<ColourOfferingYellow onClick={() => setPostitColour("yellow")}>
111-
yellow
112-
</ColourOfferingYellow>
113-
<ColourOfferingGreen onClick={() => setPostitColour("green")}>
114-
green
115-
</ColourOfferingGreen>
116-
<ColourOfferingPink onClick={() => setPostitColour("pink")}>
117-
pink
118-
</ColourOfferingPink>
119-
</ColourPicker>
120-
)}
68+
<ColourPicker
69+
setPostitColour={setPostitColour}
70+
toggleColourPicker={toggleColourPicker}
71+
/>
12172
</Postit>
12273
);
12374
};
12475
const enhance = compose(
125-
withState("isColorPickerShown", "toggleColourPicker", false),
12676
withState("isPostitActive", "highLightPostit", false),
12777
withHandlers({
128-
setPostitColour: props => colour => {
129-
props.updateNoteColour({ id: props.note.id, noteColour: colour });
130-
props.toggleColourPicker();
131-
},
13278
handleInputChange: props => event => {
133-
props.updateNoteText({ id: props.note.id, noteText: event.value });
79+
props.updateNoteText({ id: props.note.id, noteText: event.target.value });
13480
},
13581
highLightPostIt: props => event => {}
13682
})

0 commit comments

Comments
 (0)