-
Notifications
You must be signed in to change notification settings - Fork 116
Explore page #5179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Explore page #5179
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c83434d
feat: Add template for explore page (#5170)
steverydz d17484d
feat: Add recommended snap sections to explore page (#5173)
steverydz 87cce4e
feat: Add editorial slices to explore page (#5178)
steverydz 52152b5
Add new slice on explore page
steverydz 6838549
Comment out explore page slices until ready
steverydz b54c871
Linting fixes
steverydz 1fc12b9
Co-pilot code review fix
steverydz a691945
Use 25% rather than thirds on explore page
steverydz 733569b
Fix heading spacing on explore page
steverydz 1654963
Update search placeholder text
steverydz 6af2a12
Remove duplicate navigation styles
steverydz be7c917
Merge branch 'main' into explore-page
steverydz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import usePackages from "./usePackages"; | ||
import useCategories from "./useCategories"; | ||
|
||
export { usePackages }; | ||
export { usePackages, useCategories }; |
This file contains hidden or 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,20 @@ | ||
import { useQuery } from "react-query"; | ||
|
||
function useCategories() { | ||
return useQuery({ | ||
queryKey: ["categories"], | ||
queryFn: async () => { | ||
const response = await fetch("/store.json"); | ||
|
||
if (!response.ok) { | ||
throw new Error("There was a problem fetching categories"); | ||
} | ||
|
||
const responseData = await response.json(); | ||
|
||
return responseData.categories; | ||
}, | ||
}); | ||
} | ||
|
||
export default useCategories; |
This file contains hidden or 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 hidden or 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 { Row, Col } from "@canonical/react-components"; | ||
import { LoadingCard } from "@canonical/store-components"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
const elementIds: string[] = Array.of( | ||
uuidv4(), | ||
uuidv4(), | ||
uuidv4(), | ||
uuidv4(), | ||
uuidv4(), | ||
uuidv4(), | ||
uuidv4(), | ||
uuidv4(), | ||
); | ||
|
||
function CardsLoader(): JSX.Element { | ||
return ( | ||
<Row> | ||
{elementIds.map((id) => ( | ||
<Col size={4} key={id}> | ||
<LoadingCard height={157} /> | ||
</Col> | ||
))} | ||
</Row> | ||
); | ||
} | ||
|
||
export default CardsLoader; |
This file contains hidden or 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,35 @@ | ||
import { Row, Col, Strip } from "@canonical/react-components"; | ||
|
||
import { useCategories } from "../../hooks"; | ||
|
||
import type { Category } from "../../types"; | ||
|
||
function Categories(): JSX.Element { | ||
const { data, isLoading } = useCategories(); | ||
|
||
return ( | ||
<> | ||
<h2>Categories</h2> | ||
{!isLoading && data && ( | ||
<Strip shallow className="u-no-padding--bottom"> | ||
<Row> | ||
{data.map((category: Category) => ( | ||
<Col size={3} key={category.name}> | ||
<p className="p-heading--4"> | ||
<a | ||
className="p-link--soft" | ||
href={`/store?categories=${category.name}&page=1`} | ||
> | ||
{category.display_name} | ||
</a> | ||
</p> | ||
</Col> | ||
))} | ||
</Row> | ||
</Strip> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default Categories; |
This file contains hidden or 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,56 @@ | ||
import { Row, Col } from "@canonical/react-components"; | ||
import { SlicesData } from "../../types"; | ||
|
||
type Props = { | ||
isLoading: boolean; | ||
slice: SlicesData; | ||
gradient: "blueGreen" | "purplePink"; | ||
}; | ||
|
||
function EditorialSection({ isLoading, slice, gradient }: Props): JSX.Element { | ||
const gradients: Record<string, string> = { | ||
blueGreen: "linear-gradient(45deg, #251755 20%, #69e07c)", | ||
purplePink: "linear-gradient(45deg, #19224d 20%, #c481d1)", | ||
}; | ||
|
||
return ( | ||
<div className="u-fixed-width"> | ||
<div | ||
style={{ | ||
background: gradient ? gradients[gradient] : gradients["purplePink"], | ||
color: "#fff", | ||
}} | ||
> | ||
{!isLoading && ( | ||
<div className="slice-banner"> | ||
<Row> | ||
<Col size={6} className="u-vertically-center"> | ||
<div> | ||
<h2 className="p-heading--3">{slice.slice.name}</h2> | ||
<p className="p-heading--4">{slice.slice.description}</p> | ||
</div> | ||
</Col> | ||
<Col size={6} className="slice-icons"> | ||
{slice.snaps.slice(0, 3).map((snap) => ( | ||
<div className="slice-icon" key={snap.name}> | ||
<a href={`/${snap.name}`}> | ||
<img | ||
src={snap.icon} | ||
width={70} | ||
height={70} | ||
alt={snap.title} | ||
title={snap.title} | ||
/> | ||
</a> | ||
</div> | ||
))} | ||
</Col> | ||
</Row> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default EditorialSection; |
This file contains hidden or 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,191 @@ | ||
import { useRef } from "react"; | ||
import { useQueries } from "react-query"; | ||
import { Strip, Row, Col } from "@canonical/react-components"; | ||
|
||
import Banner from "../../components/Banner"; | ||
import RecommendationsSection from "./RecommendationsSection"; | ||
// import EditorialSection from "./EditorialSection"; | ||
import ListSection from "./ListSection"; | ||
import Categories from "./Categories"; | ||
|
||
import type { UseQueryResult } from "react-query"; | ||
import type { RecommendationData } from "../../types"; | ||
|
||
function Explore(): JSX.Element { | ||
const searchRef = useRef<HTMLInputElement | null>(null); | ||
const searchSummaryRef = useRef<HTMLDivElement | null>(null); | ||
const categories: string[] = ["popular", "recent", "trending"]; | ||
// const sliceIds: string[] = ["our_picks", "must_have_snaps"]; | ||
|
||
// const slices = useQueries( | ||
// sliceIds.map((sliceId) => ({ | ||
// queryKey: ["slices", sliceId], | ||
// queryFn: async () => { | ||
// const response = await fetch( | ||
// `https://recommendations.snapcraft.io/api/slice/${sliceId}`, | ||
// ); | ||
// | ||
// if (!response.ok) { | ||
// throw Error(`Unable to fetch ${sliceId} data`); | ||
// } | ||
// | ||
// const responseData = await response.json(); | ||
// | ||
// return responseData; | ||
// }, | ||
// })), | ||
// ); | ||
|
||
// const slicesLoading: boolean = slices.some((s) => s.isLoading); | ||
|
||
// const slicesData: Record<string, SlicesData> = {}; | ||
|
||
// if (slices) { | ||
// slices.forEach((slice) => { | ||
// if (slice.data) { | ||
// slicesData[slice.data.slice.id] = slice.data; | ||
// } | ||
// }); | ||
// } | ||
|
||
const recommendations: UseQueryResult<{ | ||
name: string; | ||
snaps: RecommendationData[]; | ||
}>[] = useQueries( | ||
categories.map((category) => ({ | ||
queryKey: ["recommendations", category], | ||
queryFn: async () => { | ||
const response = await fetch( | ||
`https://recommendations.snapcraft.io/api/category/${category}`, | ||
); | ||
|
||
if (!response.ok) { | ||
throw Error(`Unable to fetch ${category} data`); | ||
} | ||
|
||
const responseData = await response.json(); | ||
|
||
return { | ||
name: category, | ||
snaps: responseData, | ||
}; | ||
}, | ||
})), | ||
); | ||
|
||
const recommendationsLoading: boolean = recommendations.some( | ||
(r) => r.isLoading, | ||
); | ||
|
||
const snaps: Record<string, RecommendationData[]> = {}; | ||
|
||
if (recommendations) { | ||
recommendations.forEach((recommendation) => { | ||
if (recommendation.data) { | ||
snaps[recommendation.data.name] = recommendation.data.snaps.slice(0, 8); | ||
} | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<Banner searchRef={searchRef} searchSummaryRef={searchSummaryRef} /> | ||
|
||
{/* slices && ( | ||
<> | ||
{slicesData.our_picks && ( | ||
<Strip className="u-no-padding--bottom"> | ||
<EditorialSection | ||
isLoading={slicesLoading} | ||
slice={slicesData.our_picks} | ||
gradient="purplePink" | ||
/> | ||
</Strip> | ||
)} | ||
</> | ||
) */} | ||
|
||
{recommendations && ( | ||
<> | ||
{snaps.recent && ( | ||
<Strip shallow className="u-no-padding--bottom"> | ||
<RecommendationsSection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note, from my understanding, @0-luke wants this to be more dynamic (i.e, if I want to change the title, I don't need to open a PR). The service itself still isn't ready for this, but thought I'd mention it so that its in mind when the code is changed to be server side |
||
snaps={snaps.recent} | ||
title="Recently updated snaps" | ||
isLoading={recommendationsLoading} | ||
highlight={true} | ||
/> | ||
</Strip> | ||
)} | ||
|
||
{snaps.popular && ( | ||
<Strip shallow className="u-no-padding--bottom"> | ||
<ListSection | ||
snaps={snaps.popular} | ||
title="Most popular snaps" | ||
isLoading={recommendationsLoading} | ||
/> | ||
</Strip> | ||
)} | ||
</> | ||
)} | ||
|
||
<Strip shallow className="u-no-padding--top"> | ||
<Categories /> | ||
</Strip> | ||
|
||
{/* Placeholder until content is decided */} | ||
{/* slices && ( | ||
<> | ||
{slicesData.must_have_snaps && ( | ||
<Strip shallow className="u-no-padding--top u-no-padding--bottom"> | ||
<EditorialSection | ||
isLoading={slicesLoading} | ||
slice={slicesData.must_have_snaps} | ||
gradient="blueGreen" | ||
/> | ||
</Strip> | ||
)} | ||
</> | ||
) */} | ||
|
||
{recommendations && snaps.trending && ( | ||
<Strip shallow> | ||
<RecommendationsSection | ||
snaps={snaps.trending} | ||
title="Trending snaps" | ||
isLoading={recommendationsLoading} | ||
/> | ||
</Strip> | ||
)} | ||
|
||
<Strip className="u-no-padding--top"> | ||
<div | ||
style={{ | ||
backgroundImage: | ||
"url('https://assets.ubuntu.com/v1/e888a79f-suru.png')", | ||
steverydz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
backgroundPosition: "top right", | ||
backgroundSize: "contain", | ||
backgroundRepeat: "no-repeat", | ||
backgroundColor: "#f3f3f3", | ||
padding: "67px", | ||
}} | ||
> | ||
<Row> | ||
<Col size={6}> | ||
<h2>Learn how to snap in 30 minutes</h2> | ||
<p className="p-heading--4"> | ||
Find out how to build and publish snaps | ||
</p> | ||
<a className="p-button--positive" href="/docs/get-started"> | ||
Get started | ||
</a> | ||
</Col> | ||
</Row> | ||
</div> | ||
</Strip> | ||
</> | ||
); | ||
} | ||
|
||
export default Explore; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.