-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: added /explore/contents page * chore: added button on home page to redirect us to all contents page
- Loading branch information
Showing
16 changed files
with
730 additions
and
198 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
73 changes: 73 additions & 0 deletions
73
apps/client/app/modules/explore/contents/components/filter-bar.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,73 @@ | ||
import { AdjustmentsHorizontalIcon } from '@heroicons/react/24/outline' | ||
import { useSearchParams } from '@remix-run/react' | ||
import { useMemo } from 'react' | ||
import { Button } from '@/components/button/index.tsx' | ||
import { useDisclosure } from '@/hooks/use-disclosure.tsx' | ||
import { FiltersDialog } from '@/modules/search/components/filters-dialog/index.tsx' | ||
import { FilterByLicense } from '@/modules/search/components/license-select/index.tsx' | ||
import { FilterByOrientation } from '@/modules/search/components/orientation-select/index.tsx' | ||
|
||
export function FilterBar() { | ||
const filterModalState = useDisclosure() | ||
const [searchParams, setSearchParams] = useSearchParams() | ||
|
||
const showClearButton = | ||
searchParams.get('license') || searchParams.get('orientation') | ||
|
||
const clearFilters = () => { | ||
searchParams.delete('license') | ||
searchParams.delete('orientation') | ||
setSearchParams(searchParams) | ||
} | ||
|
||
const filterSize = useMemo(() => { | ||
let size = 0 | ||
if (searchParams.has('license')) { | ||
size++ | ||
} | ||
if (searchParams.has('orientation')) { | ||
size++ | ||
} | ||
|
||
return size | ||
}, [searchParams]) | ||
|
||
return ( | ||
<div> | ||
<div className="my-10 flex items-end justify-between"> | ||
<div> | ||
<div className="mb-3"> | ||
<h1 className="text-4xl font-black">All Contents</h1> | ||
</div> | ||
<p className="text-zinc-500 md:w-2/3"> | ||
mfoni offers millions of free, high-quality pictures. All pictures | ||
are free to download and use under the mfoni license. | ||
</p> | ||
</div> | ||
<div className="hidden flex-row items-center gap-3 lg:flex"> | ||
{showClearButton ? ( | ||
<button onClick={clearFilters} className="text-xs text-gray-500"> | ||
Clear | ||
</button> | ||
) : null} | ||
<FilterByLicense /> | ||
<FilterByOrientation /> | ||
</div> | ||
</div> | ||
<div className="mb-5 flex justify-end lg:hidden"> | ||
<Button | ||
onClick={filterModalState.onOpen} | ||
size="sm" | ||
color="secondaryGhost" | ||
> | ||
<AdjustmentsHorizontalIcon className="mr-2 h-auto w-5" /> Filters{' '} | ||
{filterSize > 0 ? `(${searchParams.size})` : ''} | ||
</Button> | ||
</div> | ||
<FiltersDialog | ||
isOpened={filterModalState.isOpened} | ||
onClose={filterModalState.onClose} | ||
/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { ArrowPathIcon } from '@heroicons/react/24/outline' | ||
import { useSearchParams } from '@remix-run/react' | ||
import { useMemo } from 'react' | ||
import { FilterBar } from './components/filter-bar.tsx' | ||
import { useGetContents } from '@/api/contents/index.ts' | ||
import { FadeIn, FadeInStagger } from '@/components/animation/FadeIn.tsx' | ||
import { Button } from '@/components/button/index.tsx' | ||
import { Content } from '@/components/Content/index.tsx' | ||
import { EmptyState } from '@/components/empty-state/index.tsx' | ||
import { ErrorState } from '@/components/error-state/index.tsx' | ||
import { Footer } from '@/components/footer/index.tsx' | ||
import { Header } from '@/components/layout/index.ts' | ||
import { Loader } from '@/components/loader/index.tsx' | ||
|
||
export const ContentsModule = () => { | ||
const [searchParams] = useSearchParams() | ||
|
||
const validateLicense = useMemo(() => { | ||
const base = searchParams.get('license') ?? 'ALL' | ||
|
||
if (['ALL', 'FREE', 'PREMIUM'].includes(base)) { | ||
return base | ||
} | ||
|
||
return 'ALL' | ||
}, [searchParams]) | ||
|
||
const validateOrientation = useMemo(() => { | ||
const base = searchParams.get('orientation') ?? 'ALL' | ||
|
||
if (['ALL', 'LANDSCAPE', 'PORTRAIT', 'SQUARE'].includes(base)) { | ||
return base | ||
} | ||
|
||
return 'ALL' | ||
}, [searchParams]) | ||
|
||
const { data, isPending, isError, refetch } = useGetContents({ | ||
query: { | ||
pagination: { page: 0, per: 50 }, | ||
filters: { | ||
license: validateLicense, | ||
orientation: validateOrientation, | ||
}, | ||
populate: ['content.createdBy'], | ||
}, | ||
}) | ||
|
||
let content = <></> | ||
|
||
if (isPending) { | ||
content = ( | ||
<div className="flex h-[50vh] flex-1 items-center justify-center"> | ||
<Loader /> | ||
</div> | ||
) | ||
} | ||
|
||
if (isError) { | ||
content = ( | ||
<div className="flex h-[50vh] flex-1 items-center justify-center"> | ||
<ErrorState | ||
message="An error occurred fetching contents." | ||
title="Something happened." | ||
> | ||
<Button isLink onClick={() => refetch()} variant="outlined"> | ||
<ArrowPathIcon | ||
aria-hidden="true" | ||
className="-ml-0.5 mr-1.5 size-5" | ||
/> | ||
Reload | ||
</Button> | ||
</ErrorState> | ||
</div> | ||
) | ||
} | ||
|
||
if (data && !data?.total) { | ||
content = ( | ||
<div className="flex h-[50vh] flex-1 items-center justify-center"> | ||
<EmptyState | ||
message={`There are no contents found`} | ||
title="No content found" | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
if (data?.total) { | ||
content = ( | ||
<FadeInStagger faster> | ||
<div className="columns-1 gap-2 sm:columns-2 sm:gap-4 md:columns-3 lg:columns-4 [&>img:not(:first-child)]:mt-8"> | ||
{data.rows.map((content) => ( | ||
<div className="mb-5" key={content.id}> | ||
<FadeIn> | ||
<Content content={content} /> | ||
</FadeIn> | ||
</div> | ||
))} | ||
</div> | ||
</FadeInStagger> | ||
) | ||
} | ||
|
||
return ( | ||
<div> | ||
<Header isHeroSearchInVisible={false} /> | ||
<div className="max-w-8xl mx-auto my-10 items-center px-3 sm:px-3 md:px-8"> | ||
<FilterBar /> | ||
{content} | ||
</div> | ||
<Footer /> | ||
</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
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
Oops, something went wrong.