Skip to content

Commit f7731a4

Browse files
committed
✨ Added star toggle but it doesn't toggle
1 parent 69edf5d commit f7731a4

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

src/components/Table/index.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const Table = () => {
5050
new Array(questions.length).fill('');
5151

5252
/* If the user has previously visited the website, then an array in
53-
LocalStorage would exist of a certain length which corresponds to which
54-
questions they have/have not completed. In the event that we add new questions
55-
to the list, then we would need to resize and copy the existing 'checked'
56-
array before updating it in LocalStorage in order to transfer their saved
57-
progress. */
53+
LocalStorage would exist of a certain length which corresponds to which
54+
questions they have/have not completed. In the event that we add new questions
55+
to the list, then we would need to resize and copy the existing 'checked'
56+
array before updating it in LocalStorage in order to transfer their saved
57+
progress. */
5858
if (checkedList.length !== questions.length) {
5959
const resizedCheckedList = new Array(questions.length).fill(false);
6060

@@ -114,6 +114,15 @@ const Table = () => {
114114
JSON.parse(localStorage.getItem('showPatterns')) || new Array(1).fill(true),
115115
);
116116

117+
const [important, setImportant] = useState(
118+
JSON.parse(localStorage.getItem('importantProblems')) ||
119+
new Array(questions.length).fill(false),
120+
);
121+
122+
useEffect(() => {
123+
localStorage.setItem('importantProblems', JSON.stringify(important));
124+
}, [important]);
125+
117126
useEffect(() => {
118127
window.localStorage.setItem('checked', JSON.stringify(checked));
119128
}, [checked]);
@@ -171,7 +180,7 @@ const Table = () => {
171180
totalValue={totalDifficultyCount.Total}
172181
label={() =>
173182
`${difficultyCount.Total} /
174-
${totalDifficultyCount.Total}`
183+
${totalDifficultyCount.Total}`
175184
}
176185
labelPosition={0}
177186
labelStyle={{
@@ -481,7 +490,46 @@ const Table = () => {
481490
},
482491
Filter: SelectColumnFilter,
483492
},
493+
/* eslint-disable react/prop-types */
484494
{
495+
Header: '⭐',
496+
accessor: 'important',
497+
disableSortBy: true,
498+
disableFilters: true,
499+
Cell: ({ row }) => {
500+
const id = Number(row?.original?.id);
501+
if (Number.isNaN(id)) return '❌';
502+
503+
const handleKeyPress = e => {
504+
if (e.key === 'Enter' || e.key === ' ') {
505+
const updatedImportant = [...important];
506+
updatedImportant[id] = !updatedImportant[id];
507+
setImportant(updatedImportant);
508+
console.log('Toggled important:', updatedImportant);
509+
}
510+
};
511+
512+
return (
513+
<span
514+
role="button"
515+
tabIndex={0}
516+
style={{ cursor: 'pointer', fontSize: '1.2em' }}
517+
onClick={() => {
518+
console.log('Star clicked!', id); // add this
519+
const updatedImportant = [...important];
520+
updatedImportant[id] = !updatedImportant[id];
521+
setImportant(updatedImportant);
522+
}}
523+
onKeyDown={handleKeyPress}
524+
aria-label="Mark as important for revision"
525+
data-tip="Mark as important for revision"
526+
>
527+
{important[id] ? '⭐' : '☆'}
528+
</span>
529+
);
530+
},
531+
}, // Optional
532+
/* eslint-enable react/prop-types */ {
485533
Header: 'Last Solved On',
486534
accessor: 'LastSolvedOn',
487535
disableSortBy: true,

0 commit comments

Comments
 (0)