Merge pull request #259 from cheeaun/main

Update from main
This commit is contained in:
Chee Aun 2023-10-09 23:10:34 +08:00 committed by GitHub
commit 5ba2af0970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 41 deletions

View file

@ -17,7 +17,7 @@ function FollowRequestButtons({ accountID, onChange }) {
<p class="follow-request-buttons">
<button
type="button"
disabled={uiState === 'loading'}
disabled={uiState === 'loading' || hasRelationship}
onClick={() => {
setUIState('loading');
setRequestState('accept');
@ -40,7 +40,7 @@ function FollowRequestButtons({ accountID, onChange }) {
</button>{' '}
<button
type="button"
disabled={uiState === 'loading'}
disabled={uiState === 'loading' || hasRelationship}
class="light danger"
onClick={() => {
setUIState('loading');

View file

@ -92,11 +92,16 @@ function Notifications({ columnMode }) {
return allNotifications;
}
function fetchFollowRequests() {
async function fetchFollowRequests() {
// Note: no pagination here yet because this better be on a separate page. Should be rare use-case???
return masto.v1.followRequests.list({
limit: 80,
});
try {
return await masto.v1.followRequests.list({
limit: 80,
});
} catch (e) {
// Silently fail
return [];
}
}
const loadFollowRequests = () => {
@ -112,8 +117,13 @@ function Notifications({ columnMode }) {
})();
};
function fetchAnnouncements() {
return masto.v1.announcements.list();
async function fetchAnnouncements() {
try {
return await masto.v1.announcements.list();
} catch (e) {
// Silently fail
return [];
}
}
const loadNotifications = (firstLoad) => {
@ -379,39 +389,43 @@ function Notifications({ columnMode }) {
)}
{snapStates.notifications.length ? (
<>
{snapStates.notifications.map((notification) => {
if (onlyMentions && notification.type !== 'mention') {
return null;
}
const notificationDay = new Date(notification.createdAt);
const differentDay =
notificationDay.toDateString() !== currentDay.toDateString();
if (differentDay) {
currentDay = notificationDay;
}
// if notificationDay is yesterday, show "Yesterday"
// if notificationDay is before yesterday, show date
const heading =
notificationDay.toDateString() === yesterdayDate.toDateString()
? 'Yesterday'
: niceDateTime(currentDay, {
hideTime: true,
});
return (
<>
{differentDay && <h2 class="timeline-header">{heading}</h2>}
<Notification
instance={instance}
notification={notification}
key={notification.id}
reload={() => {
loadNotifications(true);
loadFollowRequests();
}}
/>
</>
);
})}
{snapStates.notifications
// This is leaked from Notifications popover
.filter((n) => n.type !== 'follow_request')
.map((notification) => {
if (onlyMentions && notification.type !== 'mention') {
return null;
}
const notificationDay = new Date(notification.createdAt);
const differentDay =
notificationDay.toDateString() !== currentDay.toDateString();
if (differentDay) {
currentDay = notificationDay;
}
// if notificationDay is yesterday, show "Yesterday"
// if notificationDay is before yesterday, show date
const heading =
notificationDay.toDateString() ===
yesterdayDate.toDateString()
? 'Yesterday'
: niceDateTime(currentDay, {
hideTime: true,
});
return (
<>
{differentDay && <h2 class="timeline-header">{heading}</h2>}
<Notification
instance={instance}
notification={notification}
key={notification.id}
reload={() => {
loadNotifications(true);
loadFollowRequests();
}}
/>
</>
);
})}
</>
) : (
<>