From 79678cf8411a596b5b30ebc9d06c2d49f1da0490 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Sat, 4 Nov 2023 22:52:56 +0100 Subject: [PATCH] [Glitch] Fixes website not loading for unlogged users Port 6712bf86cd291e9db5530400e47ba5f2b6894a9c to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/reducers/accounts.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/javascript/flavours/glitch/reducers/accounts.ts b/app/javascript/flavours/glitch/reducers/accounts.ts index 02bb9d4976..c7459d1d5a 100644 --- a/app/javascript/flavours/glitch/reducers/accounts.ts +++ b/app/javascript/flavours/glitch/reducers/accounts.ts @@ -41,32 +41,34 @@ const normalizeAccounts = ( return state; }; -export const accountsReducer: Reducer = ( - state = initialState, - action, -) => { - const currentUserId = me; - - if (!currentUserId) +function getCurrentUser() { + if (!me) throw new Error( 'No current user (me) defined when calling `accountsReducer`', ); + return me; +} + +export const accountsReducer: Reducer = ( + state = initialState, + action, +) => { if (revealAccount.match(action)) return state.setIn([action.payload.id, 'hidden'], false); else if (importAccounts.match(action)) return normalizeAccounts(state, action.payload.accounts); - else if (followAccountSuccess.match(action)) + else if (followAccountSuccess.match(action)) { return state .update( action.payload.relationship.id, (account) => account?.update('followers_count', (n) => n + 1), ) .update( - currentUserId, + getCurrentUser(), (account) => account?.update('following_count', (n) => n + 1), ); - else if (unfollowAccountSuccess.match(action)) + } else if (unfollowAccountSuccess.match(action)) return state .update( action.payload.relationship.id, @@ -74,7 +76,7 @@ export const accountsReducer: Reducer = ( account?.update('followers_count', (n) => Math.max(0, n - 1)), ) .update( - currentUserId, + getCurrentUser(), (account) => account?.update('following_count', (n) => Math.max(0, n - 1)), );