-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tasks): show pending tasks in document footer (#5894)
* fix(tasks): show pending tasks in document footer * fix(tasks): add button to open tasks * fix(tasks): remove comment * fix(tasks): move out of document * fix(tasks): add conditional to tasks footer * fix(tasks): fix ts error * fix(tasks): update pr with comments * fix(tasks): keep task sidebar open if clicked on badge * fix(tasks): pluralize task text * fix(tasks): change React.ReactNode for ReactNode and remove data-as from button --------- Co-authored-by: Pedro Bonamin <[email protected]>
- Loading branch information
1 parent
9254565
commit 177bc79
Showing
9 changed files
with
105 additions
and
37 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
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
import {useCallback, useMemo} from 'react' | ||
|
||
import {Button} from '../../ui-components' | ||
import {useTasks, useTasksEnabled} from '../src' | ||
|
||
/** | ||
* Button that shows how many pending tasks are assigned to the current document. | ||
* Clicking it will open the task sidebar, showing the open tasks related to the document. | ||
* | ||
* todo: just show the tab with tasks related to the document | ||
* @internal | ||
*/ | ||
export function TasksFooterOpenTasks() { | ||
const {data, activeDocument, toggleOpen, isOpen} = useTasks() | ||
const {enabled} = useTasksEnabled() | ||
|
||
const pendingTasks = useMemo( | ||
() => | ||
data.filter((item) => { | ||
return item.target?.document._ref === activeDocument?.documentId && item.status === 'open' | ||
}), | ||
[activeDocument, data], | ||
) | ||
|
||
const handleOnClick = useCallback(() => { | ||
if (isOpen) { | ||
return | ||
} | ||
toggleOpen() | ||
}, [isOpen, toggleOpen]) | ||
|
||
if (pendingTasks.length === 0 || !enabled) return null | ||
|
||
const pluralizedTask = `task${pendingTasks.length > 1 ? 's' : ''}` | ||
|
||
return ( | ||
<Button | ||
mode="bleed" | ||
tooltipProps={{content: `Open ${pluralizedTask}`}} | ||
text={`${pendingTasks.length} open ${pluralizedTask}`} | ||
onClick={handleOnClick} | ||
/> | ||
) | ||
} |
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