diff --git a/apps/remix/app/components/general/document/document-search.tsx b/apps/remix/app/components/general/document/document-search.tsx
index 9079be8f8..bb0819008 100644
--- a/apps/remix/app/components/general/document/document-search.tsx
+++ b/apps/remix/app/components/general/document/document-search.tsx
@@ -2,38 +2,24 @@ import { useDebouncedValue } from '@documenso/lib/client-only/hooks/use-debounce
import { Input } from '@documenso/ui/primitives/input';
import { msg } from '@lingui/core/macro';
import { useLingui } from '@lingui/react';
-import { useCallback, useEffect, useState } from 'react';
-import { useSearchParams } from 'react-router';
+import { useQueryState } from 'nuqs';
+import { useEffect, useState } from 'react';
-export const DocumentSearch = ({ initialValue = '' }: { initialValue?: string }) => {
+import { documentsSearchParams } from '~/utils/documents-search-params';
+
+export const DocumentSearch = () => {
const { _ } = useLingui();
- const [searchParams, setSearchParams] = useSearchParams();
+ const [query, setQuery] = useQueryState('query', documentsSearchParams.query);
- const [searchTerm, setSearchTerm] = useState(initialValue);
+ const [searchTerm, setSearchTerm] = useState(query ?? '');
const debouncedSearchTerm = useDebouncedValue(searchTerm, 500);
- const handleSearch = useCallback(
- (term: string) => {
- const params = new URLSearchParams(searchParams?.toString() ?? '');
- if (term) {
- params.set('query', term);
- } else {
- params.delete('query');
- }
-
- setSearchParams(params);
- },
- [searchParams],
- );
-
useEffect(() => {
- const currentQueryParam = searchParams.get('query') || '';
-
- if (debouncedSearchTerm !== currentQueryParam) {
- handleSearch(debouncedSearchTerm);
+ if (debouncedSearchTerm !== (query ?? '')) {
+ void setQuery(debouncedSearchTerm || null);
}
- }, [debouncedSearchTerm, searchParams]);
+ }, [debouncedSearchTerm, query, setQuery]);
return (
void;
+ selectedLabel?: ReactNode;
+};
+
+export type FilterPillMultipleProps = FilterPillCommonProps & {
+ multiple: true;
+ value: string[];
+ onChange: (value: string[]) => void;
+};
+
+export type FilterPillProps = FilterPillSingleProps | FilterPillMultipleProps;
+
+/**
+ * A faceted filter pill.
+ *
+ * Renders as a dashed "add a filter" pill at rest, and shows the current
+ * selection inline once a value is picked. Selecting the active option
+ * again (or the Clear row) removes it.
+ *
+ * Single select by default, closing on pick. When `multiple` is set the
+ * popover stays open for toggling, and the trigger shows the first two
+ * selections followed by a "+N more" chip.
+ */
+export const FilterPill = (props: FilterPillProps) => {
+ const { icon: Icon, label, options, enableSearch, searchPlaceholder, loading, testId } = props;
+
+ const [open, setOpen] = useState(false);
+
+ const selectedValues = props.multiple ? props.value : props.value === null ? [] : [props.value];
+
+ const selectedOptions = selectedValues
+ .map((value) => options.find((option) => option.value === value))
+ .filter((option): option is FilterPillOption => option !== undefined);
+
+ const hasSelection = selectedOptions.length > 0;
+ const extraCount = selectedOptions.length - 2;
+
+ const onSelect = (nextValue: string) => {
+ if (props.multiple) {
+ const newValues = selectedValues.includes(nextValue)
+ ? selectedValues.filter((value) => value !== nextValue)
+ : [...selectedValues, nextValue];
+
+ props.onChange(newValues);
+ return;
+ }
+
+ props.onChange(nextValue === props.value ? null : nextValue);
+ setOpen(false);
+ };
+
+ const onClear = () => {
+ if (props.multiple) {
+ props.onChange([]);
+ } else {
+ props.onChange(null);
+ }
+
+ setOpen(false);
+ };
+
+ return (
+