From ccb6b02bf5d2ec6fc7640ee0adf2a81bb6fad564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Tue, 17 Oct 2023 11:44:32 +0300 Subject: [PATCH] @thunderstore/cyberstorm: replace CurrentFilters with CategoryTagCloud - Connect TagCloud to the data managed by PackageSearch and shared with CategoryMenu - PackageListing is still disconnected from this data source Refs TS-1860 --- .../CategoryTagCloud.module.css | 41 ++++++++++ .../CategoryTagCloud/CategoryTagCloud.tsx | 64 +++++++++++++++ .../PackageSearch/PackageSearch.tsx | 80 ++----------------- 3 files changed, 113 insertions(+), 72 deletions(-) create mode 100644 packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.module.css create mode 100644 packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.tsx diff --git a/packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.module.css b/packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.module.css new file mode 100644 index 000000000..0f7d5a6db --- /dev/null +++ b/packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.module.css @@ -0,0 +1,41 @@ +.root { + display: flex; + flex-flow: row wrap; + gap: var(--space--8); + list-style: none; +} + +.tag { + display: flex; + flex: none; + gap: var(--gap--4); + align-items: center; + justify-content: center; + padding: var(--space--6) var(--space--8); + border-radius: var(--border-radius--8); + color: var(--text-color); + font-weight: 700; + font-size: var(--font-size--s); + background-color: var(--bg-color); + + --text-color: var(--color-text--default); + --bg-color: var(--color-surface--5); +} + +.tag.exclude { + --text-color: var(--color-red--3); + --bg-color: var(--color-red--10); +} + +.icon { + height: var(--space--16); + color: var(--text-color); +} + +.tag.exclude .icon { + --text-color: var(--color-red--3); +} + +.clearAll { + margin-left: var(--space--4); +} diff --git a/packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.tsx b/packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.tsx new file mode 100644 index 000000000..ebf46ec1f --- /dev/null +++ b/packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.tsx @@ -0,0 +1,64 @@ +import { faXmark } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { Dispatch, SetStateAction } from "react"; + +import styles from "./CategoryTagCloud.module.css"; +import { CategorySelection, CATEGORY_STATES } from "../types"; +import * as Button from "../../Button"; +import { Icon } from "../../Icon/Icon"; + +const OFF = CATEGORY_STATES[0]; + +interface Props { + categories: CategorySelection[]; + setCategories: Dispatch>; +} + +/** + * Show currently selected category filters. + */ +export const CategoryTagCloud = (props: Props) => { + const { categories, setCategories } = props; + const visible = categories.filter((c) => c.selection !== "off"); + + if (!visible.length) { + return null; + } + + const clearCategory = (slug: string) => + setCategories( + categories.map((c) => (c.slug === slug ? { ...c, selection: OFF } : c)) + ); + + const clearAll = () => + setCategories(categories.map((c) => ({ ...c, selection: OFF }))); + + return ( +
    + {visible.map((c) => ( +
  1. + {c.name} + clearCategory(c.slug)} + colorScheme="transparentDefault" + paddingSize="none" + > + + + + + + +
  2. + ))} + +
  3. + + Clear all + +
  4. +
+ ); +}; + +CategoryTagCloud.displayName = "CategoryTagCloud"; diff --git a/packages/cyberstorm/src/components/PackageSearch/PackageSearch.tsx b/packages/cyberstorm/src/components/PackageSearch/PackageSearch.tsx index d3df288bc..6d69f14d8 100644 --- a/packages/cyberstorm/src/components/PackageSearch/PackageSearch.tsx +++ b/packages/cyberstorm/src/components/PackageSearch/PackageSearch.tsx @@ -4,7 +4,6 @@ import { faSearch, faStar, faThumbsUp, - faXmark, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { PackageCategory } from "@thunderstore/dapper/types"; @@ -12,14 +11,13 @@ import { Suspense, useState, createContext } from "react"; import { useDebounce } from "use-debounce"; import { CategoryMenu } from "./CategoryMenu/CategoryMenu"; +import { CategoryTagCloud } from "./CategoryTagCloud/CategoryTagCloud"; import styles from "./PackageSearch.module.css"; import { CategorySelection } from "./types"; -import * as Button from "../Button/"; import { Icon } from "../Icon/Icon"; import { Pagination } from "../Pagination/Pagination"; import { PackageList } from "../PackageList/PackageList"; import { Select } from "../Select/Select"; -import { Tag } from "../Tag/Tag"; import { TextInput } from "../TextInput/TextInput"; interface CategoriesProps { @@ -52,48 +50,6 @@ export function FiltersProvider(props: ContextProps) { ); } -const RemoveFilterIcon = (onClick: () => void) => ( - -); - -interface TagListProps { - filters: Filters; -} - -function CurrentFilters(props: TagListProps) { - const { filters } = props; - - function removeFilter(key: string) { - const cats = { ...filters.availableCategories }; - Object.values(cats).forEach((c) => { - if (c.label === key) { - c.value = undefined; - } - }); - - filters.setAvailableCategories(cats); - } - - return ( - <> - {Object.values(filters.availableCategories) - .filter((category) => category.value !== undefined) - .map((cat, index) => ( - removeFilter(cat.label))} - colorScheme="borderless_removable" - /> - ))} - - ); -} - interface Props { communityId?: string; packageCategories: PackageCategory[]; @@ -123,14 +79,6 @@ export function PackageSearch(props: Props) { .map((c) => ({ ...c, selection: "off" })) ); - const clearFilters = () => { - setSearchValue(""); - - const cats = { ...filters.availableCategories }; - Object.values(cats).forEach((cat) => (cat.value = undefined)); - filters.setAvailableCategories(cats); - }; - return (
} /> +
+
+ +
{/* TODO: use real values */} Showing 1-20 of 327 results @@ -157,25 +112,6 @@ export function PackageSearch(props: Props) { : ""}
- {Object.keys(filters.availableCategories).some( - (k) => filters.availableCategories[k].value !== undefined - ) ? ( -
- - - - Clear all - - -
- ) : null} -