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:
Maksim Sukharev
2025-07-11 15:22:02 +02:00
parent 63b0782823
commit ffda9b5826

View 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)
}
})