Skip to content

Commit

Permalink
complete/incomplete filter button for chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
k2xl committed Oct 1, 2023
1 parent 54a8366 commit be96b18
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion components/formatted/formattedCampaign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EnrichedCollection } from '../../models/db/collection';
import { EnrichedLevel } from '../../models/db/level';
import SelectOption from '../../models/selectOption';
import SelectOptionStats from '../../models/selectOptionStats';
import FilterButton from '../buttons/filterButton';
import SelectCard from '../cards/selectCard';

function getCompleteIcon(complete: boolean) {
Expand Down Expand Up @@ -56,12 +57,18 @@ export default function FormattedCampaign({
title,
totalLevels,
}: FormattedCampaignProps) {
const [filter, setFilter] = React.useState<string>('SHOW_ALL');

const getLevelOptions = useCallback((enrichedCollection: EnrichedCollection) => {
const levelOptions: JSX.Element[] = [];
let disabled = false;
let i = 0;

for (const level of enrichedCollection.levels as EnrichedLevel[]) {
if (filter === 'HIDE_COMPLETED' && level.userMoves === level.leastMoves) {
continue;
}

levelOptions.push(
<div className='flex flex-col w-60' key={`collection-${level._id.toString()}`}>
<div className='flex items-center justify-center' id={'level-selectcard-' + i++}>
Expand Down Expand Up @@ -94,7 +101,7 @@ export default function FormattedCampaign({
}

return levelOptions;
}, [levelHrefQuery]);
}, [filter, levelHrefQuery]);

const getOptions = useCallback(() => {
const options: JSX.Element[] = [];
Expand Down Expand Up @@ -205,6 +212,9 @@ export default function FormattedCampaign({
}
</div>
<div>
<div className='text-center mb-3'>
<FilterButton first last element={<span className='text-lg'>{filter === 'HIDE_COMPLETED' ? 'Showing Incomplete' : 'Showing All'}</span>} value='HideCompleted' selected = {filter === 'HIDE_COMPLETED'} onClick = {() => setFilter(filter === 'HIDE_COMPLETED' ? 'SHOW_ALL' : 'HIDE_COMPLETED')} />
</div>
{getOptions()}
</div>
</>);
Expand Down

0 comments on commit be96b18

Please sign in to comment.