Skip to content

Commit

Permalink
turn off eurovision playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Asvarox committed May 26, 2024
1 parent e92d135 commit 7b899f8
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 165 deletions.
3 changes: 3 additions & 0 deletions .unimportedrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"src/modules/hooks/useMemoDebugger.ts",
"src/modules/utils/TestCanvas.tsx",
"src/modules/utils/delayPromise.ts",
"src/modules/utils/isoCodeToCountry.ts",
"src/modules/utils/testUtils.ts",
"src/modules/utils/useFeatureFlag.ts",
"src/routes/SingASong/SongSelection/Hooks/usePlaylistsEurovision.tsx",
"src/setupTests.ts",
"src/stories/songFixture.ts"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { SongPreview } from 'interfaces';
import styles from 'modules/GameEngine/Drawing/styles';
import { useSongStats } from 'modules/Songs/stats/hooks';
import { isEurovisionSong } from 'modules/Songs/utils/specialSongsThemeChecks';
import { FeatureFlags } from 'modules/utils/featureFlags';
import useFeatureFlag from 'modules/utils/useFeatureFlag';
import { ReactNode, useMemo } from 'react';
import eurovisionIcon from 'routes/SingASong/SongSelection/Components/SongCard/eurovision-icon.svg';
import { filteringFunctions } from 'routes/SingASong/SongSelection/Hooks/useSongList';
Expand Down Expand Up @@ -36,9 +34,7 @@ export const SongCardStatsIndicator = ({
focused: boolean;
}) => {
const isRecentlyUpdated = useMemo(() => filteringFunctions.recentlyUpdated([song]).length > 0, [song]);
const isEurovisionEnabled = useFeatureFlag(FeatureFlags.Eurovision);

const isESCSong = isEurovisionEnabled && isEurovisionSong(song);
const isESCSong = isEurovisionSong(song);

const stats = useSongStats(song);
const lastPlayed = stats?.scores?.at(-1)?.date ?? false;
Expand Down
15 changes: 6 additions & 9 deletions src/routes/SingASong/SongSelection/Components/SongPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import styled from '@emotion/styled';
import { SingSetup, SongPreview } from 'interfaces';
import { backgroundTheme, useBackground } from 'modules/Elements/LayoutWithBackground';
import VideoPlayer, { VideoPlayerRef, VideoState } from 'modules/Elements/VideoPlayer';
import { isEurovisionSong } from 'modules/Songs/utils/specialSongsThemeChecks';
import useDebounce from 'modules/hooks/useDebounce';
import useViewportSize from 'modules/hooks/useViewportSize';
import { FeatureFlags } from 'modules/utils/featureFlags';
import useFeatureFlag from 'modules/utils/useFeatureFlag';
import { ComponentProps, PropsWithChildren, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { BackgroundThemeSetting, GraphicSetting, useSettingValue } from 'routes/Settings/SettingsState';
import {
Expand Down Expand Up @@ -72,12 +69,12 @@ export default function SongPreviewComponent({
const [showVideo, setShowVideo] = useState(false);
const player = useRef<VideoPlayerRef | null>(null);
const { width: windowWidth, height: windowHeight } = useViewportSize();
const isEurovisionEnabled = useFeatureFlag(FeatureFlags.Eurovision);
useSpecialSongTheme(
songPreview,
isEurovisionEnabled ? 'eurovision' : 'regular',
isEurovisionEnabled ? isEurovisionSong : () => false,
);
// const isEurovisionEnabled = useFeatureFlag(FeatureFlags.Eurovision);
// useSpecialSongTheme(
// songPreview,
// isEurovisionEnabled ? 'eurovision' : 'regular',
// isEurovisionEnabled ? isEurovisionSong : () => false,
// );

const expanded = keyboardControl;

Expand Down
153 changes: 4 additions & 149 deletions src/routes/SingASong/SongSelection/Hooks/usePlaylists.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import styled from '@emotion/styled';
import { SongPreview } from 'interfaces';
import { Flag } from 'modules/Elements/Flag';
import { ClosableTooltip } from 'modules/Elements/Tooltip';
import { colorSets } from 'modules/GameEngine/Drawing/styles';
import { FeatureFlags } from 'modules/utils/featureFlags';
import isoCodeToCountry from 'modules/utils/isoCodeToCountry';
import useFeatureFlag from 'modules/utils/useFeatureFlag';
// import { FeatureFlags } from 'modules/utils/featureFlags';
// import isoCodeToCountry from 'modules/utils/isoCodeToCountry';
// import eurovisionIcon from 'routes/SingASong/SongSelection/Components/SongCard/eurovision-icon.svg';
import { ReactElement, ReactNode, useMemo } from 'react';
import { useLanguageList } from 'routes/ExcludeLanguages/ExcludeLanguagesView';
import eurovisionIcon from 'routes/SingASong/SongSelection/Components/SongCard/eurovision-icon.svg';
import { AppliedFilters, SongGroup } from 'routes/SingASong/SongSelection/Hooks/useSongList';

export interface PlaylistEntry {
Expand All @@ -22,22 +18,8 @@ export interface PlaylistEntry {
sortingFn?: (a: SongPreview, b: SongPreview) => number;
}

const getEurovisionYear = (song: SongPreview) => {
return song.edition?.toLowerCase().replace('esc ', '')?.trim() ?? undefined;
};

function getFlagEmoji(countryCode: string) {
const codePoints = countryCode
.toUpperCase()
.split('')
// @ts-ignore
.map((char) => 127397 + char.charCodeAt());
return String.fromCodePoint(...codePoints);
}

export const usePlaylists = (songs: SongPreview[], recommended: string[], isLoading: boolean): PlaylistEntry[] => {
const songLanguages = useLanguageList(songs);
const isEurovisionEnabled = useFeatureFlag(FeatureFlags.Eurovision);

return useMemo<PlaylistEntry[]>(() => {
if (isLoading) return [];
Expand Down Expand Up @@ -75,74 +57,6 @@ export const usePlaylists = (songs: SongPreview[], recommended: string[], isLoad
const playlists: Array<PlaylistEntry | null> = [
selection,
all,
isEurovisionEnabled
? {
name: 'Eurovision',
display: (
<EurovisionDisplay>
Euro
<EurovisionLogo src={eurovisionIcon} alt="Eurovision logo" />
ision
</EurovisionDisplay>
),
filters: { edition: 'esc' },
hideNew: true,
groupData: (song) => {
const flag = song.artistOrigin ? <SFlag isocode={song.artistOrigin} /> : 'Other';
return {
name: song.artistOrigin ?? 'Other',
displayLong: song.artistOrigin ? (
<>
{flag} {isoCodeToCountry(song.artistOrigin)}
</>
) : (
'Other'
),
displayShort: flag,
};
},
sortingFn: (a, b) => {
const yearA = getEurovisionYear(a);
const yearB = getEurovisionYear(b);
if (yearA && yearB) {
return +yearB - +yearA;
}
return 0;
},
postGrouping: (groups) => {
let finalGroups = groups;
// group single item groups into "Other"
const singleItemGroups = groups.filter((group) => group.songs.length <= 1);
if (singleItemGroups.length) {
let other = groups.find((group) => group.name === 'Other');
if (!other) {
other = { name: 'Other', songs: [] };
groups.push(other);
}
other.displayLong = (
<>
<SFlag isocode="eu" /> Other
</>
);
other.songs = singleItemGroups.map((group) => group.songs[0]);
finalGroups = groups.filter((group) => group.songs.length > 1);
}
// sort by country name
finalGroups.sort((a, b) => {
if (a.name === 'Other') return 1;
if (b.name === 'Other') return -1;
return (
isoCodeToCountry(a.songs[0].song.artistOrigin!)?.localeCompare(
isoCodeToCountry(b.songs[0].song.artistOrigin!) ?? '',
) ?? 0
);
});

return finalGroups;
},
}
: null,

// {
// name: 'Christmas',
// display: (
Expand All @@ -166,7 +80,7 @@ export const usePlaylists = (songs: SongPreview[], recommended: string[], isLoad
}
: null,
{ name: 'Oldies', filters: { yearBefore: 1995 } },
!isEurovisionEnabled ? { name: 'Modern', filters: { yearAfter: 1995 } } : null,
{ name: 'Modern', filters: { yearAfter: 1995 } },
{ name: 'Duets', filters: { duet: true } },
{
name: 'New',
Expand All @@ -177,62 +91,3 @@ export const usePlaylists = (songs: SongPreview[], recommended: string[], isLoad
return playlists.filter((playlist): playlist is PlaylistEntry => playlist !== null);
}, [songLanguages, isLoading, recommended]);
};

const EurovisionDisplay = styled.span`
background-image: linear-gradient(
90deg,
${colorSets.eurovisionPink.text},
${colorSets.eurovisionViolet.text},
${colorSets.eurovisionPink.text},
${colorSets.eurovisionBlue.text},
${colorSets.eurovisionPink.text}
);
background-size: 200% 200%;
background-clip: text;
color: transparent;
display: flex;
align-items: center;
animation: playlist-gradient 15s linear infinite;
@keyframes playlist-gradient {
0% {
background-position: 0% 0%;
}
100% {
background-position: 400% 400%;
}
`;

const EurovisionLogo = styled.img`
width: 1em;
height: 1em;
animation: heartbeat 1.5s infinite;
@keyframes heartbeat {
0% {
transform: scale(0.85);
}
10% {
transform: scale(1);
}
20% {
transform: scale(0.85);
}
30% {
transform: scale(1);
}
40% {
transform: scale(0.85);
}
100% {
transform: scale(0.85);
}
}
`;

const SFlag = styled(Flag)`
width: 1em;
object-fit: contain;
`;
136 changes: 136 additions & 0 deletions src/routes/SingASong/SongSelection/Hooks/usePlaylistsEurovision.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import styled from '@emotion/styled';
import { SongPreview } from 'interfaces';
import { Flag } from 'modules/Elements/Flag';
import { colorSets } from 'modules/GameEngine/Drawing/styles';
import isoCodeToCountry from 'modules/utils/isoCodeToCountry';
import eurovisionIcon from 'routes/SingASong/SongSelection/Components/SongCard/eurovision-icon.svg';
import { PlaylistEntry } from 'routes/SingASong/SongSelection/Hooks/usePlaylists';

const getEurovisionYear = (song: SongPreview) => {
return song.edition?.toLowerCase().replace('esc ', '')?.trim() ?? undefined;
};

const EurovisionDisplay = styled.span`
background-image: linear-gradient(
90deg,
${colorSets.eurovisionPink.text},
${colorSets.eurovisionViolet.text},
${colorSets.eurovisionPink.text},
${colorSets.eurovisionBlue.text},
${colorSets.eurovisionPink.text}
);
background-size: 200% 200%;
background-clip: text;
color: transparent;
display: flex;
align-items: center;
animation: playlist-gradient 15s linear infinite;
@keyframes playlist-gradient {
0% {
background-position: 0% 0%;
}
100% {
background-position: 400% 400%;
}
`;

const EurovisionLogo = styled.img`
width: 1em;
height: 1em;
animation: heartbeat 1.5s infinite;
@keyframes heartbeat {
0% {
transform: scale(0.85);
}
10% {
transform: scale(1);
}
20% {
transform: scale(0.85);
}
30% {
transform: scale(1);
}
40% {
transform: scale(0.85);
}
100% {
transform: scale(0.85);
}
}
`;

const SFlag = styled(Flag)`
width: 1em;
object-fit: contain;
`;

export const eurovisionPlaylist: PlaylistEntry = {
name: 'Eurovision',
display: (
<EurovisionDisplay>
Euro
<EurovisionLogo src={eurovisionIcon} alt="Eurovision logo" />
ision
</EurovisionDisplay>
),
filters: { edition: 'esc' },
hideNew: true,
groupData: (song) => {
const flag = song.artistOrigin ? <SFlag isocode={song.artistOrigin} /> : 'Other';
return {
name: song.artistOrigin ?? 'Other',
displayLong: song.artistOrigin ? (
<>
{flag} {isoCodeToCountry(song.artistOrigin)}
</>
) : (
'Other'
),
displayShort: flag,
};
},
sortingFn: (a, b) => {
const yearA = getEurovisionYear(a);
const yearB = getEurovisionYear(b);
if (yearA && yearB) {
return +yearB - +yearA;
}
return 0;
},
postGrouping: (groups) => {
let finalGroups = groups;
// group single item groups into "Other"
const singleItemGroups = groups.filter((group) => group.songs.length <= 1);
if (singleItemGroups.length) {
let other = groups.find((group) => group.name === 'Other');
if (!other) {
other = { name: 'Other', songs: [] };
groups.push(other);
}
other.displayLong = (
<>
<SFlag isocode="eu" /> Other
</>
);
other.songs = singleItemGroups.map((group) => group.songs[0]);
finalGroups = groups.filter((group) => group.songs.length > 1);
}
// sort by country name
finalGroups.sort((a, b) => {
if (a.name === 'Other') return 1;
if (b.name === 'Other') return -1;
return (
isoCodeToCountry(a.songs[0].song.artistOrigin!)?.localeCompare(
isoCodeToCountry(b.songs[0].song.artistOrigin!) ?? '',
) ?? 0
);
});

return finalGroups;
},
};
Loading

0 comments on commit 7b899f8

Please sign in to comment.