Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

share-target API のテキストが下書きで上書きされるバグを修正 #4431

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
VirtualChannelIdに対してはmessageInputStateStoreを使わないように
  • Loading branch information
Nagarei committed Jan 3, 2025
commit 059cf58eaa0966826c32457309de6bdbb1b43cdf
23 changes: 15 additions & 8 deletions src/store/ui/messageInputStateStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineStore, acceptHMRUpdate } from 'pinia'
import type { Ref } from 'vue'
import { computed, unref, toRef } from 'vue'
import { computed, unref, toRef, ref } from 'vue'
import type { AttachmentType } from '/@/lib/basic/file'
import { convertToRefsStore } from '/@/store/utils/convertToRefsStore'
import type { ChannelId } from '/@/types/entity-ids'
Expand Down Expand Up @@ -40,7 +40,7 @@
() => {
const initialValue = {
messageInputState: new Map<
ChannelId | VirtualChannelId,
ChannelId,
MessageInputState
>()
}
Expand All @@ -59,20 +59,27 @@
)

const states = toRef(() => state.messageInputState)
const inputChannels = computed(() =>
[...states.value].filter(([id]) => !virtualIds.has(id))
)
const inputChannels = computed(() => [...states.value])

Check warning on line 62 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L62

Added line #L62 was not covered by tests
const hasInputChannel = computed(() => inputChannels.value.length > 0)
const virtualChannelStates = ref(
new Map<VirtualChannelId, MessageInputState>()
)

Check warning on line 66 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L64-L66

Added lines #L64 - L66 were not covered by tests

const getStore = (cId: MessageInputStateKey) => states.value.get(unref(cId))
const getStore = (cId: MessageInputStateKey) => {
const cId_ = unref(cId)
const st = (virtualIds.has(cId_) ? virtualChannelStates : states)
return st.value.get(cId_)
}

Check warning on line 72 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L68-L72

Added lines #L68 - L72 were not covered by tests
const setStore = (cId: MessageInputStateKey, v: MessageInputState) => {
const cId_ = unref(cId)
const st = (virtualIds.has(cId_) ? virtualChannelStates : states)

Check warning on line 75 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L74-L75

Added lines #L74 - L75 were not covered by tests
// 空のときは削除、空でないときはセット
if (v && (v.text !== '' || v.attachments.length > 0)) {
// コピーしないと参照が変わらないから上書きされる
// toRawしちゃうとreactiveで包めなくなるので、そうはしない
states.value.set(unref(cId), { ...v })
st.value.set(cId_, { ...v })

Check warning on line 80 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L80

Added line #L80 was not covered by tests
} else {
states.value.delete(unref(cId))
st.value.delete(cId_)

Check warning on line 82 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L82

Added line #L82 was not covered by tests
}
}

Expand Down
Loading