Files
boursecu_user/src/views/base/rules/composables/useRulesPage.ts
T

51 lines
1.5 KiB
TypeScript
Raw Normal View History

import { computed, inject, provide, type InjectionKey } from 'vue'
import { useConfigStore } from '@/store/configStore'
import {
getProjectBaleLink,
getProjectSupportPhoneLink,
} from '@/utils/config'
import { getRulesBlocks, getRulesTitle, type RulesBlock } from '../rulesContent'
export interface RulesPageContext {
config: ReturnType<typeof useConfigStore>
nameProject: ReturnType<typeof computed<string>>
rulesTitle: ReturnType<typeof computed<string>>
rulesBlocks: ReturnType<typeof computed<RulesBlock[]>>
getProjectSupportPhoneLink: typeof getProjectSupportPhoneLink
getProjectBaleLink: typeof getProjectBaleLink
}
export const RULES_PAGE_CONTEXT_KEY: InjectionKey<RulesPageContext> = Symbol('rulesPageContext')
export function useRulesPage() {
const config = useConfigStore()
const nameProject = computed(
() => config.config?.name_fa || config.config?.name || 'بورس مس',
)
const rulesTitle = computed(() => getRulesTitle(nameProject.value, true))
const rulesBlocks = computed(() => getRulesBlocks(nameProject.value, true))
const context: RulesPageContext = {
config,
nameProject,
rulesTitle,
rulesBlocks,
getProjectSupportPhoneLink,
getProjectBaleLink,
}
provide(RULES_PAGE_CONTEXT_KEY, context)
return context
}
export function useRulesPageContext() {
const context = inject(RULES_PAGE_CONTEXT_KEY)
if (!context) {
throw new Error('useRulesPageContext must be used within a page that calls useRulesPage()')
}
return context
}