Skip to content

Commit

Permalink
refactor(tasks): use navbar actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Mar 12, 2024
1 parent e2579e3 commit 31263ca
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
49 changes: 44 additions & 5 deletions packages/sanity/src/tasks/plugin/TasksStudioNavbar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
import {PanelRightIcon, TaskIcon} from '@sanity/icons'
import {useCallback, useMemo} from 'react'
import {type NavbarProps} from 'sanity'

import {TasksNavbarButton, useTasksEnabled} from '../src'
import {useTasks, useTasksEnabled} from '../src'

export function TasksStudioNavbar(props: NavbarProps) {
const {enabled} = useTasksEnabled()
const EMPTY_ARRAY: [] = []

function TasksStudioNavbarInner(props: NavbarProps) {
const {toggleOpen, isOpen} = useTasks()

const handleAction = useCallback(() => {
toggleOpen()
}, [toggleOpen])

const actions = useMemo((): NavbarProps['__internal_actions'] => {
return [
...(props?.__internal_actions || EMPTY_ARRAY),
{
icon: PanelRightIcon,
location: 'topbar',
name: 'tasks-topbar',
onAction: handleAction,
selected: isOpen,
title: 'Tasks',
},
{
icon: TaskIcon,
location: 'sidebar',
name: 'tasks-sidebar',
onAction: handleAction,
selected: isOpen,
title: 'Tasks',
},
]
}, [handleAction, isOpen, props?.__internal_actions])

if (!enabled) return props.renderDefault(props)
return props.renderDefault({
...props,
// eslint-disable-next-line camelcase
__internal_rightSectionNode: <TasksNavbarButton />,
__internal_actions: actions,
})
}

export function TasksStudioNavbar(props: NavbarProps) {
const {enabled} = useTasksEnabled()

if (!enabled) {
return props.renderDefault(props)
}

return <TasksStudioNavbarInner {...props} />
}
1 change: 0 additions & 1 deletion packages/sanity/src/tasks/src/tasks/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './form'
export * from './navbar'
export * from './sidebar'

This file was deleted.

This file was deleted.

0 comments on commit 31263ca

Please sign in to comment.