Skip to content

Commit d96c27d

Browse files
committed
add star feature, saves starred question to view later
1 parent 0cc695f commit d96c27d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/components/Table/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ const Table = () => {
121121
? savedImportant
122122
: new Array(questions.length).fill(false),
123123
);
124+
125+
// Returns an array of question objects that are starred
126+
const getStarredQuestions = () => {
127+
return questions.filter((q, idx) => important[idx]);
128+
};
124129
useEffect(() => {
125130
localStorage.setItem('importantProblems', JSON.stringify(important));
126131
}, [important]);
@@ -591,10 +596,48 @@ const Table = () => {
591596
useSortBy,
592597
);
593598

599+
const [showOnlyStarred, setShowOnlyStarred] = useState(false);
600+
601+
useEffect(() => {
602+
if (showOnlyStarred) {
603+
setData(getStarredQuestions());
604+
} else {
605+
setData(filteredByCheckbox());
606+
}
607+
// eslint-disable-next-line
608+
}, [showOnlyStarred, important, checked, resetCount]);
609+
594610
return (
595611
<Container className="table">
596612
<ReactTooltip />
597613
<PatternFrequencies filters={filters} rows={filteredRows} />
614+
615+
{/* Minimal Show Only Starred Button */}
616+
<div
617+
style={{
618+
display: 'flex',
619+
justifyContent: 'flex-end',
620+
marginBottom: '1rem',
621+
}}
622+
>
623+
<Button
624+
color={showOnlyStarred ? 'warning' : 'secondary'}
625+
outline={!showOnlyStarred}
626+
size="sm"
627+
style={{
628+
fontWeight: 600,
629+
letterSpacing: '0.5px',
630+
boxShadow: showOnlyStarred
631+
? '0 0 0 2px #ffd666'
632+
: '0 0 0 1px #d9d9d9',
633+
transition: 'box-shadow 0.2s',
634+
}}
635+
onClick={() => setShowOnlyStarred(!showOnlyStarred)}
636+
>
637+
{showOnlyStarred ? 'Show All Questions' : 'Show Only Starred ⭐'}
638+
</Button>
639+
</div>
640+
598641
<ReactTable borderless striped hover {...getTableProps()}>
599642
<thead>
600643
{headerGroups.map(headerGroup => (

0 commit comments

Comments
 (0)