mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-11 00:18:51 +01:00
Fix post status banner showing wrong thing for non-logged-in users
This commit is contained in:
parent
c13cab51a9
commit
cd9b01095c
1 changed files with 50 additions and 42 deletions
|
@ -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,55 +626,59 @@ function StatusPage() {
|
||||||
size="l"
|
size="l"
|
||||||
/>
|
/>
|
||||||
</InView>
|
</InView>
|
||||||
{!sameInstance && uiState !== 'loading' && (
|
{uiState !== 'loading' && !authenticated ? (
|
||||||
<div class="post-status-banner">
|
<div class="post-status-banner">
|
||||||
<p>
|
<p>
|
||||||
This post is from another instance (
|
You're not logged in. Interactions (reply, boost,
|
||||||
<b>{instance}</b>). Interactions (reply, boost, etc)
|
etc) are not possible.
|
||||||
are not possible.
|
|
||||||
</p>
|
</p>
|
||||||
<button
|
<Link to="/login" class="button">
|
||||||
type="button"
|
Log in
|
||||||
onClick={() => {
|
</Link>
|
||||||
(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>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : (
|
||||||
{sameInstance &&
|
!sameInstance && (
|
||||||
!authenticated &&
|
|
||||||
uiState !== 'loading' && (
|
|
||||||
<div class="post-status-banner">
|
<div class="post-status-banner">
|
||||||
<p>
|
<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.
|
etc) are not possible.
|
||||||
</p>
|
</p>
|
||||||
<Link to="/login" class="button">
|
<button
|
||||||
Log in
|
type="button"
|
||||||
</Link>
|
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>
|
</div>
|
||||||
)}
|
)
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Link
|
<Link
|
||||||
|
|
Loading…
Reference in a new issue