Skip to content

Commit

Permalink
コピーしたときのモーダルに説明をつけた
Browse files Browse the repository at this point in the history
  • Loading branch information
nokhnaton committed Oct 23, 2024
1 parent 4d3788f commit 8a0c4e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const useCopyChannelLink = (props: { channelId: ChannelId }) => {
const channelPath = channelIdToPathString(props.channelId)
const channelUrl = `${embeddingOrigin}${constructChannelPath(channelPath)}`

await copyText(`[#${channelPath}](${channelUrl})`)
await copyText(`[#${channelPath}](${channelUrl})`, 'チャンネルリンク')
}

return { copyLink }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { useMeStore } from '/@/store/domain/me'
import { useModalStore } from '/@/store/ui/modal'
import { useMessagesStore } from '/@/store/entities/messages'
import { useMessageEditingStateStore } from '/@/store/ui/messageEditingStateStore'
import useCopyText from '/@/composables/toast/useCopyText'
const useMessageChanger = (messageId: Ref<MessageId>) => {
const { execWithToast } = useExecWithToast()
Expand All @@ -86,15 +87,13 @@ const useMessageChanger = (messageId: Ref<MessageId>) => {
}
const useCopyMd = (messageId: Ref<MessageId>) => {
const { execWithToast } = useExecWithToast()
const { messagesMap } = useMessagesStore()
const { copyText } = useCopyText()
const copyMd = async () => {
const content = messagesMap.value.get(messageId.value)?.content ?? ''
const replacedContent = replaceBack(content)
execWithToast('コピーしました', 'コピーに失敗しました', () =>
navigator.clipboard.writeText(replacedContent)
)
copyText(replacedContent, 'Markdown')
}
return { copyMd }
}
Expand Down
4 changes: 2 additions & 2 deletions src/composables/contextMenu/useCopyLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const useCopyLink = (messageId: Ref<MessageId>) => {

const copyLink = async () => {
const link = `${embeddingOrigin}${constructMessagesPath(messageId.value)}`
await copyText(link)
await copyText(link, 'メッセージリンク')
}

const copyEmbedded = async () => {
const link = `<iframe src="${embeddingOrigin}/widget/?type=message&id=${messageId.value}" scrolling="no" frameborder="no" width="600"></iframe>`
await copyText(link)
await copyText(link, '埋め込み')
}

return { copyLink, copyEmbedded }
Expand Down
16 changes: 12 additions & 4 deletions src/composables/toast/useCopyText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import useExecWithToast from '/@/composables/toast/useExecWithToast'
const useCopyText = () => {
const { execWithToast } = useExecWithToast()

const copyText = async (text: string) => {
await execWithToast('コピーしました', 'コピーに失敗しました', () =>
navigator.clipboard.writeText(text)
)
const copyText = async (text: string, description?: string) => {
if (description === undefined) {
await execWithToast('コピーしました', 'コピーに失敗しました', () =>
navigator.clipboard.writeText(text)
)
} else {
await execWithToast(
`${description}をコピーしました`,
`${description}のコピーに失敗しました`,
() => navigator.clipboard.writeText(text)
)
}
}

return { copyText }
Expand Down

0 comments on commit 8a0c4e7

Please sign in to comment.