|
|
@ -2,10 +2,13 @@ import {
|
|
|
|
AdjustmentsHorizontalIcon,
|
|
|
|
AdjustmentsHorizontalIcon,
|
|
|
|
MagnifyingGlassIcon,
|
|
|
|
MagnifyingGlassIcon,
|
|
|
|
} from '@heroicons/react/24/outline';
|
|
|
|
} from '@heroicons/react/24/outline';
|
|
|
|
import { Button, TextInput } from '@tih/ui';
|
|
|
|
import { Button, Tabs, TextInput } from '@tih/ui';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { SORT_ORDERS } from '~/utils/questions/constants';
|
|
|
|
|
|
|
|
|
|
|
|
import type { SortOptionsSelectProps } from './SortOptionsSelect';
|
|
|
|
import type { SortOptionsSelectProps } from './SortOptionsSelect';
|
|
|
|
import SortOptionsSelect from './SortOptionsSelect';
|
|
|
|
|
|
|
|
|
|
|
|
import { SortOrder, SortType } from '~/types/questions.d';
|
|
|
|
|
|
|
|
|
|
|
|
export type QuestionSearchBarProps = SortOptionsSelectProps & {
|
|
|
|
export type QuestionSearchBarProps = SortOptionsSelectProps & {
|
|
|
|
onFilterOptionsToggle: () => void;
|
|
|
|
onFilterOptionsToggle: () => void;
|
|
|
@ -13,6 +16,22 @@ export type QuestionSearchBarProps = SortOptionsSelectProps & {
|
|
|
|
query: string;
|
|
|
|
query: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getSortOrderLabel(sortOrder: SortOrder, sortType: SortType): string {
|
|
|
|
|
|
|
|
switch (sortType) {
|
|
|
|
|
|
|
|
case SortType.NEW:
|
|
|
|
|
|
|
|
return sortOrder === SortOrder.ASC ? 'Oldest first' : 'Newest first';
|
|
|
|
|
|
|
|
case SortType.TOP:
|
|
|
|
|
|
|
|
return sortOrder === SortOrder.ASC
|
|
|
|
|
|
|
|
? 'Least upvotes first'
|
|
|
|
|
|
|
|
: 'Most upvotes first';
|
|
|
|
|
|
|
|
case SortType.ENCOUNTERS:
|
|
|
|
|
|
|
|
return sortOrder === SortOrder.ASC
|
|
|
|
|
|
|
|
? 'Least received first'
|
|
|
|
|
|
|
|
: 'Most received first';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function QuestionSearchBar({
|
|
|
|
export default function QuestionSearchBar({
|
|
|
|
onFilterOptionsToggle,
|
|
|
|
onFilterOptionsToggle,
|
|
|
|
onQueryChange,
|
|
|
|
onQueryChange,
|
|
|
@ -20,44 +39,75 @@ export default function QuestionSearchBar({
|
|
|
|
...sortOptionsSelectProps
|
|
|
|
...sortOptionsSelectProps
|
|
|
|
}: QuestionSearchBarProps) {
|
|
|
|
}: QuestionSearchBarProps) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="flex flex-col items-stretch gap-x-4 gap-y-4 lg:flex-row lg:items-end">
|
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
<div className="flex flex-1 gap-2">
|
|
|
|
<div className="flex flex-col items-stretch gap-x-2 gap-y-4 lg:flex-row lg:items-end">
|
|
|
|
<div className="flex-1">
|
|
|
|
<div className="flex flex-1 gap-2">
|
|
|
|
<TextInput
|
|
|
|
<div className="flex-1">
|
|
|
|
isLabelHidden={true}
|
|
|
|
<TextInput
|
|
|
|
label="Search by content"
|
|
|
|
isLabelHidden={true}
|
|
|
|
placeholder="Search by content"
|
|
|
|
label="Search by content"
|
|
|
|
startAddOn={MagnifyingGlassIcon}
|
|
|
|
placeholder="Search by content"
|
|
|
|
startAddOnType="icon"
|
|
|
|
startAddOn={MagnifyingGlassIcon}
|
|
|
|
value={query}
|
|
|
|
startAddOnType="icon"
|
|
|
|
onChange={(value) => {
|
|
|
|
value={query}
|
|
|
|
onQueryChange(value);
|
|
|
|
onChange={(value) => {
|
|
|
|
}}
|
|
|
|
onQueryChange(value);
|
|
|
|
/>
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="sm:hidden">
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
|
|
addonPosition="start"
|
|
|
|
|
|
|
|
icon={AdjustmentsHorizontalIcon}
|
|
|
|
|
|
|
|
isLabelHidden={true}
|
|
|
|
|
|
|
|
label="Filters"
|
|
|
|
|
|
|
|
variant="tertiary"
|
|
|
|
|
|
|
|
onClick={onFilterOptionsToggle}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="hidden sm:block lg:hidden">
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
|
|
addonPosition="start"
|
|
|
|
|
|
|
|
icon={AdjustmentsHorizontalIcon}
|
|
|
|
|
|
|
|
label="Filters"
|
|
|
|
|
|
|
|
variant="tertiary"
|
|
|
|
|
|
|
|
onClick={onFilterOptionsToggle}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="sm:hidden">
|
|
|
|
{/* <SortOptionsSelect {...sortOptionsSelectProps} /> */}
|
|
|
|
<Button
|
|
|
|
</div>
|
|
|
|
addonPosition="start"
|
|
|
|
<div className="flex justify-start gap-4">
|
|
|
|
icon={AdjustmentsHorizontalIcon}
|
|
|
|
<div>
|
|
|
|
isLabelHidden={true}
|
|
|
|
<Tabs
|
|
|
|
label="Filters"
|
|
|
|
label="Sort by"
|
|
|
|
variant="tertiary"
|
|
|
|
tabs={sortOptionsSelectProps.sortTypeOptions ?? []}
|
|
|
|
onClick={onFilterOptionsToggle}
|
|
|
|
value={sortOptionsSelectProps.sortTypeValue}
|
|
|
|
|
|
|
|
onChange={sortOptionsSelectProps.onSortTypeChange}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="hidden sm:block lg:hidden">
|
|
|
|
<div className="border-l" />
|
|
|
|
<Button
|
|
|
|
<div>
|
|
|
|
addonPosition="start"
|
|
|
|
<Tabs
|
|
|
|
icon={AdjustmentsHorizontalIcon}
|
|
|
|
label="Order by"
|
|
|
|
label="Filters"
|
|
|
|
tabs={(sortOptionsSelectProps.sortOrderOptions ?? SORT_ORDERS).map(
|
|
|
|
variant="tertiary"
|
|
|
|
(option) => {
|
|
|
|
onClick={onFilterOptionsToggle}
|
|
|
|
const newLabel = getSortOrderLabel(
|
|
|
|
|
|
|
|
option.value,
|
|
|
|
|
|
|
|
sortOptionsSelectProps.sortTypeValue,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...option,
|
|
|
|
|
|
|
|
label: newLabel,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
value={sortOptionsSelectProps.sortOrderValue}
|
|
|
|
|
|
|
|
onChange={sortOptionsSelectProps.onSortOrderChange}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-end justify-end gap-4">
|
|
|
|
|
|
|
|
<SortOptionsSelect {...sortOptionsSelectProps} />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|