Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Jul 8, 2024
1 parent 0dc7abc commit 89849ec
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
11 changes: 10 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<script setup lang="ts"></script>
<script setup lang="ts">
import { useSettings } from '@stores/useSettings'
import { updateCredential } from './api'
const { cookie } = storeToRefs(useSettings())
onBeforeMount(() => {
updateCredential(cookie.value)
})
</script>

<template>
<div
Expand Down
1 change: 1 addition & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const apiClient = new CatClient({
port: getPort(),
secure: window.location.protocol === 'https:',
timeout: 15000,
instant: false,
ws: {
retries: 3,
delay: 3000,
Expand Down
10 changes: 4 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ import { createPinia } from 'pinia'
import { defineRule } from 'vee-validate'
import { all as AllRules } from '@vee-validate/rules'
import vLock from '@/directives/vLock'

Object.keys(AllRules).forEach(rule => {
defineRule(rule, AllRules[rule])
})

import App from '@/App.vue'
import router from '@/router'

import 'unfonts.css'
import 'animate.css'
import '@assets/main.css'
import { cloneDeep } from 'lodash'

Object.keys(AllRules).forEach(rule => {
defineRule(rule, AllRules[rule])
})

const app = createApp(App)

const pinia = createPinia()
Expand Down
6 changes: 5 additions & 1 deletion src/stores/useMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const useMemory = defineStore('memory', () => {
data: [],
})

const { state: collections, isLoading, execute: fetchCollections } = useAsyncState(MemoryService.getCollections, undefined)
const {
state: collections,
isLoading,
execute: fetchCollections,
} = useAsyncState(MemoryService.getCollections, undefined, { resetOnExecute: false })

watchEffect(() => {
currentState.loading = isLoading.value
Expand Down
2 changes: 1 addition & 1 deletion src/stores/useMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useMessages = defineStore('messages', () => {
],
})

const { state: history } = useAsyncState(MemoryService.getConversation, [])
const { state: history } = useAsyncState(MemoryService.getConversation, [], { resetOnExecute: false })

watchEffect(() => {
history.value.forEach(({ who, message, why, when }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/usePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const usePlugins = defineStore('plugins', () => {
},
})

const { state: plugins, isLoading, execute: fetchPlugins } = useAsyncState(PluginService.getPlugins, undefined)
const { state: settings, execute: fetchSettings } = useAsyncState(PluginService.getPluginsSettings, undefined)
const { state: plugins, isLoading, execute: fetchPlugins } = useAsyncState(PluginService.getPlugins, undefined, { resetOnExecute: false })
const { state: settings, execute: fetchSettings } = useAsyncState(PluginService.getPluginsSettings, undefined, { resetOnExecute: false })

const { showNotification, sendNotificationFromJSON } = useNotifications()

Expand Down
13 changes: 1 addition & 12 deletions src/stores/useSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { apiClient, tryRequest } from '@/api'
import { useJwt } from '@vueuse/integrations/useJwt'
import { useCookies } from '@vueuse/integrations/useCookies'
import type { Status, AuthPermission, AuthResource } from 'ccat-api'
import type { AuthPermission, AuthResource } from 'ccat-api'
import type { JwtPayload } from 'jwt-decode'

interface Filter {
Expand Down Expand Up @@ -49,22 +48,12 @@ export const useSettings = defineStore('settings', () => {
},
})

const getStatus = async () => {
const result = await tryRequest(apiClient.api?.status.home(), 'Getting Cheshire Cat status', 'Unable to fetch Cheshire Cat status')
return result.data ?? result.message
}

const { state: cat, execute } = useAsyncState(getStatus, {} as Status)

return {
isDark,
pluginsFilters,
toggleDark,
cat,
cookie,
jwt,
getStatus,
refreshStatus: execute,
}
})

Expand Down
12 changes: 9 additions & 3 deletions src/views/SettingsView.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<script setup lang="ts">
import { apiClient, tryRequest } from '@/api'
import SidePanel from '@components/SidePanel.vue'
import { useSettings } from '@stores/useSettings'
import type { Status } from 'ccat-api'
const { cat } = storeToRefs(useSettings())
const getStatus = async () => {
const result = await tryRequest(apiClient.api?.status.home(), 'Getting Cheshire Cat status', 'Unable to fetch Cheshire Cat status')
return result.data
}
const { state: cat } = useAsyncState(getStatus, {} as Status, { resetOnExecute: false })
const panelTitles = {
embedder: 'Configure the Embedder',
Expand All @@ -24,7 +30,7 @@ const openSidePanel = (title: keyof typeof panelTitles) => {
<p class="text-lg font-bold">
Cheshire Cat AI - Version
<span class="text-primary">
{{ typeof cat == 'string' ? 'unknown' : cat.version }}
{{ cat ? cat.version : 'unknown' }}
</span>
</p>
</div>
Expand Down

0 comments on commit 89849ec

Please sign in to comment.