-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add generated genre list on dashboard
- Loading branch information
Stéphane
committed
Aug 29, 2023
1 parent
7db87db
commit e48c327
Showing
9 changed files
with
1,010 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -72,6 +72,7 @@ | |
] | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.9.5" | ||
"typescript": "^4.9.5", | ||
"uniqolor": "^1.1.0" | ||
} | ||
} |
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,133 @@ | ||
const uniqolor = require("uniqolor"); | ||
|
||
const genres = [ | ||
{ name: "Acoustic" }, | ||
{ name: "Afrobeat" }, | ||
{ name: "Alt-rock" }, | ||
{ name: "Alternative" }, | ||
{ name: "Ambient" }, | ||
{ name: "Anime" }, | ||
{ name: "Black-metal" }, | ||
{ name: "Bluegrass" }, | ||
{ name: "Blues" }, | ||
{ name: "Bossanova" }, | ||
{ name: "Brazil" }, | ||
{ name: "Breakbeat" }, | ||
{ name: "British" }, | ||
{ name: "Cantopop" }, | ||
{ name: "Chicago-house" }, | ||
{ name: "Children" }, | ||
{ name: "Chill" }, | ||
{ name: "Classical" }, | ||
{ name: "Club" }, | ||
{ name: "Comedy" }, | ||
{ name: "Country" }, | ||
{ name: "Dance" }, | ||
{ name: "Dancehall" }, | ||
{ name: "Death-metal" }, | ||
{ name: "Deep-house" }, | ||
{ name: "Detroit-techno" }, | ||
{ name: "Disco" }, | ||
{ name: "Disney" }, | ||
{ name: "Drum-and-bass" }, | ||
{ name: "Dub" }, | ||
{ name: "Dubstep" }, | ||
{ name: "Edm" }, | ||
{ name: "Electro" }, | ||
{ name: "Electronic" }, | ||
{ name: "Emo" }, | ||
{ name: "Folk" }, | ||
{ name: "Forro" }, | ||
{ name: "Funk" }, | ||
{ name: "Garage" }, | ||
{ name: "Gospel" }, | ||
{ name: "Goth" }, | ||
{ name: "Grindcore" }, | ||
{ name: "Groove" }, | ||
{ name: "Grunge" }, | ||
{ name: "Guitar" }, | ||
{ name: "Happy" }, | ||
{ name: "Hard-rock" }, | ||
{ name: "Hardcore" }, | ||
{ name: "Hardstyle" }, | ||
{ name: "Heavy-metal" }, | ||
{ name: "Hip-hop" }, | ||
{ name: "Holidays" }, | ||
{ name: "Honky-tonk" }, | ||
{ name: "House" }, | ||
{ name: "Idm" }, | ||
{ name: "Industrial" }, | ||
{ name: "J-dance" }, | ||
{ name: "J-idol" }, | ||
{ name: "J-pop" }, | ||
{ name: "J-rock" }, | ||
{ name: "Jazz" }, | ||
{ name: "K-pop" }, | ||
{ name: "Kids" }, | ||
{ name: "Latin" }, | ||
{ name: "Latino" }, | ||
{ name: "Malay" }, | ||
{ name: "Mandopop" }, | ||
{ name: "Metal" }, | ||
{ name: "Metal-misc" }, | ||
{ name: "Metalcore" }, | ||
{ name: "Minimal-techno" }, | ||
{ name: "Mpb" }, | ||
{ name: "Opera" }, | ||
{ name: "Pagode" }, | ||
{ name: "Party" }, | ||
{ name: "Piano" }, | ||
{ name: "Pop" }, | ||
{ name: "Post-dubstep" }, | ||
{ name: "Power-pop" }, | ||
{ name: "Progressive-house" }, | ||
{ name: "Psych-rock" }, | ||
{ name: "Punk" }, | ||
{ name: "Punk-rock" }, | ||
{ name: "R-n-b" }, | ||
{ name: "Rainy-day" }, | ||
{ name: "Reggae" }, | ||
{ name: "Reggaeton" }, | ||
{ name: "Road-trip" }, | ||
{ name: "Rock" }, | ||
{ name: "Rock-n-roll" }, | ||
{ name: "Rockabilly" }, | ||
{ name: "Romance" }, | ||
{ name: "Sad" }, | ||
{ name: "Salsa" }, | ||
{ name: "Samba" }, | ||
{ name: "Sertanejo" }, | ||
{ name: "Show-tunes" }, | ||
{ name: "Singer-songwriter" }, | ||
{ name: "Ska" }, | ||
{ name: "Sleep" }, | ||
{ name: "Songwriter" }, | ||
{ name: "Soul" }, | ||
{ name: "Soundtracks" }, | ||
{ name: "Spanish" }, | ||
{ name: "Study" }, | ||
{ name: "Summer" }, | ||
{ name: "Synth-pop" }, | ||
{ name: "Tango" }, | ||
{ name: "Techno" }, | ||
{ name: "Trance" }, | ||
{ name: "Trip-hop" }, | ||
{ name: "Work-out" }, | ||
{ name: "World-music" }, | ||
]; | ||
|
||
const generateGenres = () => { | ||
return genres.map((genre) => { | ||
const { color, isLight } = uniqolor(genre.name, { format: "rgb" }); | ||
const rgbaColor = color.replace("rgb", "rgba"); | ||
|
||
return { | ||
name: genre.name, | ||
color: rgbaColor.replace(")", ", 0.6)"), | ||
colorHover: rgbaColor.replace(")", ", 1)"), | ||
textColor: isLight ? "#000" : "#fff", | ||
}; | ||
}); | ||
}; | ||
|
||
console.log(JSON.stringify(generateGenres())); |
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,84 @@ | ||
import { | ||
Box, | ||
Flex, | ||
Space, | ||
Text, | ||
Title, | ||
UnstyledButton, | ||
createStyles, | ||
} from "@mantine/core"; | ||
import { memo } from "react"; | ||
import { genres } from "../utils/genres"; | ||
import { useHover } from "@mantine/hooks"; | ||
import { useSearchValues, useSetSearchValues } from "../providers/Search"; | ||
|
||
const useStyles = createStyles((theme) => ({ | ||
item: { | ||
width: 90, | ||
height: 90, | ||
backgroundColor: | ||
theme.colorScheme === "dark" | ||
? theme.colors.dark[6] | ||
: theme.colors.gray[0], | ||
borderRadius: 10, | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
textAlign: "center", | ||
padding: theme.spacing.xs, | ||
transition: "background-color 0.2s", | ||
}, | ||
text: { | ||
fontSize: theme.fontSizes.sm, | ||
}, | ||
})); | ||
|
||
export const GenreList = memo(() => { | ||
return ( | ||
<> | ||
<Title order={2}>Moods & genres</Title> | ||
<Space h="lg" /> | ||
<Flex gap={20} wrap="wrap"> | ||
{genres.map((genre) => ( | ||
<Genre genre={genre} /> | ||
))} | ||
</Flex> | ||
</> | ||
); | ||
}); | ||
|
||
const Genre = memo( | ||
({ | ||
genre, | ||
}: { | ||
genre: { | ||
name: string; | ||
color: string; | ||
colorHover: string; | ||
}; | ||
}) => { | ||
const { classes } = useStyles(); | ||
const { hovered, ref } = useHover(); | ||
const setSearchValues = useSetSearchValues(); | ||
const searchValues = useSearchValues(); | ||
|
||
const handleClick = () => { | ||
setSearchValues({ ...searchValues, q: genre.name }); | ||
}; | ||
|
||
return ( | ||
<UnstyledButton onClick={handleClick}> | ||
<Box | ||
ref={ref} | ||
className={classes.item} | ||
style={{ | ||
border: `solid 4px ${genre.color}`, | ||
backgroundColor: hovered ? genre.color : undefined, | ||
}} | ||
> | ||
<Text className={classes.text}>{genre.name}</Text> | ||
</Box> | ||
</UnstyledButton> | ||
); | ||
} | ||
); |
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 |
---|---|---|
@@ -1,29 +1,52 @@ | ||
import { LoadingOverlay } from "@mantine/core"; | ||
import { Alert, LoadingOverlay, Text } from "@mantine/core"; | ||
import { memo } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useQuery } from "react-query"; | ||
import { getTrendings } from "../services/trending"; | ||
import { CardList } from "./CardList"; | ||
import { useTrendingFiltersValues } from "../providers/TrendingFilters"; | ||
import { HorizontalGridList } from "./HorizontalGridList"; | ||
|
||
export const Trending = memo(() => { | ||
const trendingFiltersValues = useTrendingFiltersValues(); | ||
const query = useQuery( | ||
`trending-${trendingFiltersValues.type}-${trendingFiltersValues.region}`, | ||
() => getTrendings(trendingFiltersValues), | ||
{ | ||
enabled: Boolean(trendingFiltersValues.region), | ||
interface TrendingProps { | ||
horizontal?: boolean; | ||
} | ||
|
||
export const Trending: React.FC<TrendingProps> = memo( | ||
({ horizontal = false }) => { | ||
const trendingFiltersValues = useTrendingFiltersValues(); | ||
const query = useQuery( | ||
`trending-${trendingFiltersValues.type}-${trendingFiltersValues.region}`, | ||
() => getTrendings(trendingFiltersValues), | ||
{ | ||
enabled: Boolean(trendingFiltersValues.region), | ||
} | ||
); | ||
const { t } = useTranslation(); | ||
|
||
if (!query.data) { | ||
return <LoadingOverlay visible />; | ||
} | ||
); | ||
const { t } = useTranslation(); | ||
|
||
if (!query.data) { | ||
return <LoadingOverlay visible />; | ||
} | ||
if (query.error) { | ||
return <div>{t("error")}</div>; | ||
} | ||
|
||
if (query.error) { | ||
return <div>{t("error")}</div>; | ||
} | ||
if (horizontal) { | ||
if (!query.data.length) { | ||
return ( | ||
<Alert title={t("recently.play.alert.title")}> | ||
<Text>{t("recently.play.alert.message")}</Text> | ||
</Alert> | ||
); | ||
} | ||
return ( | ||
<HorizontalGridList | ||
data={query.data.slice(0, 10)} | ||
keyPrefix="horizontal-trending" | ||
/> | ||
); | ||
} | ||
|
||
return <CardList data={query.data} />; | ||
}); | ||
return <CardList data={query.data} />; | ||
} | ||
); |
Oops, something went wrong.