Skip to content

Commit 0b8cf00

Browse files
committed
fix: eslint on picker wheel
1 parent 831993c commit 0b8cf00

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

src/components/PickerWheel.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useRef, useEffect } from 'react';
1+
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
22
import '../styles/PickerWheel.css';
33
import colors from '../config/colors';
44
import { Trash } from '@phosphor-icons/react';
@@ -15,33 +15,19 @@ const PickerWheel = () => {
1515
const newEntryInputRef = useRef(null);
1616
const [isModalOpen, setIsModalOpen] = useState(false);
1717

18-
const colorPalette = [
18+
const colorPalette = useMemo(() => [
1919
"#FDE2E4", "#E2ECE9", "#BEE1E6", "#F0EFEB", "#DFE7FD", "#CDDAFD", "#EAD5E6", "#F4C7C3", "#D6E2E9", "#B9E2E6",
2020
"#F9D8D6", "#D4E9E6", "#A8DADC", "#E9E4F2", "#D0D9FB", "#C0CFFB", "#E3C8DE", "#F1BDBD", "#C9D5DE", "#A1D5DB",
2121
"#F6C4C1", "#C1E0DA", "#92D2D2", "#E2DDF0", "#C3CEFA", "#B3C4FA", "#DBBBD1", "#EDB3B0", "#BCC8D3", "#8DCED1"
22-
];
22+
], []);
2323

2424
const cardStyle = {
2525
backgroundColor: colors['app-alpha-10'],
2626
borderColor: colors['app-alpha-50'],
2727
color: colors.app,
2828
};
2929

30-
useEffect(() => {
31-
drawWheel();
32-
}, [entries, rotation]);
33-
34-
const getColorData = (color) => {
35-
const canvas = document.createElement('canvas');
36-
canvas.width = 1;
37-
canvas.height = 1;
38-
const ctx = canvas.getContext('2d');
39-
ctx.fillStyle = color;
40-
ctx.fillRect(0, 0, 1, 1);
41-
return ctx.getImageData(0, 0, 1, 1).data;
42-
}
43-
44-
const drawWheel = () => {
30+
const drawWheel = useCallback(() => {
4531
const canvas = canvasRef.current;
4632
if (!canvas) return;
4733
const ctx = canvas.getContext('2d');
@@ -72,7 +58,21 @@ const PickerWheel = () => {
7258
ctx.restore();
7359
}
7460
ctx.restore();
75-
};
61+
}, [entries, rotation, colorPalette]);
62+
63+
useEffect(() => {
64+
drawWheel();
65+
}, [drawWheel]);
66+
67+
const getColorData = (color) => {
68+
const canvas = document.createElement('canvas');
69+
canvas.width = 1;
70+
canvas.height = 1;
71+
const ctx = canvas.getContext('2d');
72+
ctx.fillStyle = color;
73+
ctx.fillRect(0, 0, 1, 1);
74+
return ctx.getImageData(0, 0, 1, 1).data;
75+
}
7676

7777
const addEntry = () => {
7878
if (newEntry.trim() && entries.length < 30) {
@@ -140,16 +140,6 @@ const PickerWheel = () => {
140140
}
141141
};
142142

143-
const reset = () => {
144-
setWinner(null);
145-
}
146-
147-
const clearEntries = () => {
148-
setEntries([]);
149-
setWinner(null);
150-
setRotation(0);
151-
}
152-
153143
const handleSaveList = (list) => {
154144
const newEntries = list.split('\n').map(entry => entry.trim()).filter(entry => entry);
155145
setEntries([...entries, ...newEntries].slice(0, 30));

0 commit comments

Comments
 (0)