fix: checkLogin in StatusCard (#270)

pull/282/head^2
Chris 2022-12-02 10:18:57 +08:00 zatwierdzone przez GitHub
rodzic c4cf3fb371
commit 18d5fd4804
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 22 dodań i 7 usunięć

Wyświetl plik

@ -29,6 +29,8 @@ useCommand({
icon: () => props.icon,
onActivate() {
if (!checkLogin())
return
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,

Wyświetl plik

@ -18,6 +18,8 @@ const {
} = $(useStatusActions(props))
const reply = () => {
if (!checkLogin())
return
if (details) {
// TODO focus to editor
}

Wyświetl plik

@ -25,15 +25,18 @@ export function useStatusActions(props: StatusActionsProps) {
translation: false,
})
async function toggleStatusAction(action: Action, newStatus: Promise<Status>, countField?: CountField) {
// Optimistic update
async function toggleStatusAction(action: Action, newStatus: () => Promise<Status>, countField?: CountField) {
// check login
if (!checkLogin())
return
// Optimistic update
status[action] = !status[action]
if (countField)
status[countField] += status[action] ? 1 : -1
try {
isLoading[action] = true
Object.assign(status, await newStatus)
Object.assign(status, await newStatus())
}
finally {
isLoading[action] = false
@ -41,7 +44,7 @@ export function useStatusActions(props: StatusActionsProps) {
}
const toggleReblog = () => toggleStatusAction(
'reblogged',
useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
() => useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
if (status.reblogged)
// returns the original status
return res.reblog!
@ -52,18 +55,18 @@ export function useStatusActions(props: StatusActionsProps) {
const toggleFavourite = () => toggleStatusAction(
'favourited',
useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
() => useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
'favouritesCount',
)
const toggleBookmark = () => toggleStatusAction(
'bookmarked',
useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
() => useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
)
const togglePin = async () => toggleStatusAction(
'pinned',
useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
() => useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
)
return {

Wyświetl plik

@ -96,3 +96,11 @@ export async function signout() {
await loginTo(currentUser.value)
}
export function checkLogin() {
if (!currentUser.value) {
openSigninDialog()
return false
}
return true
}