Skip to content

Commit

Permalink
feat(stats): add Past Week option to dropdown when using last.fm
Browse files Browse the repository at this point in the history
  • Loading branch information
harbassan committed Jul 8, 2024
1 parent a923ef2 commit 0a5fd16
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions stats/src/api/lastfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type * as LastFM from "../types/lastfm";
import { apiFetch } from "./spotify";

const lfmperiods = {
extra_short_term: "7day",
short_term: "1month",
medium_term: "6month",
long_term: "overall",
Expand Down
2 changes: 1 addition & 1 deletion stats/src/pages/top_albums.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getTopAlbums = async (timeRange: SpotifyRange, config: Config) => {
};

const AlbumsPage = ({ configWrapper }: { configWrapper: ConfigWrapper }) => {
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions, "stats:top-albums");
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions(configWrapper), "stats:top-albums");

const { status, error, data, refetch } = useQuery({
queryKey: ["top-albums", activeOption.id],
Expand Down
14 changes: 8 additions & 6 deletions stats/src/pages/top_artists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ export const getTopArtists = async (timeRange: SpotifyRange, config: Config) =>
return response.map(minifyArtist);
};

export const DropdownOptions = [
{ id: SpotifyRange.Short, name: "Past Month" },
{ id: SpotifyRange.Medium, name: "Past 6 Months" },
{ id: SpotifyRange.Long, name: "All Time" },
];
export const DropdownOptions = ({ config: { "use-lastfm": useLastFM } }: ConfigWrapper) =>
[
useLastFM && { id: "extra_short_term", name: "Past Week" },
{ id: SpotifyRange.Short, name: "Past Month" },
{ id: SpotifyRange.Medium, name: "Past 6 Months" },
{ id: SpotifyRange.Long, name: "All Time" },
].filter(Boolean) as { id: string; name: string }[];

const ArtistsPage = ({ configWrapper }: { configWrapper: ConfigWrapper }) => {
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions, "stats:top-artists");
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions(configWrapper), "stats:top-artists");

const { status, error, data, refetch } = useQuery({
queryKey: ["top-artists", activeOption.id],
Expand Down
2 changes: 1 addition & 1 deletion stats/src/pages/top_genres.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getGenres = async (time_range: SpotifyRange, config: Config) => {
};

const GenresPage = ({ configWrapper }: { configWrapper: ConfigWrapper }) => {
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions, "stats:top-genres");
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions(configWrapper), "stats:top-genres");

const { status, error, data, refetch } = useQuery({
queryKey: ["top-genres", activeOption.id],
Expand Down
2 changes: 1 addition & 1 deletion stats/src/pages/top_tracks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getTopTracks = async (timeRange: SpotifyRange, config: Config) => {
};

const TracksPage = ({ configWrapper }: { configWrapper: ConfigWrapper }) => {
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions, "stats:top-tracks");
const [dropdown, activeOption] = useDropdownMenu(DropdownOptions(configWrapper), "stats:top-tracks");

const { status, error, data, refetch } = useQuery({
queryKey: ["top-tracks", activeOption.id],
Expand Down

0 comments on commit 0a5fd16

Please sign in to comment.