mirror of
https://github.com/nextcloud/spreed.git
synced 2025-07-23 18:55:33 +00:00
feat(threads): add composable to get current threadId
- in main app: based on router, casting to number - in sidebar: internal value Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
This commit is contained in:
27
src/composables/useGetThreadId.ts
Normal file
27
src/composables/useGetThreadId.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { createSharedComposable } from '@vueuse/core'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
/**
|
||||
* Shared composable to get threadId of current thread in conversation
|
||||
*/
|
||||
export const useGetThreadId = createSharedComposable(function() {
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
if (router) {
|
||||
return computed<number>({
|
||||
get: () => route.query.threadId ? Number(route.query.threadId) : 0,
|
||||
set: (value: number) => {
|
||||
router.push({ query: { ...route.query, threadId: value !== 0 ? value : undefined } })
|
||||
},
|
||||
})
|
||||
} else {
|
||||
return ref(0)
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user