refactor: the DM-only conversation-actions rule as a helper
dmActionsTarget (app/lib/slots.ts) answers the open DM's row or null; ChatHeader renders the slot from it. Same behaviour, testable outside a component.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
// only when the open conversation is a DM.
|
||||
import { badgeText } from '../../lib/chatUnread'
|
||||
import { shortName } from '../../lib/chatFormat'
|
||||
import { dmActionsTarget } from '../../lib/slots'
|
||||
|
||||
const props = withDefaults(defineProps<{ back?: boolean; pinsOpen?: boolean }>(), { back: true, pinsOpen: false })
|
||||
const emit = defineEmits<{ back: []; pins: [] }>()
|
||||
@@ -18,8 +19,8 @@ const chat = useChat()
|
||||
|
||||
const channel = computed(() => chat.activeChannel)
|
||||
const dm = computed(() => chat.activeDm)
|
||||
/** The open conversation's kind and row, for the DM-only slot. */
|
||||
const conversation = computed(() => dm.value ?? null)
|
||||
/** The open DM's row, for the DM-only slot (null in a channel). */
|
||||
const conversation = computed(() => dmActionsTarget(dm.value))
|
||||
const dmName = computed(() => (dm.value ? shortName(chat.members.get(dm.value.other_user_id), '', t('chat.someone')) : ''))
|
||||
const title = computed(() => (channel.value ? `# ${channel.value.name}` : dmName.value))
|
||||
const eyebrow = computed(() => (channel.value ? t('chat.header.channel') : t('chat.header.dm')))
|
||||
@@ -90,7 +91,7 @@ async function leave() {
|
||||
</template>
|
||||
</div>
|
||||
<div class="chat-head-actions">
|
||||
<slot v-if="conversation && conversation.type === 'dm'" name="conversation-actions" :conversation="conversation" />
|
||||
<slot v-if="conversation" name="conversation-actions" :conversation="conversation" />
|
||||
<button
|
||||
v-if="channel"
|
||||
class="chat-icon-btn"
|
||||
|
||||
11
app/lib/slots.ts
Normal file
11
app/lib/slots.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// The layer's slot rules, shared by the components that render the slots.
|
||||
import type { ChatConversationRow } from './types'
|
||||
|
||||
/**
|
||||
* dmActionsTarget is the conversation the conversation-actions slot renders
|
||||
* for: the open DM's row when it is a DM, else null (channels never show
|
||||
* the slot, so a call button placed in it appears in DMs only).
|
||||
*/
|
||||
export function dmActionsTarget(dm: ChatConversationRow | null | undefined): ChatConversationRow | null {
|
||||
return dm && dm.type === 'dm' ? dm : null
|
||||
}
|
||||
Reference in New Issue
Block a user