Fix post status banner showing wrong thing for non-logged-in users

This commit is contained in:
Lim Chee Aun 2023-02-22 00:42:43 +08:00
parent c13cab51a9
commit cd9b01095c

View file

@ -40,8 +40,12 @@ function resetScrollPosition(id) {
function StatusPage() { function StatusPage() {
const { id, ...params } = useParams(); const { id, ...params } = useParams();
const { masto, instance, authenticated } = api({ instance: params.instance }); const { masto, instance } = api({ instance: params.instance });
const { masto: currentMasto, instance: currentInstance } = api(); const {
masto: currentMasto,
instance: currentInstance,
authenticated,
} = api();
const sameInstance = instance === currentInstance; const sameInstance = instance === currentInstance;
const navigate = useNavigate(); const navigate = useNavigate();
const snapStates = useSnapshot(states); const snapStates = useSnapshot(states);
@ -622,19 +626,31 @@ function StatusPage() {
size="l" size="l"
/> />
</InView> </InView>
{!sameInstance && uiState !== 'loading' && ( {uiState !== 'loading' && !authenticated ? (
<div class="post-status-banner">
<p>
You're not logged in. Interactions (reply, boost,
etc) are not possible.
</p>
<Link to="/login" class="button">
Log in
</Link>
</div>
) : (
!sameInstance && (
<div class="post-status-banner"> <div class="post-status-banner">
<p> <p>
This post is from another instance ( This post is from another instance (
<b>{instance}</b>). Interactions (reply, boost, etc) <b>{instance}</b>). Interactions (reply, boost,
are not possible. etc) are not possible.
</p> </p>
<button <button
type="button" type="button"
onClick={() => { onClick={() => {
(async () => { (async () => {
try { try {
const results = await currentMasto.v2.search({ const results =
await currentMasto.v2.search({
q: heroStatus.url, q: heroStatus.url,
type: 'statuses', type: 'statuses',
resolve: true, resolve: true,
@ -642,7 +658,11 @@ function StatusPage() {
}); });
if (results.statuses.length) { if (results.statuses.length) {
const status = results.statuses[0]; const status = results.statuses[0];
navigate(`/s/${status.id}`); navigate(
currentInstance
? `/${currentInstance}/s/${status.id}`
: `/s/${status.id}`,
);
} else { } else {
throw new Error('No results'); throw new Error('No results');
} }
@ -657,19 +677,7 @@ function StatusPage() {
enable interactions enable interactions
</button> </button>
</div> </div>
)} )
{sameInstance &&
!authenticated &&
uiState !== 'loading' && (
<div class="post-status-banner">
<p>
You're not logged in. Interactions (reply, boost,
etc) are not possible.
</p>
<Link to="/login" class="button">
Log in
</Link>
</div>
)} )}
</> </>
) : ( ) : (