Skip to content

Commit

Permalink
use horizontal list for recipe tag filter
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jul 14, 2024
1 parent c3e3fdc commit 734cfa2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
11 changes: 6 additions & 5 deletions apps/gnocchi/web/src/components/addBar/AddPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AddToListDialog } from '@/components/recipes/viewer/AddToListDialog.jsx
import useMergedRef from '@/hooks/useMergedRef.js';
import { Input } from '@a-type/ui/components/input';
import { useSize } from '@a-type/ui/hooks';
import { isUrl } from '@a-type/utils';
import { isUrl, stopPropagation } from '@a-type/utils';
import { showSubscriptionPromotion, useCanSync } from '@biscuits/client';
import { Recipe } from '@gnocchi.biscuits/verdant';
import classNames from 'classnames';
Expand All @@ -30,6 +30,7 @@ import {
useAddBarSuggestions,
} from './hooks.js';
import { AddBarProps } from './AddBar.jsx';
import { ScrollArea } from '@a-type/ui/components/scrollArea';

const AddPaneImpl = forwardRef<
HTMLDivElement,
Expand Down Expand Up @@ -132,12 +133,12 @@ const AddPaneImpl = forwardRef<
disableInteraction={disabled}
{...rest}
/>
<div
<ScrollArea
{...menuProps}
className={classNames(
'flex flex-col overflow-x-hidden overflow-y-auto overscroll-contain max-h-[calc(var(--viewport-height,40vh)-80px)] lg:max-h-50vh w-full max-w-none gap-4 p-3',
'flex flex-col max-h-[calc(var(--viewport-height,40vh)-80px)] lg:max-h-50vh w-full max-w-none gap-4 p-3',
)}
onScroll={console.log}
onScroll={stopPropagation}
>
{showSuggested && (
<SuggestionGroup
Expand All @@ -164,7 +165,7 @@ const AddPaneImpl = forwardRef<
/>
)}
{noSuggestions && <div>No suggestions</div>}
</div>
</ScrollArea>
{addingRecipe && (
<AddToListDialog
recipe={addingRecipe}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { RecipeTagsList } from './RecipeTagsList.jsx';
import classNames from 'classnames';
import { RecipePresenceNotification } from '@/components/sync/collaborationMenu/RecipePresenceNotification.jsx';
import { RecipeTagsFilter } from './RecipeTagsFilter.jsx';

export interface RecipeListProps {}

Expand Down Expand Up @@ -104,11 +105,10 @@ function TagFilterList() {
tagFilter ? setTagFilter(null) : setTagFilter(value);

return (
<RecipeTagsList
<RecipeTagsFilter
onSelect={toggleTagFilter}
selectedValues={tagFilter ? [tagFilter] : []}
onlySelected
className="mb-4 font-normal text-xs"
className="mb-1 font-normal text-xs"
buttonClassName="py-1 px-2 text-xs"
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Icon } from '@/components/icons/Icon.jsx';
import { RecipeTagMenuWrapper } from '@/components/recipes/tags/RecipeTagMenuWrapper.jsx';
import { hooks } from '@/stores/groceries/index.js';
import { Button, ButtonProps } from '@a-type/ui/components/button';
import { HorizontalList } from '@a-type/ui/components/horizontalList';
import classNames from 'classnames';
import { forwardRef } from 'react';

export function RecipeTagsFilter({
onSelect,
selectedValues = [],
className,
buttonClassName,
}: {
onSelect: (name: string | null) => void;
selectedValues?: string[] | null;
className?: string;
buttonClassName?: string;
}) {
const allTags = hooks.useAllRecipeTagMetadata();
const filteredByOmit = allTags.filter((tag) => {
if (selectedValues?.length) {
return selectedValues.includes(tag.get('name'));
}
return true;
});

if (allTags.length === 0) {
return null;
}

return (
<HorizontalList className={className}>
{filteredByOmit.map((tag) => (
<RecipeTagMenuWrapper tagName={tag.get('name')} key={tag.get('name')}>
<TagButtonBase
toggled={!!selectedValues?.includes(tag.get('name'))}
onClick={() => onSelect(tag.get('name'))}
className={classNames(
'my-auto',
tag.get('color') && `theme-${tag.get('color')}`,
buttonClassName,
)}
>
<span>{tag.get('icon') ?? <Icon name="tag" />}</span>
<span>{tag.get('name')}</span>
</TagButtonBase>
</RecipeTagMenuWrapper>
))}
</HorizontalList>
);
}

const TagButtonBase = forwardRef<HTMLButtonElement, ButtonProps>(
function TagButtonBase({ className, ...props }, ref) {
return (
<Button
ref={ref}
size="small"
color="primary"
{...props}
className={classNames(
'flex items-center gap-1 [font-weight:inherit] [font-size:inherit]',
className,
)}
/>
);
},
);

0 comments on commit 734cfa2

Please sign in to comment.