Skip to content

Commit

Permalink
feat: Added glass and garnish col to manage cocktail view (#378)
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Groß <mail@gross-johannes.de>
  • Loading branch information
jo-gross authored Aug 23, 2024
1 parent fef5ea8 commit 1fbf183
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions models/CocktailRecipeModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import { Prisma } from '@prisma/client';
export type CocktailRecipeModel = Prisma.CocktailRecipeGetPayload<{
include: {
_count: { select: { CocktailRecipeImage: true } };
glass: true;
garnishes: { include: { garnish: true } };
};
}>;
37 changes: 23 additions & 14 deletions pages/workspaces/[workspaceId]/manage/cocktails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export default function CocktailsOverviewPage() {
refreshCocktails();
}, [refreshCocktails]);

const cocktailFilter = useCallback((filterString: string) => {
const lowerCaseFilterString = filterString.toLowerCase();

return function (cocktailRecipe: CocktailRecipeModel): boolean {
return (
cocktailRecipe.name.toLowerCase().includes(lowerCaseFilterString) ||
cocktailRecipe.glass?.name.toLowerCase().includes(lowerCaseFilterString) ||
cocktailRecipe.garnishes.some((garnish) => garnish.garnish.name.toLowerCase().includes(lowerCaseFilterString)) ||
cocktailRecipe.tags.some((tag) => tag.toLowerCase().includes(lowerCaseFilterString))
);
};
}, []);

return (
<ManageEntityLayout
backLink={`/workspaces/${workspaceId}/manage`}
Expand All @@ -73,10 +86,12 @@ export default function CocktailsOverviewPage() {
<table className="table table-zebra w-full">
<thead>
<tr>
<th className=""></th>
<th className="">Name</th>
<th className="">Preis</th>
<th className="">Tags</th>
<th></th>
<th>Name</th>
<th>Preis</th>
<th>Tags</th>
<th>Glas</th>
<th>Garnitur(en)</th>
<th className="flex justify-end"></th>
</tr>
</thead>
Expand All @@ -87,23 +102,15 @@ export default function CocktailsOverviewPage() {
<Loading />
</td>
</tr>
) : cocktailRecipes.filter(
(cocktailRecipe) =>
cocktailRecipe.name.toLowerCase().includes(filterString.toLowerCase()) ||
cocktailRecipe.tags.some((tag) => tag.toLowerCase().includes(filterString.toLowerCase())),
).length == 0 ? (
) : cocktailRecipes.filter(cocktailFilter(filterString)).length == 0 ? (
<tr>
<td colSpan={5} className={'text-center'}>
Keine Einträge gefunden
</td>
</tr>
) : (
cocktailRecipes
.filter(
(cocktailRecipe) =>
cocktailRecipe.name.toLowerCase().includes(filterString.toLowerCase()) ||
cocktailRecipe.tags.some((tag) => tag.toLowerCase().includes(filterString.toLowerCase())),
)
.filter(cocktailFilter(filterString))
.sort((a, b) => a.name.localeCompare(b.name))
.map((cocktailRecipe) => (
<tr key={cocktailRecipe.id} className={''}>
Expand Down Expand Up @@ -138,6 +145,8 @@ export default function CocktailsOverviewPage() {
</div>
))}
</td>
<td>{cocktailRecipe.glass?.name}</td>
<td>{cocktailRecipe.garnishes.map((garnish) => garnish.garnish.name).join(', ')}</td>
<ManageColumn entity={'cocktails'} id={cocktailRecipe.id} onRefresh={refreshCocktails} />
</tr>
))
Expand Down

0 comments on commit 1fbf183

Please sign in to comment.