fix: checkLogin in StatusCard (#270)
parent
c4cf3fb371
commit
18d5fd4804
|
@ -29,6 +29,8 @@ useCommand({
|
||||||
icon: () => props.icon,
|
icon: () => props.icon,
|
||||||
|
|
||||||
onActivate() {
|
onActivate() {
|
||||||
|
if (!checkLogin())
|
||||||
|
return
|
||||||
const clickEvent = new MouseEvent('click', {
|
const clickEvent = new MouseEvent('click', {
|
||||||
view: window,
|
view: window,
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
|
|
|
@ -18,6 +18,8 @@ const {
|
||||||
} = $(useStatusActions(props))
|
} = $(useStatusActions(props))
|
||||||
|
|
||||||
const reply = () => {
|
const reply = () => {
|
||||||
|
if (!checkLogin())
|
||||||
|
return
|
||||||
if (details) {
|
if (details) {
|
||||||
// TODO focus to editor
|
// TODO focus to editor
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,18 @@ export function useStatusActions(props: StatusActionsProps) {
|
||||||
translation: false,
|
translation: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
async function toggleStatusAction(action: Action, newStatus: Promise<Status>, countField?: CountField) {
|
async function toggleStatusAction(action: Action, newStatus: () => Promise<Status>, countField?: CountField) {
|
||||||
// Optimistic update
|
// check login
|
||||||
|
if (!checkLogin())
|
||||||
|
return
|
||||||
|
// Optimistic update
|
||||||
status[action] = !status[action]
|
status[action] = !status[action]
|
||||||
if (countField)
|
if (countField)
|
||||||
status[countField] += status[action] ? 1 : -1
|
status[countField] += status[action] ? 1 : -1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isLoading[action] = true
|
isLoading[action] = true
|
||||||
Object.assign(status, await newStatus)
|
Object.assign(status, await newStatus())
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
isLoading[action] = false
|
isLoading[action] = false
|
||||||
|
@ -41,7 +44,7 @@ export function useStatusActions(props: StatusActionsProps) {
|
||||||
}
|
}
|
||||||
const toggleReblog = () => toggleStatusAction(
|
const toggleReblog = () => toggleStatusAction(
|
||||||
'reblogged',
|
'reblogged',
|
||||||
useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
|
() => useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
|
||||||
if (status.reblogged)
|
if (status.reblogged)
|
||||||
// returns the original status
|
// returns the original status
|
||||||
return res.reblog!
|
return res.reblog!
|
||||||
|
@ -52,18 +55,18 @@ export function useStatusActions(props: StatusActionsProps) {
|
||||||
|
|
||||||
const toggleFavourite = () => toggleStatusAction(
|
const toggleFavourite = () => toggleStatusAction(
|
||||||
'favourited',
|
'favourited',
|
||||||
useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
|
() => useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
|
||||||
'favouritesCount',
|
'favouritesCount',
|
||||||
)
|
)
|
||||||
|
|
||||||
const toggleBookmark = () => toggleStatusAction(
|
const toggleBookmark = () => toggleStatusAction(
|
||||||
'bookmarked',
|
'bookmarked',
|
||||||
useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
|
() => useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
const togglePin = async () => toggleStatusAction(
|
const togglePin = async () => toggleStatusAction(
|
||||||
'pinned',
|
'pinned',
|
||||||
useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
|
() => useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -96,3 +96,11 @@ export async function signout() {
|
||||||
|
|
||||||
await loginTo(currentUser.value)
|
await loginTo(currentUser.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkLogin() {
|
||||||
|
if (!currentUser.value) {
|
||||||
|
openSigninDialog()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue