mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 23:03:11 +00:00
fix(C94): draft mirror p/ picks cumulativos no omnibox + simplificações do /simplify
This commit is contained in:
parent
ad39602d04
commit
f36cc244b7
6 changed files with 44 additions and 29 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { MapPinnedIcon, PlusIcon } from 'lucide-react'
|
import { MapPinnedIcon, PlusIcon } from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
import { CampaignListOmnibox } from '@/components/campaign/shared/CampaignListOmnibox'
|
import { CampaignListOmnibox } from '@/components/campaign/shared/CampaignListOmnibox'
|
||||||
import type { RelationOption } from '@/components/campaign/shared/RelationMultiSelect'
|
import type { RelationOption } from '@/components/campaign/shared/RelationMultiSelect'
|
||||||
|
|
@ -35,6 +35,10 @@ type ActivityAgendaFiltersProps = {
|
||||||
* Deputado presente (chip bool), with the desktop create entries as icon
|
* Deputado presente (chip bool), with the desktop create entries as icon
|
||||||
* buttons beside the bar. Mobile creates live in the FAB drawer, so the
|
* buttons beside the bar. Mobile creates live in the FAB drawer, so the
|
||||||
* trailing icons are desktop-only. Filter state stays on the URL.
|
* trailing icons are desktop-only. Filter state stays on the URL.
|
||||||
|
*
|
||||||
|
* A local `draft` mirrors the URL state so consecutive picks within the same
|
||||||
|
* RSC pending window apply cumulatively (a bare `state` prop would drop the
|
||||||
|
* first selection while the router.replace round-trip is in flight).
|
||||||
*/
|
*/
|
||||||
export const ActivityAgendaFilters = ({
|
export const ActivityAgendaFilters = ({
|
||||||
state,
|
state,
|
||||||
|
|
@ -45,8 +49,11 @@ export const ActivityAgendaFilters = ({
|
||||||
state,
|
state,
|
||||||
toHref: buildActivityAgendaHref,
|
toHref: buildActivityAgendaHref,
|
||||||
})
|
})
|
||||||
|
const [draft, setDraft] = useState(state)
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
|
|
||||||
|
useEffect(() => setDraft(state), [state])
|
||||||
|
|
||||||
const municipalityLabelsById = useMemo(() => {
|
const municipalityLabelsById = useMemo(() => {
|
||||||
const map = new Map<number, string>()
|
const map = new Map<number, string>()
|
||||||
for (const option of municipalityOptions) {
|
for (const option of municipalityOptions) {
|
||||||
|
|
@ -65,8 +72,8 @@ export const ActivityAgendaFilters = ({
|
||||||
)
|
)
|
||||||
|
|
||||||
const chips = useMemo(
|
const chips = useMemo(
|
||||||
() => buildActivityAgendaOmniboxChips({ state, municipalityLabelsById }),
|
() => buildActivityAgendaOmniboxChips({ state: draft, municipalityLabelsById }),
|
||||||
[state, municipalityLabelsById],
|
[draft, municipalityLabelsById],
|
||||||
)
|
)
|
||||||
|
|
||||||
const suggestionSeeds = useMemo(
|
const suggestionSeeds = useMemo(
|
||||||
|
|
@ -86,9 +93,11 @@ export const ActivityAgendaFilters = ({
|
||||||
const runAction = (action: ActivityAgendaOmniboxAction) => {
|
const runAction = (action: ActivityAgendaOmniboxAction) => {
|
||||||
if (action.kind === 'clear') {
|
if (action.kind === 'clear') {
|
||||||
setQuery('')
|
setQuery('')
|
||||||
|
setDraft({})
|
||||||
navigate({})
|
navigate({})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
setDraft(action.state)
|
||||||
navigate(action.state)
|
navigate(action.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,10 +112,10 @@ export const ActivityAgendaFilters = ({
|
||||||
onQueryChange={setQuery}
|
onQueryChange={setQuery}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
onSelectSuggestion={(suggestionId) => {
|
onSelectSuggestion={(suggestionId) => {
|
||||||
runAction(applyActivityAgendaOmniboxSuggestion({ state, suggestionId }))
|
runAction(applyActivityAgendaOmniboxSuggestion({ state: draft, suggestionId }))
|
||||||
}}
|
}}
|
||||||
onRemoveChip={(chipId) => {
|
onRemoveChip={(chipId) => {
|
||||||
runAction(removeActivityAgendaOmniboxChip({ state, chipId }))
|
runAction(removeActivityAgendaOmniboxChip({ state: draft, chipId }))
|
||||||
}}
|
}}
|
||||||
onClearAll={() => {
|
onClearAll={() => {
|
||||||
runAction(clearActivityAgendaOmnibox())
|
runAction(clearActivityAgendaOmnibox())
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { CalendarIcon } from 'lucide-react'
|
import { CalendarIcon } from 'lucide-react'
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CalendarFeedDialog,
|
CalendarFeedDialog,
|
||||||
|
|
@ -42,22 +42,27 @@ export const AgendaFeedChrome = ({
|
||||||
}
|
}
|
||||||
}, [setContext, openFeed])
|
}, [setContext, openFeed])
|
||||||
|
|
||||||
|
const headerButton = useMemo(
|
||||||
|
() => (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="size-11 hidden shrink-0 md:inline-flex"
|
||||||
|
aria-label="Link de import"
|
||||||
|
title={canGenerate ? 'Link de import' : 'Aplique filtros para gerar um link de import'}
|
||||||
|
disabled={!canGenerate}
|
||||||
|
onClick={openFeed}
|
||||||
|
>
|
||||||
|
<CalendarIcon className="size-5" aria-hidden />
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
[canGenerate, openFeed],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SetCampaignHeaderAction id="calendar-feed">
|
<SetCampaignHeaderAction id="calendar-feed">{headerButton}</SetCampaignHeaderAction>
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="size-11 hidden shrink-0 md:inline-flex"
|
|
||||||
aria-label="Link de import"
|
|
||||||
title={canGenerate ? 'Link de import' : 'Aplique filtros para gerar um link de import'}
|
|
||||||
disabled={!canGenerate}
|
|
||||||
onClick={openFeed}
|
|
||||||
>
|
|
||||||
<CalendarIcon className="size-5" aria-hidden />
|
|
||||||
</Button>
|
|
||||||
</SetCampaignHeaderAction>
|
|
||||||
|
|
||||||
<CalendarFeedDialog
|
<CalendarFeedDialog
|
||||||
open={open}
|
open={open}
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,6 @@ export const CalendarFeedDialog = ({
|
||||||
setTimeout(() => setCopied(false), 2000)
|
setTimeout(() => setCopied(false), 2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRevoke = async (feedId: number) => {
|
|
||||||
await onRevokeFeed(feedId)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleClose = (next: boolean) => {
|
const handleClose = (next: boolean) => {
|
||||||
if (next) return
|
if (next) return
|
||||||
setCreatedUrl(null)
|
setCreatedUrl(null)
|
||||||
|
|
@ -198,7 +194,7 @@ export const CalendarFeedDialog = ({
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => handleRevoke(feed.id)}
|
onClick={() => void onRevokeFeed(feed.id)}
|
||||||
aria-label={`Revogar feed ${feed.label}`}
|
aria-label={`Revogar feed ${feed.label}`}
|
||||||
>
|
>
|
||||||
<Trash2Icon className="h-4 w-4 text-muted-foreground" />
|
<Trash2Icon className="h-4 w-4 text-muted-foreground" />
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { ReactNode } from 'react'
|
import { Fragment, type ReactNode } from 'react'
|
||||||
|
|
||||||
import { CampaignAIHeaderButton } from '@/components/campaign/shell/ai/CampaignAIHeaderButton'
|
import { CampaignAIHeaderButton } from '@/components/campaign/shell/ai/CampaignAIHeaderButton'
|
||||||
import { useCampaignHeaderActions } from '@/components/campaign/shell/CampaignPageChromeContext'
|
import { useCampaignHeaderActions } from '@/components/campaign/shell/CampaignPageChromeContext'
|
||||||
|
|
@ -15,7 +15,9 @@ export const CampaignDesktopHeader = ({ notificationBell }: { notificationBell?:
|
||||||
<SidebarTrigger />
|
<SidebarTrigger />
|
||||||
<CampaignPageChromeDisplay layout="desktop" className="flex-1" />
|
<CampaignPageChromeDisplay layout="desktop" className="flex-1" />
|
||||||
<div className="ml-auto flex shrink-0 items-center gap-1">
|
<div className="ml-auto flex shrink-0 items-center gap-1">
|
||||||
{Object.values(headerActions)}
|
{Object.entries(headerActions).map(([id, node]) => (
|
||||||
|
<Fragment key={id}>{node}</Fragment>
|
||||||
|
))}
|
||||||
{notificationBell ?? null}
|
{notificationBell ?? null}
|
||||||
<CampaignAIHeaderButton />
|
<CampaignAIHeaderButton />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,10 @@ const OverlayActionsChrome = ({
|
||||||
label: action.label,
|
label: action.label,
|
||||||
icon: action.icon,
|
icon: action.icon,
|
||||||
description: action.description,
|
description: action.description,
|
||||||
href: action.href,
|
// Dialog-style actions win over a route when both are present
|
||||||
|
// (`CampaignHomeActionButton` renders the href branch without
|
||||||
|
// onClick, which would silently drop the action and the close).
|
||||||
|
href: action.onAction ? undefined : action.href,
|
||||||
onClick: action.onAction
|
onClick: action.onAction
|
||||||
? () => {
|
? () => {
|
||||||
action.onAction?.()
|
action.onAction?.()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export type ActivityAgendaOmniboxAction =
|
||||||
| { kind: 'url'; state: ActivityAgendaState }
|
| { kind: 'url'; state: ActivityAgendaState }
|
||||||
| { kind: 'clear' }
|
| { kind: 'clear' }
|
||||||
|
|
||||||
export type ActivityAgendaFilterOption = {
|
type ActivityAgendaFilterOption = {
|
||||||
value: string
|
value: string
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue