store.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { createStore } from 'zustand'
  2. import type { Features } from './types'
  3. import { Resolution, TransferMethod } from '@/types/app'
  4. export type FeaturesModal = {
  5. showFeaturesModal: boolean
  6. setShowFeaturesModal: (showFeaturesModal: boolean) => void
  7. }
  8. export type FeaturesState = {
  9. features: Features
  10. }
  11. export type FeaturesAction = {
  12. setFeatures: (features: Features) => void
  13. }
  14. export type FeatureStoreState = FeaturesState & FeaturesAction & FeaturesModal
  15. export type FeaturesStore = ReturnType<typeof createFeaturesStore>
  16. export const createFeaturesStore = (initProps?: Partial<FeaturesState>) => {
  17. const DEFAULT_PROPS: FeaturesState = {
  18. features: {
  19. moreLikeThis: {
  20. enabled: false,
  21. },
  22. opening: {
  23. enabled: false,
  24. },
  25. suggested: {
  26. enabled: false,
  27. },
  28. text2speech: {
  29. enabled: false,
  30. },
  31. speech2text: {
  32. enabled: false,
  33. },
  34. citation: {
  35. enabled: false,
  36. },
  37. moderation: {
  38. enabled: false,
  39. },
  40. file: {
  41. image: {
  42. enabled: false,
  43. detail: Resolution.high,
  44. number_limits: 3,
  45. transfer_methods: [TransferMethod.local_file, TransferMethod.remote_url],
  46. },
  47. },
  48. annotationReply: {
  49. enabled: false,
  50. },
  51. },
  52. }
  53. return createStore<FeatureStoreState>()(set => ({
  54. ...DEFAULT_PROPS,
  55. ...initProps,
  56. setFeatures: features => set(() => ({ features })),
  57. showFeaturesModal: false,
  58. setShowFeaturesModal: showFeaturesModal => set(() => ({ showFeaturesModal })),
  59. }))
  60. }