Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/assets/mdi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
mdiPlus,
mdiPlusCircle,
mdiPlusCircleOutline,
mdiRefresh,
mdiSend,
mdiSlack,
mdiSnowflake,
Expand Down Expand Up @@ -117,6 +118,7 @@ const mdi: MdiIconsMapping = {
'microphone-off': mdiMicrophoneOff,
pin: mdiPin,
search: mdiMagnify,
refresh: mdiRefresh,
history: mdiHistory,
creation: mdiCreation,
'file-upload': mdiFileUpload,
Expand Down
30 changes: 3 additions & 27 deletions src/components/Main/MainView/MessageElement/MessageTools.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<transition v-if="!isMinimum" name="quick-reaction">
<div v-if="showQuickReaction || !isMobile" :class="$style.quickReaction">
<AStamp
v-for="stamp in topStamps"
v-for="stamp in quickReactionStampIds"
:key="stamp"
:stamp-id="stamp"
:size="28"
Expand Down Expand Up @@ -84,8 +84,6 @@
</template>

<script lang="ts" setup>
import type { Stamp } from '@traptitech/traq'

import { computed, ref, toRef, watch } from 'vue'

import AIcon from '/@/components/UI/AIcon.vue'
Expand All @@ -97,11 +95,10 @@ import useToggle from '/@/composables/utils/useToggle'
import { isDefined } from '/@/lib/basic/array'
import { useStampUpdater } from '/@/lib/updater/stamp'
import { useMeStore } from '/@/store/domain/me'
import { useTopStampIds } from '/@/store/domain/stampRecommendations'
import { useMessagesStore } from '/@/store/entities/messages'
import { useStampsStore } from '/@/store/entities/stamps'
import { useMessageEditingStateStore } from '/@/store/ui/messageEditingStateStore'
import { useStampPickerInvoker } from '/@/store/ui/stampPicker'
import { useStampPickerSettings } from '/@/store/ui/stampPickerSettings'
import type { MessageId, StampId } from '/@/types/entity-ids'

import MessageContextMenu from './MessageContextMenu.vue'
Expand All @@ -120,30 +117,9 @@ const props = withDefaults(

const isActive = defineModel<boolean>('isActive', { default: false })

const { topStampIds } = useTopStampIds()
const { quickReactionStampIds } = useStampPickerSettings()
const { addStampOptimistically } = useStampUpdater()
const { initialRecentStamps } = useStampsStore()

const pushInitialRecentStampsIfNeeded = (
initialRecentStamps: Stamp[],
recents: StampId[]
) => {
if (recents.length >= 3) return

const initials = initialRecentStamps.map(stamp => stamp.id)
for (const s of initials) {
if (recents.length >= 3) return
if (recents.includes(s)) return

recents.push(s)
}
}

const topStamps = computed(() => {
const tops = topStampIds.value.slice(0, 3)
pushInitialRecentStampsIfNeeded(initialRecentStamps.value, tops)
return tops
})
const addStamp = async (stampId: StampId) =>
addStampOptimistically(props.messageId, stampId)

Expand Down
24 changes: 10 additions & 14 deletions src/components/Main/StampPicker/StampPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@
:anime-effects="selectedAnimeEffects"
/>
<StampPickerStampSetSelector
v-model:current-stamp-set="currentStampSet"
v-model:current-stamp-set="selectedStampSet"
v-model:tab-order="tabOrder"
:class="$style.paletteSelector"
:stamp-sets="stampSetState.stampSets"
:stamp-sets="stampSets"
:sortable="isRecommendationEnabled"
/>
</div>
</ClickOutside>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { ref } from 'vue'

import ClickOutside from '/@/components/UI/ClickOutside'
import FilterInput from '/@/components/UI/FilterInput.vue'
import useResponsive from '/@/composables/useResponsive'
import { useStampHistory } from '/@/store/domain/stampHistory'
import { useStampRecommendations } from '/@/store/domain/stampRecommendations'
import { useStampPicker } from '/@/store/ui/stampPicker'
import { useStampPickerSettings } from '/@/store/ui/stampPickerSettings'
import type { StampId } from '/@/types/entity-ids'

import StampPickerEffectSelector from './StampPickerEffectSelector.vue'
Expand All @@ -68,13 +71,8 @@ import useStampList from './composables/useStampList'
import useStampPreselector from './composables/useStampPreselector'
import useStampSetSelector from './composables/useStampSetSelector'

const {
selectHandler,
isEffectEnabled,
currentStampSet,
validateCurrentStampSet,
closeStampPicker
} = useStampPicker()
const { selectHandler, isEffectEnabled, closeStampPicker } = useStampPicker()
const { isRecommendationEnabled } = useStampPickerSettings()
const { upsertLocalStampHistory } = useStampHistory()
const { isMobile } = useResponsive()

Expand All @@ -84,8 +82,8 @@ const incrementAnimationKey = (id: StampId) => {
animationKeys.value.set(id, currentVal + 1)
}

const { stamps, filterState } = useStampList(currentStampSet)
const { stampSetState } = useStampSetSelector()
const { stampSets, selectedStampSet, tabOrder } = useStampSetSelector()
const { stamps, filterState } = useStampList(selectedStampSet)

const {
shouldShowEffectSelector,
Expand Down Expand Up @@ -119,8 +117,6 @@ const onFilterEnter = () => {
if (!firstStamp) return
onInputStamp(firstStamp.id)
}

onMounted(validateCurrentStampSet)
</script>

<style lang="scss" module>
Expand Down
140 changes: 113 additions & 27 deletions src/components/Main/StampPicker/StampPickerStampSetSelector.vue
Original file line number Diff line number Diff line change
@@ -1,64 +1,150 @@
<template>
<div :class="$style.container">
<div :class="$style.innerContainer">
<div ref="tabStrip" :class="$style.container">
<div
ref="tabList"
:class="[$style.innerContainer, { [$style.dragging]: isDragging }]"
role="group"
aria-label="スタンプ一覧の切り替え"
>
<StampPickerStampSetSelectorItem
v-for="set in stampSets"
:key="set.id"
:key="getStampSetKey(set)"
:class="$style.item"
:data-id="getStampSetKey(set)"
:stamp-set="set"
:is-active="currentStampSet.id === set.id"
@click="onStampSetSelect(set)"
:is-active="getStampSetKey(currentStampSet) === getStampSetKey(set)"
@click="currentStampSet = set"
/>
</div>
<template v-if="sortable && tabOrder.length > 0">
<span :class="$style.divider" aria-hidden="true" />
<button
ref="resetButton"
type="button"
title="タブの並び順をリセット"
:class="$style.resetButton"
:disabled="isDragging"
>
<AIcon mdi name="refresh" aria-hidden="true" />
</button>
</template>
</div>
</template>

<script lang="ts" setup>
import { computed, useCssModule, useTemplateRef } from 'vue'

import { useEventListener } from '@vueuse/core'

import AIcon from '/@/components/UI/AIcon.vue'
import { useSortable } from '/@/composables/dom/useSortable'
import {
type StampPickerTab,
type StampSet,
getStampSetKey
} from '/@/store/ui/stampPickerSettings'

import StampPickerStampSetSelectorItem from './StampPickerStampSetSelectorItem.vue'
import type { StampSet } from './composables/useStampSetSelector'

const currentStampSet = defineModel<StampSet>('currentStampSet', {
required: true
})

withDefaults(
defineProps<{
stampSets: StampSet[]
foldedStampSets?: StampSet[]
}>(),
const tabOrder = defineModel<string[]>('tabOrder', { required: true })

const props = defineProps<{
stampSets: StampPickerTab[]
sortable: boolean
}>()

const tabStrip = useTemplateRef('tabStrip')
const tabList = useTemplateRef('tabList')
const styles = useCssModule()
const { isDragging } = useSortable(
computed(() => (props.sortable ? tabList.value : null)),
ids => {
tabOrder.value = ids
},
{
foldedStampSets: () => []
sortOutside: 'horizontal',
scroll: tabStrip,
delay: 200,
delayOnTouchOnly: true,
touchStartThreshold: 4,
fallbackTolerance: 4,
fallbackClass: styles.dragPreview
}
)

const onStampSetSelect = (stampSet: StampSet) => {
currentStampSet.value = stampSet
}
const resetButton = useTemplateRef('resetButton')

// 列外ドロップ後のクリックを SortableJS が抑制する前に処理する
useEventListener(
() =>
isDragging.value ? undefined : resetButton.value?.ownerDocument.defaultView,
'click',
event => {
const button = resetButton.value
if (!button || !event.composedPath().includes(button)) return

tabOrder.value = []
tabStrip.value?.scrollTo({ left: 0 })
},
{ capture: true }
)
</script>

<style lang="scss" module>
.container {
@include background-secondary;
display: flex;
align-items: center;
position: relative;
height: fit-content;
padding-inline: 8px;
overflow-x: auto;
}
.innerContainer {
display: flex;
align-items: center;
height: fit-content;
overflow-x: scroll;
&::-webkit-scrollbar {
display: none;
}
}
.item {
flex-shrink: 0;
margin: 0 4px;
&:first-child {
margin-left: 12px;
}
.item,
.resetButton {
flex: 0 0 32px;
}
.divider {
flex: 0 0 1px;
height: 20px;
margin-inline: 4px;
background: $theme-ui-tertiary-default;
}
.resetButton {
@include background-tertiary;
@include color-ui-secondary;
display: grid;
place-items: center;
height: 36px;
cursor: pointer;

&:hover {
@include background-primary;
}
&:last-child {
padding-right: 8px;

&:focus-visible {
outline: 2px solid $theme-accent-focus-default;
outline-offset: -2px;
}
}
.dragging ~ .divider,
.dragging ~ .resetButton {
visibility: hidden;
}
.dragPreview {
visibility: hidden;
}
:global(html):has(.dragging),
:global(html):has(.dragging) * {
cursor: grabbing !important;
}
</style>
Loading
Loading