Skip to content

Commit

Permalink
✨ Replace react hook based pathname with browser api
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Jan 3, 2025
1 parent 70a6072 commit c52f4f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
4 changes: 1 addition & 3 deletions components/shell/CommandPalette/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const CommandPaletteRoot = ({
children: React.ReactNode
}) => {
const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
const staticActions = getStaticActions({ router, pathname, searchParams })
const staticActions = getStaticActions({ router })
return (
<KBarProvider actions={staticActions}>
<KBarPortal>
Expand Down
16 changes: 4 additions & 12 deletions components/shell/CommandPalette/actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime'
import { ReadonlyURLSearchParams } from 'next/navigation'

export const getStaticActions = ({
router,
pathname,
searchParams,
}: {
router: AppRouterInstance
pathname: string
searchParams: ReadonlyURLSearchParams
}) => [
export const getStaticActions = ({ router }: { router: AppRouterInstance }) => [
{
id: 'quick-action-modal',
name: 'Open Quick Action Panel',
Expand All @@ -25,9 +16,10 @@ export const getStaticActions = ({
shortcut: ['w'],
keywords: 'workspace,panel',
perform: () => {
const newParams = new URLSearchParams(searchParams)
const pathname = window.location.pathname
const newParams = new URLSearchParams(window.location.search)
newParams.set('workspaceOpen', 'true')
router.push((pathname ?? '') + '?' + newParams.toString())
router.push(`${pathname}?${newParams.toString()}`)
},
},
{
Expand Down

0 comments on commit c52f4f5

Please sign in to comment.