Skip to content

Commit

Permalink
fix(anime-filters): add group separator to genres
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed May 11, 2024
1 parent df4d987 commit c3c9f37
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
45 changes: 27 additions & 18 deletions components/filters/anime-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import clsx from 'clsx';
import * as React from 'react';
import { FC, useEffect, useState } from 'react';
import { FC, Fragment, useEffect, useState } from 'react';
import AntDesignClearOutlined from '~icons/ant-design/clear-outlined';
import MaterialSymbolsSortRounded from '~icons/material-symbols/sort-rounded';

Expand All @@ -13,19 +13,19 @@ import { useQuery } from '@tanstack/react-query';
import BadgeFilter from '@/components/filters/components/ui/badge-filter';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { ScrollArea } from '@/components/ui/scroll-area';
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectList,
SelectSearch,
SelectSeparator,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Slider } from '@/components/ui/slider';
import { Switch } from '@/components/ui/switch';
import getAnimeGenres from '@/services/api/anime/getAnimeGenres';
import {
AGE_RATING,
Expand All @@ -37,6 +37,8 @@ import {
import createQueryString from '@/utils/createQueryString';
import { cn } from '@/utils/utils';

import { Switch } from '../ui/switch';

const YEARS: [number, number] = [1965, new Date().getFullYear()];

interface Props {
Expand Down Expand Up @@ -222,21 +224,27 @@ const AnimeFilters: FC<Props> = ({ className, type }) => {
Object.keys(
genresList,
) as API.GenreType[]
).map((type) => (
<SelectGroup
heading={GENRE_TYPES[type].title_ua}
key={type}
>
{genresList[type].map((genre) => (
<SelectItem
key={genre.slug}
value={genre.slug}
>
{genre.name_ua ||
genre.name_en}
</SelectItem>
))}
</SelectGroup>
).map((type, index) => (
<Fragment key={type}>
{index !== 0 && <SelectSeparator />}
<SelectGroup
heading={
GENRE_TYPES[type].title_ua
}
>
{genresList[type].map(
(genre) => (
<SelectItem
key={genre.slug}
value={genre.slug}
>
{genre.name_ua ||
genre.name_en}
</SelectItem>
),
)}
</SelectGroup>
</Fragment>
))}
</SelectList>
</SelectContent>
Expand Down Expand Up @@ -326,6 +334,7 @@ const AnimeFilters: FC<Props> = ({ className, type }) => {
>
<AntDesignClearOutlined /> Очистити
</Button>
; ;
</ScrollArea>
);
};
Expand Down
25 changes: 16 additions & 9 deletions components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ const SelectTrigger = React.forwardRef<
data-disabled={disabled}
{...props}
className={cn(
!asChild && buttonVariants({ variant: 'outline', size: 'default' }),
!asChild && 'flex h-auto min-h-12 items-center justify-between',
!asChild &&
buttonVariants({ variant: 'outline', size: 'default' }),
!asChild &&
'flex h-auto min-h-12 items-center justify-between',
disabled ? 'cursor-not-allowed opacity-50' : 'cursor-text',
className,
)}
Expand Down Expand Up @@ -310,7 +312,7 @@ const SelectValue = React.forwardRef<
if (!multiple) {
const item = itemCache ? itemCache[value[0]] : undefined;

console.log(item)
console.log(item);

return (
<Fragment>
Expand Down Expand Up @@ -490,6 +492,7 @@ type SelectItemProps = ComponentPropsWithoutRef<typeof CommandItem> &
Partial<SelectOptionItem> & {
onSelect?: (value: string, item: SelectOptionItem) => void;
onDeselect?: (value: string, item: SelectOptionItem) => void;
disableCheckbox?: boolean;
};

const SelectItem = React.forwardRef<
Expand All @@ -505,6 +508,7 @@ const SelectItem = React.forwardRef<
label,
disabled: disabledProp,
className,
disableCheckbox,
...props
},
forwardedRef,
Expand All @@ -522,9 +526,7 @@ const SelectItem = React.forwardRef<
return value
? {
value,
label:
label ||
children,
label: label || children,
}
: undefined;
}, [value, label, children]);
Expand Down Expand Up @@ -570,9 +572,14 @@ const SelectItem = React.forwardRef<
onSelect={!disabled && value ? handleClick : undefined}
ref={forwardedRef}
>
<span className="size-4">
<Checkbox className="border-secondary" checked={selected} />
</span>
{!disableCheckbox && (
<span className="size-4">
<Checkbox
className="border-secondary"
checked={selected}
/>
</span>
)}

<span className="truncate">{children || label || value}</span>
</CommandItem>
Expand Down
6 changes: 1 addition & 5 deletions components/watchlist-button/watchlist-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ const SETTINGS_BUTTON = {
),
value: 'settings',
disableCheckbox: true,
separator: true,
title: 'Налаштування',
group: {
value: 'settings',
},
};

const OPTIONS = [
Expand Down Expand Up @@ -141,7 +137,7 @@ const Component = ({ slug, additional, disabled }: Props) => {
{watch && !watchError && (
<SelectGroup>
{watch && !watchError && (
<SelectItem value="settings">
<SelectItem disableCheckbox value="settings">
{SETTINGS_BUTTON.label}
</SelectItem>
)}
Expand Down

0 comments on commit c3c9f37

Please sign in to comment.