From cd9b01095ce32ea68714fc6556d0befb403f4267 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun <cheeaun@gmail.com> Date: Wed, 22 Feb 2023 00:42:43 +0800 Subject: [PATCH] Fix post status banner showing wrong thing for non-logged-in users --- src/pages/status.jsx | 92 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/src/pages/status.jsx b/src/pages/status.jsx index c22e6bc0..8d3a488e 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -40,8 +40,12 @@ function resetScrollPosition(id) { function StatusPage() { const { id, ...params } = useParams(); - const { masto, instance, authenticated } = api({ instance: params.instance }); - const { masto: currentMasto, instance: currentInstance } = api(); + const { masto, instance } = api({ instance: params.instance }); + const { + masto: currentMasto, + instance: currentInstance, + authenticated, + } = api(); const sameInstance = instance === currentInstance; const navigate = useNavigate(); const snapStates = useSnapshot(states); @@ -622,55 +626,59 @@ function StatusPage() { size="l" /> </InView> - {!sameInstance && uiState !== 'loading' && ( + {uiState !== 'loading' && !authenticated ? ( <div class="post-status-banner"> <p> - This post is from another instance ( - <b>{instance}</b>). Interactions (reply, boost, etc) - are not possible. + You're not logged in. Interactions (reply, boost, + etc) are not possible. </p> - <button - type="button" - onClick={() => { - (async () => { - try { - const results = await currentMasto.v2.search({ - q: heroStatus.url, - type: 'statuses', - resolve: true, - limit: 1, - }); - if (results.statuses.length) { - const status = results.statuses[0]; - navigate(`/s/${status.id}`); - } else { - throw new Error('No results'); - } - } catch (e) { - alert('Error: ' + e); - console.error(e); - } - })(); - }} - > - <Icon icon="transfer" /> Switch to my instance to - enable interactions - </button> + <Link to="/login" class="button"> + Log in + </Link> </div> - )} - {sameInstance && - !authenticated && - uiState !== 'loading' && ( + ) : ( + !sameInstance && ( <div class="post-status-banner"> <p> - You're not logged in. Interactions (reply, boost, + This post is from another instance ( + <b>{instance}</b>). Interactions (reply, boost, etc) are not possible. </p> - <Link to="/login" class="button"> - Log in - </Link> + <button + type="button" + onClick={() => { + (async () => { + try { + const results = + await currentMasto.v2.search({ + q: heroStatus.url, + type: 'statuses', + resolve: true, + limit: 1, + }); + if (results.statuses.length) { + const status = results.statuses[0]; + navigate( + currentInstance + ? `/${currentInstance}/s/${status.id}` + : `/s/${status.id}`, + ); + } else { + throw new Error('No results'); + } + } catch (e) { + alert('Error: ' + e); + console.error(e); + } + })(); + }} + > + <Icon icon="transfer" /> Switch to my instance to + enable interactions + </button> </div> - )} + ) + )} </> ) : ( <Link