|
|
@ -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,7 +39,8 @@ 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-col items-stretch gap-x-2 gap-y-4 lg:flex-row lg:items-end">
|
|
|
|
<div className="flex flex-1 gap-2">
|
|
|
|
<div className="flex flex-1 gap-2">
|
|
|
|
<div className="flex-1">
|
|
|
|
<div className="flex-1">
|
|
|
|
<TextInput
|
|
|
|
<TextInput
|
|
|
@ -55,8 +75,38 @@ export default function QuestionSearchBar({
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-end justify-end gap-4">
|
|
|
|
{/* <SortOptionsSelect {...sortOptionsSelectProps} /> */}
|
|
|
|
<SortOptionsSelect {...sortOptionsSelectProps} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex justify-start gap-4">
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
<Tabs
|
|
|
|
|
|
|
|
label="Sort by"
|
|
|
|
|
|
|
|
tabs={sortOptionsSelectProps.sortTypeOptions ?? []}
|
|
|
|
|
|
|
|
value={sortOptionsSelectProps.sortTypeValue}
|
|
|
|
|
|
|
|
onChange={sortOptionsSelectProps.onSortTypeChange}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="border-l" />
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
<Tabs
|
|
|
|
|
|
|
|
label="Order by"
|
|
|
|
|
|
|
|
tabs={(sortOptionsSelectProps.sortOrderOptions ?? SORT_ORDERS).map(
|
|
|
|
|
|
|
|
(option) => {
|
|
|
|
|
|
|
|
const newLabel = getSortOrderLabel(
|
|
|
|
|
|
|
|
option.value,
|
|
|
|
|
|
|
|
sortOptionsSelectProps.sortTypeValue,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
...option,
|
|
|
|
|
|
|
|
label: newLabel,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
value={sortOptionsSelectProps.sortOrderValue}
|
|
|
|
|
|
|
|
onChange={sortOptionsSelectProps.onSortOrderChange}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|