-
Notifications
You must be signed in to change notification settings - Fork 46
feat(app-list): 並び替え可能なサービス一覧 #4776
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
Open
uni-kakurenbo
wants to merge
6
commits into
master
Choose a base branch
from
feat/rearrangeable-app-list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−39
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c3cf291
feat: `AppList` の順番を保存するための `useAppList` store を作成
uni-kakurenbo 0c90931
feat: グリッドのソートのための `useSortable` composable を作成
uni-kakurenbo 3cf81e8
feat: grid の配列情報を得るための `useGridLayout` composable を作成
uni-kakurenbo 3c53529
feat: ドラッグアンドドロップで `AppList` を並び替えられるように
uni-kakurenbo b2d8be6
refactor: `StampPaletteEditorSortableStampList` の実装を `useSortable` を用…
uni-kakurenbo b0e8ffe
fix: タッチデバイスの場合は長押しで並び替える
uni-kakurenbo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { type ShallowRef, onMounted, onUnmounted, ref } from 'vue' | ||
|
|
||
| export const useGridLayout = ( | ||
| elementRef: ShallowRef<HTMLElement | null>, | ||
| fallback?: { | ||
| columnCount?: number | ||
| rowCount?: number | ||
| } | ||
| ) => { | ||
| const columnCount = ref<number>(fallback?.columnCount ?? NaN) | ||
| const rowCount = ref<number>(fallback?.rowCount ?? NaN) | ||
|
|
||
| let resizeObserver: ResizeObserver | null = null | ||
|
|
||
| const updateLayout = () => { | ||
| if (!elementRef.value) return | ||
|
|
||
| const computedStyle = getComputedStyle(elementRef.value) | ||
|
|
||
| rowCount.value = computedStyle | ||
| .getPropertyValue('grid-template-rows') | ||
| .split(' ') | ||
| .filter(size => size !== '0px').length | ||
|
uni-kakurenbo marked this conversation as resolved.
|
||
|
|
||
| columnCount.value = computedStyle | ||
| .getPropertyValue('grid-template-columns') | ||
| .split(' ') | ||
| .filter(size => size !== '0px').length | ||
| } | ||
|
|
||
| onMounted(() => { | ||
| if (!elementRef.value) return | ||
|
|
||
| resizeObserver = new ResizeObserver(() => { | ||
| updateLayout() | ||
| }) | ||
|
|
||
| resizeObserver.observe(elementRef.value) | ||
| updateLayout() | ||
| }) | ||
|
|
||
| onUnmounted(() => { | ||
| if (!resizeObserver) return | ||
|
|
||
| resizeObserver.disconnect() | ||
| resizeObserver = null | ||
| }) | ||
|
|
||
| return { | ||
| columnCount, | ||
| rowCount | ||
| } | ||
| } | ||
|
|
||
| export default useGridLayout | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { onMounted, onUnmounted, shallowRef } from 'vue' | ||
|
|
||
| import Sortable from 'sortablejs' | ||
|
|
||
| type Options = Omit<Sortable.Options, 'store'> & { | ||
| store?: { | ||
| get?: (sortable: Sortable) => string[] | ||
| set?: (sortable: Sortable) => void | ||
| } | ||
| } | ||
|
|
||
| export const useSortable = ({ store, ...options }: Options = {}) => { | ||
| const containerRef = shallowRef<HTMLElement | null>(null) | ||
| let sortableInstance: Sortable | null = null | ||
|
|
||
| const setupSortable = () => { | ||
| if (sortableInstance) return | ||
| if (!containerRef.value) return | ||
|
|
||
| sortableInstance = Sortable.create(containerRef.value, { | ||
| animation: 150, | ||
| draggable: '.js-sortable-item', | ||
| store: { | ||
| get: store?.get ?? (() => []), | ||
| set: store?.set ?? (() => void 0) | ||
| }, | ||
| ...options | ||
| }) | ||
| } | ||
|
|
||
| const destroySortableInstance = () => { | ||
| if (sortableInstance) { | ||
| sortableInstance.destroy() | ||
| sortableInstance = null | ||
| } | ||
| } | ||
|
|
||
| onMounted(setupSortable) | ||
| onUnmounted(destroySortableInstance) | ||
|
|
||
| return { setupSortable, destroySortableInstance, containerRef } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { computed, toRefs } from 'vue' | ||
|
|
||
| import { acceptHMRUpdate, defineStore } from 'pinia' | ||
|
|
||
| import useIndexedDbValue from '/@/composables/utils/useIndexedDbValue' | ||
| import { convertToRefsStore } from '/@/store/utils/convertToRefsStore' | ||
|
|
||
| export interface AppItem { | ||
| label: string | ||
| iconPath: string | ||
| appLink: string | ||
| } | ||
|
|
||
| type State = { | ||
| customOrder: string[] | ||
| } | ||
|
|
||
| const useAppListPinia = defineStore('ui/appList', () => { | ||
| const services = window.traQConfig.services ?? [] | ||
|
|
||
| const initialValue: State = { | ||
| customOrder: [] | ||
| } | ||
|
|
||
| const [state, restoring, restoringPromise] = useIndexedDbValue( | ||
| 'store/ui/appList', | ||
| 1, | ||
| {}, | ||
| initialValue | ||
| ) | ||
|
|
||
| const updateAppOrder = async (newOrder: ReadonlyArray<string>) => { | ||
| await restoringPromise.value | ||
| state.customOrder = [...newOrder] | ||
| } | ||
|
|
||
| const resetToDefaultAppOrder = async () => { | ||
| await restoringPromise.value | ||
| state.customOrder = [] | ||
| } | ||
|
|
||
| const displayApps = computed((): ReadonlyArray<AppItem> => { | ||
| if (state.customOrder.length <= 0) return services ?? [] | ||
|
|
||
| return [ | ||
| ...state.customOrder | ||
| .map(item => services?.find(({ label }) => label === item)) | ||
| .filter((item): item is AppItem => !!item), | ||
| ...services.filter(({ label }) => !state.customOrder.includes(label)) | ||
| ] | ||
| }) | ||
|
|
||
| const hasCustomOrder = computed(() => { | ||
| return state.customOrder.length > 0 | ||
| }) | ||
|
|
||
| return { | ||
| ...toRefs(state), | ||
| restoring, | ||
| restoringPromise, | ||
| updateAppOrder, | ||
| resetToDefaultAppOrder, | ||
| displayApps, | ||
| hasCustomOrder | ||
| } | ||
| }) | ||
|
|
||
| export const useAppList = convertToRefsStore(useAppListPinia) | ||
|
|
||
| if (import.meta.hot) { | ||
| import.meta.hot.accept(acceptHMRUpdate(useAppListPinia, import.meta.hot)) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.