Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/relisten/tabs/(relisten)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,18 @@ function StorageUsage() {
const [showMigrationModal, setShowMigrationModal] = useState(false);

useEffect(() => {
let cancelled = false;

(async () => {
setHasLegacyData(await legacyDatabaseExists());
const exists = await legacyDatabaseExists();
if (!cancelled) {
setHasLegacyData(exists);
}
})();

return () => {
cancelled = true;
};
}, []);

useFocusEffect(
Expand Down
18 changes: 12 additions & 6 deletions app/relisten/tabs/(relisten)/recently-played.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,24 @@ export default function Page() {
const artistsResults = useArtists();

useEffect(() => {
const controller = new AbortController();

const getData = async () => {
let params = '';

// console.log(state.data[0]);
if (state.data[0]) {
params = `?lastSeenId=${state.data[0]}`;
}
const data = await fetch(RelistenApiClient.API_BASE + `/v2/live/history${params}`).then(
(res) => res.json()
);
try {
const data = await fetch(RelistenApiClient.API_BASE + `/v2/live/history${params}`, {
signal: controller.signal,
}).then((res) => res.json());

// console.log(data);
call({ type: ACTIONS.UPDATE_DATA, data: data?.toReversed() });
call({ type: ACTIONS.UPDATE_DATA, data: data?.toReversed() });
} catch (e) {
if (e instanceof DOMException && e.name === 'AbortError') return;
throw e;
}
};

getData();
Expand All @@ -239,6 +244,7 @@ export default function Page() {

return () => {
clearInterval(interval);
controller.abort();
};
}, []);

Expand Down
11 changes: 9 additions & 2 deletions app/useCacheAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function useCacheAssets() {

// Load any resources or data that you need prior to rendering the app
useEffect(() => {
let cancelled = false;

async function loadResourcesAndDataAsync() {
try {
const imageAssets = cacheImages([ToolbarRelisten]);
Expand All @@ -28,14 +30,19 @@ export default function useCacheAssets() {
}
}
} catch (e) {
// You might want to provide this error information to an error reporting service
console.warn(e);
} finally {
setIsAppReady(true);
if (!cancelled) {
setIsAppReady(true);
}
}
}

loadResourcesAndDataAsync();

return () => {
cancelled = true;
};
}, []);

return isAppReady;
Expand Down
54 changes: 36 additions & 18 deletions app/web/[artistSlug]/[year]/[month]/[day]/[trackSlug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default function Page() {
return;
}

let cancelled = false;
const timeoutIds: ReturnType<typeof setTimeout>[] = [];

(async () => {
const show = await apiClient.showWithSourcesOnDate(
String(artistSlug),
Expand All @@ -35,14 +38,18 @@ export default function Page() {
}
);

if (cancelled) return;

const showData = show.data;

if (!showData) {
logger.error(`Did not find a show matching ${year}-${month}-${day} for ${artistSlug}`);

setTimeout(() => {
router.push({ pathname: '/relisten/tabs' });
}, 0);
timeoutIds.push(
setTimeout(() => {
if (!cancelled) router.push({ pathname: '/relisten/tabs' });
}, 0)
);

return;
}
Expand Down Expand Up @@ -80,25 +87,36 @@ export default function Page() {

const artistByUuid = groupByUuid([...artistsResults.data]);

setTimeout(() => {
const params: PushShowOptions = {
artist: artistByUuid[showData.artist_uuid],
showUuid: showData.uuid,
sourceUuid: sourceUuid,
overrideGroupSegment: '(artists)',
};
timeoutIds.push(
setTimeout(() => {
if (cancelled) return;

if (autoplay && trackUuid) {
params.playTrackUuid = trackUuid;
}
const params: PushShowOptions = {
artist: artistByUuid[showData.artist_uuid],
showUuid: showData.uuid,
sourceUuid: sourceUuid,
overrideGroupSegment: '(artists)',
};

router.push({ pathname: '/relisten/tabs' });
if (autoplay && trackUuid) {
params.playTrackUuid = trackUuid;
}

setTimeout(() => {
pushShow(params);
}, 0);
}, 0);
router.push({ pathname: '/relisten/tabs' });

timeoutIds.push(
setTimeout(() => {
if (!cancelled) pushShow(params);
}, 0)
);
}, 0)
);
})();

return () => {
cancelled = true;
timeoutIds.forEach(clearTimeout);
};
}, [artistSlug, year, month, day, artistsResults.data]);

return <WebRewriteLoader />;
Expand Down
36 changes: 24 additions & 12 deletions app/web/[artistSlug]/[year]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default function Page() {
const years = useArtistYears(artist.data?.uuid || 'invalid');

useEffect(() => {
const timeoutIds: ReturnType<typeof setTimeout>[] = [];

if (years.data.artist !== null && years.data.years.length > 0) {
const yearArtist = years.data.artist;
const filteredYears = years.data.years.filter((y) => y.year === yearSlug);
Expand All @@ -26,26 +28,36 @@ export default function Page() {
const params = { artistUuid: yearArtist.uuid, yearUuid: year.uuid };
logger.info(`redirecting to ${newPath} ${JSON.stringify(params)}`);

setTimeout(() => {
router.push({ pathname: '/relisten/tabs' });

timeoutIds.push(
setTimeout(() => {
router.push({
pathname: newPath,
params,
});
}, 0);
}, 0);
router.push({ pathname: '/relisten/tabs' });

timeoutIds.push(
setTimeout(() => {
router.push({
pathname: newPath,
params,
});
}, 0)
);
}, 0)
);
} else {
logger.error(`Did not find a year matching ${yearSlug}`);

setTimeout(() => {
router.push({ pathname: '/relisten/tabs' });
}, 0);
timeoutIds.push(
setTimeout(() => {
router.push({ pathname: '/relisten/tabs' });
}, 0)
);
}
} else {
logger.warn(`Cannot redirect artist=${years.data.artist}, years=${years.data.years.length}`);
}

return () => {
timeoutIds.forEach(clearTimeout);
};
}, [years.data, yearSlug]);

return <WebRewriteLoader />;
Expand Down
20 changes: 15 additions & 5 deletions app/web/[artistSlug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ export default function Page() {
const params = { artistUuid: artist.data?.uuid };
logger.info(`redirecting to ${newPath} ${JSON.stringify(params)}`);

setTimeout(() => {
router.push({ pathname: '/relisten/tabs' });
const timeoutIds: ReturnType<typeof setTimeout>[] = [];

timeoutIds.push(
setTimeout(() => {
router.push({ pathname: newPath, params });
}, 0);
}, 0);
router.push({ pathname: '/relisten/tabs' });

timeoutIds.push(
setTimeout(() => {
router.push({ pathname: newPath, params });
}, 0)
);
}, 0)
);

return () => {
timeoutIds.forEach(clearTimeout);
};
}
}, [artist.data]);

Expand Down
8 changes: 7 additions & 1 deletion relisten/pages/legacy_migration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ export function LegacyDataMigrationModal({
const realm = useRealm();

useEffect(() => {
let cancelled = false;

(async () => {
const isIOS = Platform.OS === 'ios';

Expand All @@ -383,10 +385,14 @@ export function LegacyDataMigrationModal({
const legacyDbExists = await legacyDatabaseExists();
const eligibleForModal = legacyDbExists && hasNotDismissed && isIOS;

if (forceShow || (eligibleForModal && shouldMakeNetworkRequests)) {
if (!cancelled && (forceShow || (eligibleForModal && shouldMakeNetworkRequests))) {
setModalVisible(true);
}
})();

return () => {
cancelled = true;
};
}, [forceShow]);

const loadLegacyData = async () => {
Expand Down