-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
103 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
apps/cyberstorm-nextjs/app/communities/@searchAndOrder/SearchAndOrder.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.root { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--gap--16); | ||
} | ||
|
||
.searchTextInput { | ||
width: 100%; | ||
} | ||
|
||
@media (min-width: 40rem) { | ||
.searchTextInput { | ||
width: 50%; | ||
} | ||
|
||
.root { | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
} | ||
|
||
.searchFilters { | ||
display: flex; | ||
flex: 1 1 auto; | ||
gap: var(--gap--16); | ||
align-content: center; | ||
justify-content: flex-end; | ||
} | ||
|
||
.searchFiltersSortLabel { | ||
align-self: center; | ||
color: var(--color-text--tertiary); | ||
font-weight: var(--font-weight-bold); | ||
} |
94 changes: 94 additions & 0 deletions
94
apps/cyberstorm-nextjs/app/communities/@searchAndOrder/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use client"; | ||
import styles from "./SearchAndOrder.module.css"; | ||
import { TextInput, Select } from "@thunderstore/cyberstorm"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { useDebounce } from "use-debounce"; | ||
|
||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { | ||
faSearch, | ||
faArrowDownAZ, | ||
faStar, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { faFire } from "@fortawesome/pro-solid-svg-icons"; | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
enum SortOptions { | ||
Name = "name", | ||
Latest = "-datetime_created", | ||
Popular = "-aggregated_fields__download_count", | ||
} | ||
|
||
export default function Page() { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
|
||
const createQueryString = useCallback( | ||
(name: string, value: string, isDefault?: boolean) => { | ||
const params = new URLSearchParams(searchParams.toString()); | ||
if (isDefault || value.length === 0) { | ||
params.delete(name); | ||
} else { | ||
params.set(name, value); | ||
} | ||
|
||
return params.toString(); | ||
}, | ||
[searchParams] | ||
); | ||
|
||
const [order, setOrder] = useState(SortOptions.Popular); | ||
|
||
const changeOrder = (v: SortOptions) => { | ||
setOrder(v); | ||
router.push( | ||
pathname + "?" + createQueryString("order", v, v === SortOptions.Popular) | ||
); | ||
}; | ||
|
||
const [searchValue, setSearchValue] = useState(""); | ||
const [debouncedSearchValue] = useDebounce(searchValue, 300); | ||
|
||
useEffect(() => { | ||
router.push( | ||
pathname + "?" + createQueryString("search", debouncedSearchValue) | ||
); | ||
}, [createQueryString, debouncedSearchValue, pathname, router]); | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<div className={styles.searchTextInput}> | ||
<TextInput | ||
onChange={(e) => setSearchValue(e.target.value)} | ||
value={searchValue} | ||
placeholder="Search communities..." | ||
leftIcon={<FontAwesomeIcon icon={faSearch} />} | ||
/> | ||
</div> | ||
<div className={styles.searchFilters}> | ||
<div className={styles.searchFiltersSortLabel}>Sort by</div> | ||
<Select onChange={changeOrder} options={selectOptions} value={order} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const selectOptions = [ | ||
{ | ||
value: SortOptions.Name, | ||
label: "Name", | ||
leftIcon: <FontAwesomeIcon icon={faArrowDownAZ} />, | ||
}, | ||
{ | ||
value: SortOptions.Latest, | ||
label: "Latest", | ||
leftIcon: <FontAwesomeIcon icon={faStar} />, | ||
}, | ||
{ | ||
value: SortOptions.Popular, | ||
label: "Popular", | ||
leftIcon: <FontAwesomeIcon icon={faFire} />, | ||
}, | ||
]; |
5 changes: 5 additions & 0 deletions
5
apps/cyberstorm-nextjs/app/communities/@searchAndOrder/searchAndOrderSkeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import styles from "./SearchAndOrder.module.css"; | ||
|
||
export const SearchAndOrderSkeleton = () => { | ||
return <div className={styles.root}>TODO: SKELETON</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters