Skip to content

Commit e16a995

Browse files
lang parameter removed after language is set
1 parent d054b30 commit e16a995

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/client/components/Rag/Rag.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React, { useState } from 'react'
22
import { TextField, Button, Box, Typography, Table, TableHead, TableBody, TableRow, TableCell, Paper, Link, Container } from '@mui/material'
33
import { useNavigate, Link as RouterLink, useParams } from 'react-router-dom'
4-
import { useRagIndices } from '../../hooks/useRagIndices'
4+
import { useCourseRagIndices, useRagIndices } from '../../hooks/useRagIndices'
55
import { useCreateRagIndexMutation } from './api'
66

77
const Rag: React.FC = () => {
88
const { id: chatInstanceId } = useParams<{ id: string }>()
99
const navigate = useNavigate()
10-
const { ragIndices } = useRagIndices(chatInstanceId, true)
10+
const { ragIndices } = useCourseRagIndices(chatInstanceId, true)
1111
const createIndexMutation = useCreateRagIndexMutation()
1212
const [indexName, setIndexName] = useState('')
1313

src/client/hooks/useUpdateUrlLang.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { useTranslation } from 'react-i18next'
22
import { useLocation, useSearchParams } from 'react-router-dom'
33
import useCurrentUser from '../hooks/useCurrentUser'
44
import { useState, useEffect } from 'react'
5+
import useLocalStorageState from './useLocalStorageState'
56

67
export const useUpdateUrlLang = () => {
78
const languages = ['fi', 'sv', 'en']
89
const { i18n } = useTranslation()
910
const { user } = useCurrentUser()
10-
const [lang, setLanguageState] = useState(localStorage.getItem('lang'))
1111
const [params, setParams] = useSearchParams()
1212
const langParam = params.get('lang')
13-
13+
const [lang, setStorageLang] = useLocalStorageState('lang', 'en')
1414
useEffect(() => {
1515
const updatedLangFromLocal = localStorage.getItem('lang')
1616

@@ -34,16 +34,19 @@ export const useUpdateUrlLang = () => {
3434
}
3535
}, [i18n.language])
3636

37-
// sets both the url and the local lang state to match the newlang if the newLang is supported
37+
// sets the local lang state to match the newlang if the newLang is supported
3838
const setLang = (newLang: string) => {
3939
if (!languages.includes(newLang)) {
4040
console.log('aborted lang update')
4141
return
4242
}
43-
localStorage.setItem('lang', newLang)
44-
setLanguageState(newLang)
43+
setStorageLang(newLang)
4544
i18n.changeLanguage(newLang)
46-
setParams({ lang: newLang })
45+
46+
//we dont want ?lang=?? to stick around since it makes it annoying to navigate so clear the param
47+
48+
params.delete('lang')
49+
setParams(params)
4750
}
4851
return {}
4952
}

0 commit comments

Comments
 (0)