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 all commits
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
26 changes: 15 additions & 11 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 @@ -39,10 +39,7 @@
'ui/messageInputStateStore',
() => {
const initialValue = {
messageInputState: new Map<
ChannelId | VirtualChannelId,
MessageInputState
>()
messageInputState: new Map<ChannelId, MessageInputState>()

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

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L42

Added line #L42 was not covered by tests
}

const [state, restoring, restoringPromise] = useIndexedDbValue(
Expand All @@ -59,20 +56,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 59 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L59

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

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

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L61-L63

Added lines #L61 - L63 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 69 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L65-L69

Added lines #L65 - L69 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 72 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L71 - L72 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 77 in src/store/ui/messageInputStateStore.ts

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L77

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

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

View check run for this annotation

Codecov / codecov/patch

src/store/ui/messageInputStateStore.ts#L79

Added line #L79 was not covered by tests
}
}

Expand Down
Loading