Fix the issue where useSettings does not work in SSR mode.

This commit is contained in:
Rafi
2023-04-06 16:07:46 +08:00
parent 82c1811034
commit 8a9b705b99
5 changed files with 23 additions and 20 deletions

View File

@@ -1,3 +1,12 @@
<script setup>
onNuxtReady(() => {
fetchSystemSettings()
// api key
const apiKey = useApiKey()
apiKey.value = getStoredApiKey()
})
</script>
<template> <template>
<NuxtLayout> <NuxtLayout>
<NuxtLoadingIndicator /> <NuxtLoadingIndicator />

View File

@@ -166,20 +166,18 @@ const deleteMessage = (index) => {
props.conversation.messages.splice(index, 1) props.conversation.messages.splice(index, 1)
} }
const showWebSearchToggle = ref(false)
const enableWebSearch = ref(false)
const enableCustomApiKey = ref(false)
const settings = useSettings() const settings = useSettings()
const enableWebSearch = ref(false)
watchEffect(() => { const showWebSearchToggle = computed(() => {
if (settings.value) { return settings.value && settings.value.open_web_search && settings.value.open_web_search === 'True'
const settingsValue = toRaw(settings.value)
showWebSearchToggle.value = settingsValue.open_web_search && settingsValue.open_web_search === 'True'
enableCustomApiKey.value = settingsValue.open_api_key_setting && settingsValue.open_api_key_setting === 'True'
}
}) })
const enableCustomApiKey = computed(() => {
return settings.value && settings.value.open_api_key_setting && settings.value.open_api_key_setting === 'True'
})
onNuxtReady(() => { onNuxtReady(() => {
currentModel.value = getCurrentModel() currentModel.value = getCurrentModel()
}) })

View File

@@ -89,12 +89,8 @@ const loadConversations = async () => {
} }
const settings = useSettings() const settings = useSettings()
const showApiKeySetting = ref(false) const showApiKeySetting = computed(() => {
watchEffect(() => { return settings.value && settings.value.open_api_key_setting && settings.value.open_api_key_setting === 'True'
if (settings.value) {
const settingsValue = toRaw(settings.value)
showApiKeySetting.value = settingsValue.open_api_key_setting && settingsValue.open_api_key_setting === 'True'
}
}) })
const signOut = async () => { const signOut = async () => {

View File

@@ -7,7 +7,7 @@ export const useApiKey = () => useState('apiKey', () => getStoredApiKey())
export const useConversations = () => useState('conversations', () => []) export const useConversations = () => useState('conversations', () => [])
export const useSettings = () => useState('settings', () => getSystemSettings()) export const useSettings = () => useState('settings', () => {})
export const useUser = () => useState('user', () => null) export const useUser = () => useState('user', () => null)

View File

@@ -53,14 +53,14 @@ const transformData = (list) => {
return result; return result;
} }
export const getSystemSettings = async () => { export const fetchSystemSettings = async () => {
const { data, error } = await useAuthFetch('/api/chat/settings/', { const { data, error } = await useAuthFetch('/api/chat/settings/', {
method: 'GET', method: 'GET',
}) })
if (!error.value) { if (!error.value) {
return transformData(data.value) const settings = useSettings()
settings.value = transformData(data.value)
} }
return {}
} }
export const fetchUser = async () => { export const fetchUser = async () => {