Skip to content

Commit

Permalink
[feat]: fetchTop5Tracks on FavoriteSongs search & fix some icon
Browse files Browse the repository at this point in the history
  • Loading branch information
llucasspot committed Jan 21, 2024
1 parent f400121 commit 0417d7d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function RegisterStepper<T extends object>({
const I18n = languageService.useTranslation();
const nestedNavigationRef =
createNavigationContainerRef<RegistrationStackScreenParamsList>();
const [step, setStep] = useState<number>(1);
const [step, setStep] = useState<number>(0);
const [disableSubmit, setDisableSubmit] = useState<boolean>(true);

const stepperLayoutCallback = useRef({
Expand All @@ -73,8 +73,8 @@ export function RegisterStepper<T extends object>({
await stepperLayoutCallback.current.value({ navigateOnNextStep });
};

const isLastStep = step === numberOfStep;
const progress = step / numberOfStep;
const isLastStep = step === numberOfStep - 1;
const progress = step / (numberOfStep - 1);

const coreStyles = useCoreStyles();
const styles = useEStyles({
Expand Down Expand Up @@ -117,9 +117,11 @@ export function RegisterStepper<T extends object>({
<Progressheader onPressBack={onPressBack} progress={progress} />
<View>
<Text style={{ ...coreStyles.P, ...styles.stepTitle }}>
{I18n.t("common.stepperHeader", { step, numberOfStep })}
{I18n.t("common.stepperHeader", { step: step + 1, numberOfStep })}
</Text>
<Text style={{ ...coreStyles.H2 }}>
{I18n.t(`component.RegisterStepper.step.${step}.title`)}
</Text>
<Text style={{ ...coreStyles.H2 }}>Upload profile picture</Text>
</View>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { useQuery } from "@tanstack/react-query";
import { useEffect, useState } from "react";
import { Modal, ScrollView, Text, TouchableOpacity, View } from "react-native";

import { ProfileApiServiceI } from "../../../api/ProfileApiService/ProfileApiServiceI";
import { Track } from "../../../api/SpotifyApiService/SpotifyApiServiceI";
import {
SpotifyApiServiceI,
Track,
} from "../../../api/SpotifyApiService/SpotifyApiServiceI";
import useEStyles from "../../../hooks/useEStyles";
import {
RegisterStackParamsList,
Expand All @@ -18,9 +22,6 @@ import { SongCard } from "../../SongCard";
import { SongPicker } from "../../SongPicker";
import { StepProps } from "../RegisterStepper";

// TODO use styles
const CONTENT_PADDING = 20;

export default function FavoriteSongs({
setStepperLayoutCallback,
setDisableSubmit,
Expand All @@ -32,7 +33,20 @@ export default function FavoriteSongs({
const profileApiService = getGlobalInstance<ProfileApiServiceI>(
ServiceInterface.ProfileApiServiceI,
);
const spotifyApiService = getGlobalInstance<SpotifyApiServiceI>(
ServiceInterface.SpotifyApiServiceI,
);
const [mySongs, setMySongs] = useState<Track[]>([]);
const { data: top5Tracks } = useQuery({
queryKey: [spotifyApiService.fetchTop5Tracks.name],
queryFn: () => spotifyApiService.fetchTop5Tracks(),
});

useEffect(() => {
if (top5Tracks) {
setMySongs(top5Tracks);
}
}, [top5Tracks]);

const [pickSongModalVisible, setPickSongModalVisible] = useState(false);

Expand Down Expand Up @@ -83,7 +97,7 @@ export default function FavoriteSongs({
}, []);

useEffect(() => {
if (mySongs.length === 4) {
if (mySongs.length === 5) {
setDisableSubmit(false);
}
}, [mySongs]);
Expand All @@ -105,8 +119,6 @@ export default function FavoriteSongs({
<View
style={{
flex: 1,
paddingHorizontal: CONTENT_PADDING,
paddingVertical: 15,
}}
>
<TouchableOpacity
Expand All @@ -122,7 +134,7 @@ export default function FavoriteSongs({
? "Add a new song..."
: "Remove a song before adding a new one"}
</Text>
<BaseButton color="$primaryColor" icon="arrow-left" />
<BaseButton color="$primaryColor" icon="magnify" />
</TouchableOpacity>

<ScrollView style={{ marginTop: 15 }}>
Expand All @@ -134,7 +146,7 @@ export default function FavoriteSongs({
icon={() => (
<BaseButton
color="$primaryColor"
icon="arrow-left"
icon="check"
onPress={() => removeSong(song.name)}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion expo-boomboomapp/src/components/SongCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function SongCard({ song, icon }: SongCardProps) {
});

return (
<View key={song.trackId} style={coreStyles.SONG_CARD}>
<View style={coreStyles.SONG_CARD}>
<View style={styles.cardSubContainer}>
{song.image && (
<Image
Expand Down
13 changes: 13 additions & 0 deletions expo-boomboomapp/src/services/LanguageService/Languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const en: LanguageTranslationType = {
UserProfileForm: {
errorMessage: "This is required.",
},
RegisterStepper: {
step: {
"0": {
title: "Upload profile picture",
},
"1": {
title: "Tell us more about you",
},
"2": {
title: "Add favorites songs",
},
},
},
},
screen: {
SignInScreen: {
Expand Down
13 changes: 13 additions & 0 deletions expo-boomboomapp/src/services/LanguageService/Languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const fr: LanguageTranslationType = {
UserProfileForm: {
errorMessage: "Le champ est requis.",
},
RegisterStepper: {
step: {
"0": {
title: "Télécharge ta photo de profil",
},
"1": {
title: "Dis-nous en plus sur toi",
},
"2": {
title: "Ajoute tes chansons favorites",
},
},
},
},
screen: {
SignInScreen: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Gender } from "../../UserService/userServiceI";

type RegisterStepperStep = {
title: string;
};

type LanguageTranslationType = {
common: {
matches: string;
Expand All @@ -24,6 +28,13 @@ type LanguageTranslationType = {
UserProfileForm: {
errorMessage: string;
};
RegisterStepper: {
step: {
"0": RegisterStepperStep;
"1": RegisterStepperStep;
"2": RegisterStepperStep;
};
};
};
screen: {
SignInScreen: {
Expand Down

0 comments on commit 0417d7d

Please sign in to comment.