-
Notifications
You must be signed in to change notification settings - Fork 63
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
1 parent
a717807
commit d38941a
Showing
7 changed files
with
75 additions
and
72 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export type SearchSort = | ||
| 'price_desc' | ||
| 'price_asc' | ||
| 'orders_desc' | ||
| 'name_desc' | ||
| 'name_asc' | ||
| 'release_desc' | ||
| 'discount_desc' | ||
| 'score_desc' | ||
|
||
export interface Facet { | ||
key: string | ||
value: string | ||
} | ||
|
||
export interface State { | ||
/** @description search sorting criteria */ | ||
sort: SearchSort | ||
/** | ||
* @description selected facets | ||
* */ | ||
selectedFacets: Facet[] | ||
/** @description full text term */ | ||
term: string | null | ||
/** | ||
* @description the base path url for the search context | ||
* */ | ||
base: string | ||
/** | ||
* @description current pagination cursor | ||
*/ | ||
page: number | ||
} |
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,28 @@ | ||
import type { State } from '../types' | ||
|
||
const format = (params: State): URL => { | ||
const url = new URL(params.base, 'http://localhost') | ||
const { page, selectedFacets, sort, term } = params | ||
|
||
if (term !== null) { | ||
url.searchParams.set('q', term) | ||
} | ||
|
||
const facets = new Set<string>() | ||
|
||
for (const facet of selectedFacets) { | ||
url.searchParams.append(facet.key, facet.value) | ||
facets.add(facet.key) | ||
} | ||
|
||
if (selectedFacets.length > 0) { | ||
url.searchParams.set('facets', Array.from(facets).join(',')) | ||
} | ||
|
||
url.searchParams.set('sort', sort) | ||
url.searchParams.set('page', page.toString()) | ||
|
||
return url | ||
} | ||
|
||
export default format |
d38941a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
faststore – ./
faststore-docs.vercel.app
faststore-faststore.vercel.app
faststore-git-main-faststore.vercel.app
faststore.dev
www.faststore.dev