From ddd089ef87113164bc6d39ea4f221aec9af37e28 Mon Sep 17 00:00:00 2001 From: David Snyder Date: Wed, 19 Aug 2020 17:53:28 -0400 Subject: [PATCH] improve mod channel updating --- src/components/Channels.js | 9 +-------- src/index.js | 8 ++++++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/Channels.js b/src/components/Channels.js index c8799cd..258ad8e 100644 --- a/src/components/Channels.js +++ b/src/components/Channels.js @@ -157,15 +157,8 @@ const Channels = React.memo(props => { useEffect(() => { (async () => { - const channelsInfo = await Promise.all( - userData.ModChannels?.map?.(async channel => { - const apiUrl = `${process.env.REACT_APP_SOCKET_URL}/resolveuser?user=${channel.id}&platform=twitch`; - const response = await fetch(apiUrl); - return response.json(); - }) || [] - ); setModChannels( - channelsInfo + userData.modChannels ?.sort((a, b) => a.login.localeCompare(b.login)) ?.map(channel => { return { ...channel, modPlatform: "twitch", uid: sha1(channel.id) }; diff --git a/src/index.js b/src/index.js index 9ff51a7..7c19344 100644 --- a/src/index.js +++ b/src/index.js @@ -77,9 +77,13 @@ const App = () => { const removedChannels = userData.removedChannels || []; const NewModChannels = (await modChannelResponse.json()).filter(channel => !removedChannels.includes(channel.id)); - const ModChannels = [...NewModChannels, ...(userData.ModChannels || [])].filter( + const ModChannels = await Promise.all([...NewModChannels, ...(userData.ModChannels || [])].filter( (thing, index, self) => index === self.findIndex(t => t.id === thing.id) - ); + ).map(async channel => { + const apiUrl = `${process.env.REACT_APP_SOCKET_URL}/resolveuser?user=${channel.id}&platform=twitch`; + const response = await fetch(apiUrl); + return response.json(); + })); firebase.db.collection("Streamers").doc(currentUser.uid).update({ profilePicture, ModChannels,