fix(web): keep /share available to copy existing link (#12533)
This commit is contained in:
@@ -357,30 +357,41 @@ export const useSessionCommands = (input: {
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: "session.share",
|
id: "session.share",
|
||||||
title: input.language.t("command.session.share"),
|
title: input.info()?.share?.url ? "Copy share link" : input.language.t("command.session.share"),
|
||||||
description: input.language.t("command.session.share.description"),
|
description: input.info()?.share?.url
|
||||||
|
? "Copy share URL to clipboard"
|
||||||
|
: input.language.t("command.session.share.description"),
|
||||||
category: input.language.t("command.category.session"),
|
category: input.language.t("command.category.session"),
|
||||||
slash: "share",
|
slash: "share",
|
||||||
disabled: !input.params.id || !!input.info()?.share?.url,
|
disabled: !input.params.id,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
if (!input.params.id) return
|
if (!input.params.id) return
|
||||||
await input.sdk.client.session
|
const copy = (url: string, existing: boolean) =>
|
||||||
.share({ sessionID: input.params.id })
|
navigator.clipboard
|
||||||
.then((res) => {
|
.writeText(url)
|
||||||
navigator.clipboard.writeText(res.data!.share!.url).catch(() =>
|
.then(() =>
|
||||||
|
showToast({
|
||||||
|
title: existing
|
||||||
|
? input.language.t("session.share.copy.copied")
|
||||||
|
: input.language.t("toast.session.share.success.title"),
|
||||||
|
description: input.language.t("toast.session.share.success.description"),
|
||||||
|
variant: "success",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.catch(() =>
|
||||||
showToast({
|
showToast({
|
||||||
title: input.language.t("toast.session.share.copyFailed.title"),
|
title: input.language.t("toast.session.share.copyFailed.title"),
|
||||||
variant: "error",
|
variant: "error",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
const url = input.info()?.share?.url
|
||||||
.then(() =>
|
if (url) {
|
||||||
showToast({
|
await copy(url, true)
|
||||||
title: input.language.t("toast.session.share.success.title"),
|
return
|
||||||
description: input.language.t("toast.session.share.success.description"),
|
}
|
||||||
variant: "success",
|
await input.sdk.client.session
|
||||||
}),
|
.share({ sessionID: input.params.id })
|
||||||
)
|
.then((res) => copy(res.data!.share!.url, false))
|
||||||
.catch(() =>
|
.catch(() =>
|
||||||
showToast({
|
showToast({
|
||||||
title: input.language.t("toast.session.share.failed.title"),
|
title: input.language.t("toast.session.share.failed.title"),
|
||||||
|
|||||||
Reference in New Issue
Block a user