-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,62 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { useTasks } from '../../lib/api/useTasks'; | ||
import createListItems from '../../lib/createListItems'; | ||
import ReactList from 'react-list'; | ||
import { Alert, AlertTitle, ListSubheader } from '@mui/material'; | ||
import Task from '../molecules/Task'; | ||
import useFilters from '../../lib/useFilters'; | ||
import browser from '../../lib/Browser'; | ||
import isTask from '../../lib/isTask'; | ||
|
||
export default function Archive(): JSX.Element { | ||
return <>Archive</>; | ||
const { data: tasks, isFetched } = useTasks(); | ||
const { filters } = useFilters(); | ||
const listRef = useRef<ReactList>(null); | ||
const [entries, setEntries] = useState<(TaskType | string)[]>([]); | ||
|
||
useEffect(() => { | ||
const filtered = filters | ||
? (tasks ?? []).filter((t) => filters[t.status]) | ||
: tasks ?? []; | ||
|
||
const { entries: e } = createListItems({ | ||
tasks: filtered, | ||
maxDue: browser.getLastMidnight(), | ||
reverse: true, | ||
}); | ||
|
||
setEntries(e); | ||
}, [tasks, filters]); | ||
|
||
return ( | ||
<> | ||
{isFetched && !(tasks || []).length && ( | ||
<Alert severity="info"> | ||
<AlertTitle>Nothing here!</AlertTitle> | ||
Maybe add a task? | ||
</Alert> | ||
)} | ||
<ReactList | ||
itemRenderer={(i: number) => { | ||
const entry = entries[i]; | ||
return isTask(entry) ? ( | ||
<Task key={`${entry.id ?? ''}_${entry.task}`} task={entry} /> | ||
) : ( | ||
<ListSubheader | ||
key={`${entry}__heading`} | ||
className={`organism-taskList__heading`} | ||
component={'div'} | ||
disableSticky={true} | ||
> | ||
{entry} | ||
</ListSubheader> | ||
); | ||
}} | ||
itemSizeEstimator={(i) => (isTask(entries[i]) ? 60 : 48)} | ||
length={entries.length} | ||
type={'variable'} | ||
ref={listRef} | ||
/> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function isTask(value: unknown): value is TaskType { | ||
return Object.prototype.hasOwnProperty.call(value || {}, 'task'); | ||
} |
f593d55
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://636af17f5cd4523fd8ec12ce--taskratchet.netlify.app