-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle navigation between the grid and list views
- Loading branch information
Showing
19 changed files
with
635 additions
and
471 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
34 changes: 34 additions & 0 deletions
34
components/header-bar/src/command-palette/context/command-palette-context.js
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,34 @@ | ||
import PropTypes from 'prop-types' | ||
import React, { createContext, useContext, useState } from 'react' | ||
|
||
const commandPaletteContext = createContext() | ||
|
||
export const CommandPaletteContextProvider = ({ children }) => { | ||
const [filter, setFilter] = useState('') | ||
const [highlightedIndex, setHighlightedIndex] = useState(0) | ||
const [currentView, setCurrentView] = useState('home') | ||
// home view sections | ||
const [activeSection, setActiveSection] = useState('grid') | ||
|
||
return ( | ||
<commandPaletteContext.Provider | ||
value={{ | ||
filter, | ||
setFilter, | ||
highlightedIndex, | ||
setHighlightedIndex, | ||
currentView, | ||
setCurrentView, | ||
activeSection, | ||
setActiveSection, | ||
}} | ||
> | ||
{children} | ||
</commandPaletteContext.Provider> | ||
) | ||
} | ||
CommandPaletteContextProvider.propTypes = { | ||
children: PropTypes.node, | ||
} | ||
|
||
export const useCommandPaletteContext = () => useContext(commandPaletteContext) |
30 changes: 30 additions & 0 deletions
30
components/header-bar/src/command-palette/hooks/use-filter.js
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,30 @@ | ||
import { useMemo } from 'react' | ||
import { useCommandPaletteContext } from '../context/command-palette-context.js' | ||
import { filterItemsArray } from '../utils/filterItemsArray.js' | ||
|
||
export const useFilter = ({ apps, commands, shortcuts }) => { | ||
const { filter, currentView } = useCommandPaletteContext() | ||
|
||
const filteredApps = filterItemsArray(apps, filter) | ||
const filteredCommands = filterItemsArray(commands, filter) | ||
const filteredShortcuts = filterItemsArray(shortcuts, filter) | ||
|
||
const currentViewItemsArray = useMemo(() => { | ||
if (currentView === 'apps') { | ||
return filteredApps | ||
} else if (currentView === 'commands') { | ||
return filteredCommands | ||
} else if (currentView === 'shortcuts') { | ||
return filteredShortcuts | ||
} else { | ||
return filteredApps.concat(filteredCommands, filteredShortcuts) | ||
} | ||
}, [currentView, filteredApps, filteredCommands, filteredShortcuts]) | ||
|
||
return { | ||
filteredApps, | ||
filteredCommands, | ||
filteredShortcuts, | ||
currentViewItemsArray, | ||
} | ||
} |
Oops, something went wrong.