Skip to content

Commit

Permalink
fix round #6
Browse files Browse the repository at this point in the history
  • Loading branch information
xiduzo committed Nov 8, 2023
1 parent 6cc11ae commit e7f2c7d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
25 changes: 14 additions & 11 deletions apps/expo/src/components/pages/fissa/Tracks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Animated, NativeScrollEvent, NativeSyntheticEvent, View } from "react-native";
import { FlashList } from "@shopify/flash-list";
import { useCallback, useEffect, useMemo, useRef, useState, type FC } from "react";
import { Animated, View, type NativeScrollEvent, type NativeSyntheticEvent } from "react-native";
import { type FlashList } from "@shopify/flash-list";
import { useGetFissa, useIsOwner } from "@fissa/hooks";
import { sortFissaTracksOrder, useDevices, useTracks } from "@fissa/utils";

Expand Down Expand Up @@ -50,12 +50,15 @@ export const FissaTracks: FC<{ pin: string }> = ({ pin }) => {
[data?.currentlyPlayingId, localTracks],
);

const shouldShowBackButton = useCallback((showShow = false) => {
Animated.spring(showBackAnimation, {
toValue: Number(showShow),
useNativeDriver: false,
}).start();
}, []);
const shouldShowBackButton = useCallback(
(showShow = false) => {
Animated.spring(showBackAnimation, {
toValue: Number(showShow),
useNativeDriver: false,
}).start();
},
[showBackAnimation],
);

const getTrackVotes = useCallback(
(track?: SpotifyApi.TrackObjectFull) => {
Expand All @@ -68,7 +71,7 @@ export const FissaTracks: FC<{ pin: string }> = ({ pin }) => {

return localTrack.score;
},
[data?.tracks, data?.currentlyPlayingId, localTracks],
[data?.tracks, data?.currentlyPlayingId],
);

const trackEnd = useCallback(
Expand All @@ -86,7 +89,7 @@ export const FissaTracks: FC<{ pin: string }> = ({ pin }) => {

return <TrackEnd trackId={track.id} pin={pin} />;
},
[data?.tracks, data?.currentlyPlayingId, localTracks, isOwner],
[data?.tracks, data?.currentlyPlayingId, isOwner, pin],
);

const trackExtra = useCallback(
Expand Down
32 changes: 18 additions & 14 deletions apps/expo/src/components/pages/fissa/quickVote/QuickVoteContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createContext,
useCallback,
useMemo,
useRef,
useState,
type FC,
Expand All @@ -12,8 +13,12 @@ import { impactAsync } from "expo-haptics";
export const QuickVoteContext = createContext({
track: undefined as SpotifyApi.TrackObjectFull | undefined,
vote: 0,
setVote: (vote: number) => {},
selectTrack: (event: GestureResponderEvent, track?: SpotifyApi.TrackObjectFull) => {},
setVote: (vote: number): void => {
console.log("setVote", vote);
},
selectTrack: (event: GestureResponderEvent, track?: SpotifyApi.TrackObjectFull): void => {
console.log("selectTrack", event, track);
},
touchStartPosition: {
current: 0,
},
Expand Down Expand Up @@ -47,17 +52,16 @@ export const QuickVoteProvider: FC<PropsWithChildren> = ({ children }) => {
[],
);

return (
<QuickVoteContext.Provider
value={{
track,
vote,
setVote: handleSetVote,
selectTrack: handleSelectTrack,
touchStartPosition,
}}
>
{children}
</QuickVoteContext.Provider>
const contextValue = useMemo(
() => ({
track,
vote,
setVote: handleSetVote,
selectTrack: handleSelectTrack,
touchStartPosition,
}),
[track, vote, handleSetVote, handleSelectTrack, touchStartPosition],
);

return <QuickVoteContext.Provider value={contextValue}>{children}</QuickVoteContext.Provider>;
};
2 changes: 1 addition & 1 deletion apps/expo/src/components/shared/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Badge: FC<Props> = ({ amount, inverted }) => {
animation.reset();
amountRef.current = amount;
});
}, [amount]);
}, [amount, amountAnimation]);

if (amount === undefined) return null;

Expand Down
22 changes: 14 additions & 8 deletions apps/expo/src/providers/SpotifyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
useState,
Expand Down Expand Up @@ -132,21 +133,26 @@ export const SpotifyProvider: FC<PropsWithChildren> = ({ children }) => {
await mutateAsync({ code, redirectUri });
}, [response, request, saveScopes, saveTokens]);

useMemo(async () => {
useEffect(() => {
if (user) return;
const localScopes = await getScopes();

if (String(localScopes) !== scopes.join("_")) return;
getScopes()
.then((localScopes) => {
if (String(localScopes) !== scopes.join("_")) return;

await updateTokens();
updateTokens().catch(console.info);
})
.catch(console.info);
}, [updateTokens, user, getScopes]);

useOnActiveApp(async () => {
useOnActiveApp(() => {
const { current } = lastTokenSaveTime;
const difference = differenceInMinutes(new Date(), current);

if (difference < REFRESH_INTERVAL_MINUTES) return;
await updateTokens();
if (difference < REFRESH_INTERVAL_MINUTES) {
return;
}

updateTokens().catch(console.info);
});

useInterval(() => {
Expand Down

0 comments on commit e7f2c7d

Please sign in to comment.