mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-23 09:06:23 +01:00
Handle logged-out cases
This commit is contained in:
parent
7f22ec6a9b
commit
d5bceb1d81
3 changed files with 75 additions and 59 deletions
|
@ -60,7 +60,7 @@ function Status({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const { masto, instance } = api({ instance: propInstance });
|
const { masto, instance, authenticated } = api({ instance: propInstance });
|
||||||
const { instance: currentInstance } = api();
|
const { instance: currentInstance } = api();
|
||||||
const sameInstance = instance === currentInstance;
|
const sameInstance = instance === currentInstance;
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ function Status({
|
||||||
<Poll
|
<Poll
|
||||||
lang={language}
|
lang={language}
|
||||||
poll={poll}
|
poll={poll}
|
||||||
readOnly={readOnly || !sameInstance}
|
readOnly={readOnly || !sameInstance || !authenticated}
|
||||||
onUpdate={(newPoll) => {
|
onUpdate={(newPoll) => {
|
||||||
states.statuses[sKey].poll = newPoll;
|
states.statuses[sKey].poll = newPoll;
|
||||||
}}
|
}}
|
||||||
|
@ -517,7 +517,7 @@ function Status({
|
||||||
icon="comment"
|
icon="comment"
|
||||||
count={repliesCount}
|
count={repliesCount}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!sameInstance) {
|
if (!sameInstance || !authenticated) {
|
||||||
return alert(unauthInteractionErrorMessage);
|
return alert(unauthInteractionErrorMessage);
|
||||||
}
|
}
|
||||||
states.showCompose = {
|
states.showCompose = {
|
||||||
|
@ -537,7 +537,7 @@ function Status({
|
||||||
icon="rocket"
|
icon="rocket"
|
||||||
count={reblogsCount}
|
count={reblogsCount}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (!sameInstance) {
|
if (!sameInstance || !authenticated) {
|
||||||
return alert(unauthInteractionErrorMessage);
|
return alert(unauthInteractionErrorMessage);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -580,7 +580,7 @@ function Status({
|
||||||
icon="heart"
|
icon="heart"
|
||||||
count={favouritesCount}
|
count={favouritesCount}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (!sameInstance) {
|
if (!sameInstance || !authenticated) {
|
||||||
return alert(unauthInteractionErrorMessage);
|
return alert(unauthInteractionErrorMessage);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -616,7 +616,7 @@ function Status({
|
||||||
class="bookmark-button"
|
class="bookmark-button"
|
||||||
icon="bookmark"
|
icon="bookmark"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (!sameInstance) {
|
if (!sameInstance || !authenticated) {
|
||||||
return alert(unauthInteractionErrorMessage);
|
return alert(unauthInteractionErrorMessage);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -36,21 +36,20 @@
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-deck footer {
|
.post-status-banner {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
bottom: 16px;
|
bottom: 16px;
|
||||||
bottom: max(16px, env(safe-area-inset-bottom));
|
bottom: max(16px, env(safe-area-inset-bottom));
|
||||||
font-size: 90%;
|
font-size: 90%;
|
||||||
background-color: var(--bg-faded-blur-color);
|
background-color: var(--bg-faded-color);
|
||||||
backdrop-filter: blur(16px);
|
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
margin: 16px;
|
margin: 0 16px;
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
max-width: var(--main-width);
|
max-width: var(--main-width);
|
||||||
}
|
}
|
||||||
.status-deck footer > p:first-of-type {
|
.post-status-banner > p:first-of-type {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ function resetScrollPosition(id) {
|
||||||
|
|
||||||
function StatusPage() {
|
function StatusPage() {
|
||||||
const { id, ...params } = useParams();
|
const { id, ...params } = useParams();
|
||||||
const { masto, instance } = api({ instance: params.instance });
|
const { masto, instance, authenticated } = api({ instance: params.instance });
|
||||||
const { masto: currentMasto, instance: currentInstance } = api();
|
const { masto: currentMasto, instance: currentInstance } = api();
|
||||||
const sameInstance = instance === currentInstance;
|
const sameInstance = instance === currentInstance;
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
@ -609,6 +609,7 @@ function StatusPage() {
|
||||||
} ${thread ? 'thread' : ''} ${isHero ? 'hero' : ''}`}
|
} ${thread ? 'thread' : ''} ${isHero ? 'hero' : ''}`}
|
||||||
>
|
>
|
||||||
{isHero ? (
|
{isHero ? (
|
||||||
|
<>
|
||||||
<InView
|
<InView
|
||||||
threshold={0.1}
|
threshold={0.1}
|
||||||
onChange={onView}
|
onChange={onView}
|
||||||
|
@ -622,6 +623,56 @@ function StatusPage() {
|
||||||
size="l"
|
size="l"
|
||||||
/>
|
/>
|
||||||
</InView>
|
</InView>
|
||||||
|
{!sameInstance && uiState !== 'loading' && (
|
||||||
|
<div class="post-status-banner">
|
||||||
|
<p>
|
||||||
|
This post is from another instance (
|
||||||
|
<b>{instance}</b>). 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>
|
||||||
|
</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>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Link
|
<Link
|
||||||
class="status-link"
|
class="status-link"
|
||||||
|
@ -730,40 +781,6 @@ function StatusPage() {
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{!sameInstance && uiState !== 'loading' && (
|
|
||||||
<footer class="">
|
|
||||||
<p>
|
|
||||||
This post is from another instance (<b>{instance}</b>), different
|
|
||||||
from your current logged-in instance (<b>{currentInstance}</b>).
|
|
||||||
</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
|
|
||||||
</button>
|
|
||||||
</footer>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue