Skip to content

Commit 8666fa1

Browse files
committed
acual lint fix
1 parent 55e612c commit 8666fa1

File tree

119 files changed

+692
-2402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+692
-2402
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"tsc": "tsc",
1212
"lint": "eslint 'src/**/*.{ts,tsx}'",
1313
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
14-
"format": "prettier --write '**/*.{ts,json,css,md}'",
1514
"build": "vite build",
1615
"prepare": "husky install"
1716
},
@@ -31,8 +30,7 @@
3130
"singleQuote": true
3231
},
3332
"lint-staged": {
34-
"src/**/*.{ts,tsx}": "eslint",
35-
"*.{ts,tsx,json,md}": "prettier --write"
33+
"src/**/*.{ts,tsx}": "eslint"
3634
},
3735
"devDependencies": {
3836
"@babel/eslint-parser": "^7.23.10",

src/client/Router.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
RouterProvider,
3-
Route,
4-
createBrowserRouter,
5-
createRoutesFromElements,
6-
} from 'react-router-dom'
1+
import { RouterProvider, Route, createBrowserRouter, createRoutesFromElements } from 'react-router-dom'
72

83
import { PUBLIC_URL } from '../config'
94
import App from './App'
@@ -28,20 +23,17 @@ const router = createBrowserRouter(
2823
<Route path="/courses" element={<Courses />} />
2924
<Route path="/courses/:id" element={<Course />} />
3025
<Route path="/courses/:id/discussions" element={<Discussions />} />
31-
<Route
32-
path="/courses/:id/discussions/:user_id"
33-
element={<Discussion />}
34-
/>
26+
<Route path="/courses/:id/discussions/:user_id" element={<Discussion />} />
3527
<Route path="/admin/*" element={<Admin />} />
3628
<Route path="/noaccess" element={<NoAccess />} />
3729
<Route path="/chats" element={<Chats />} />
3830
<Route path="/statistics" element={<Statistics />} />
3931
<Route path="/rag" element={<Rag />} />
40-
</Route>
32+
</Route>,
4133
),
4234
{
4335
basename: PUBLIC_URL,
44-
}
36+
},
4537
)
4638

4739
const Router = () => <RouterProvider router={router} />

src/client/components/Admin/ChatInstances/ChatInstanceTable.tsx

Lines changed: 27 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import TableCell from '@mui/material/TableCell'
66
import TableContainer from '@mui/material/TableContainer'
77
import TableHead from '@mui/material/TableHead'
88
import TablePagination from '@mui/material/TablePagination'
9-
import {
10-
TextField,
11-
Link,
12-
TableSortLabel,
13-
Checkbox,
14-
InputLabel,
15-
} from '@mui/material'
9+
import { TextField, Link, TableSortLabel, Checkbox, InputLabel } from '@mui/material'
1610
import TableRow from '@mui/material/TableRow'
1711
import { debounce } from 'lodash'
1812
import Paper from '@mui/material/Paper'
@@ -86,36 +80,22 @@ const Head = ({
8680
order,
8781
orderBy,
8882
}: {
89-
onRequestSort: (
90-
event: React.MouseEvent<unknown>,
91-
property: keyof ChatInstanceWithTokens
92-
) => void
83+
onRequestSort: (event: React.MouseEvent<unknown>, property: keyof ChatInstanceWithTokens) => void
9384
order: Order
9485
orderBy: string
9586
}) => {
9687
const { t } = useTranslation()
9788

98-
const createSortHandler =
99-
(property: keyof ChatInstanceWithTokens) =>
100-
(event: React.MouseEvent<unknown>) => {
101-
onRequestSort(event, property)
102-
}
89+
const createSortHandler = (property: keyof ChatInstanceWithTokens) => (event: React.MouseEvent<unknown>) => {
90+
onRequestSort(event, property)
91+
}
10392

10493
return (
10594
<TableHead>
10695
<TableRow>
10796
{headCells.map((headCell) => (
108-
<TableCell
109-
key={headCell.id}
110-
align={headCell.numeric ? 'right' : 'left'}
111-
padding={headCell.disablePadding ? 'none' : 'normal'}
112-
sx={{ pl: 1 }}
113-
>
114-
<TableSortLabel
115-
active={orderBy === headCell.id}
116-
direction={orderBy === headCell.id ? order : 'asc'}
117-
onClick={createSortHandler(headCell.id)}
118-
>
97+
<TableCell key={headCell.id} align={headCell.numeric ? 'right' : 'left'} padding={headCell.disablePadding ? 'none' : 'normal'} sx={{ pl: 1 }}>
98+
<TableSortLabel active={orderBy === headCell.id} direction={orderBy === headCell.id ? order : 'asc'} onClick={createSortHandler(headCell.id)}>
11999
{t(`admin:${headCell.id}`)}
120100
{orderBy === headCell.id ? (
121101
<Box component="span" sx={visuallyHidden}>
@@ -140,10 +120,7 @@ const ChatInstanceTableChatInstanceWithTokens = React.memo(
140120
rows: ChatInstanceWithTokens[]
141121
order: Order
142122
orderBy: string
143-
onRequestSort: (
144-
event: React.MouseEvent<unknown>,
145-
property: keyof ChatInstanceWithTokens
146-
) => void
123+
onRequestSort: (event: React.MouseEvent<unknown>, property: keyof ChatInstanceWithTokens) => void
147124
}) => {
148125
const { i18n } = useTranslation()
149126

@@ -156,13 +133,7 @@ const ChatInstanceTableChatInstanceWithTokens = React.memo(
156133
<TableBody>
157134
{rows.map((row) => (
158135
<TableRow role="checkbox" key={row.id}>
159-
<TableCell
160-
component="th"
161-
scope="row"
162-
padding="none"
163-
width="40%"
164-
sx={{ pl: 1 }}
165-
>
136+
<TableCell component="th" scope="row" padding="none" width="40%" sx={{ pl: 1 }}>
166137
<Link to={`/courses/${row.courseId}`} component={RouterLink}>
167138
{row.name[language]}
168139
</Link>
@@ -187,16 +158,15 @@ const ChatInstanceTableChatInstanceWithTokens = React.memo(
187158
</Table>
188159
</TableContainer>
189160
)
190-
}
161+
},
191162
)
192163

193164
const ChatInstanceTable = () => {
194165
const { t } = useTranslation()
195166
const [search, setSearch] = React.useState('')
196167
const deferredSearch = React.useDeferredValue(search)
197168
const [order, setOrder] = React.useState<Order>('asc')
198-
const [orderBy, setOrderBy] =
199-
React.useState<keyof ChatInstanceWithTokens>('name')
169+
const [orderBy, setOrderBy] = React.useState<keyof ChatInstanceWithTokens>('name')
200170
const [showActiveCourses, setShowActiveCourses] = React.useState(false)
201171

202172
const [page, setPage] = React.useState(0)
@@ -211,34 +181,22 @@ const ChatInstanceTable = () => {
211181
showActiveCourses,
212182
})
213183

214-
const handleChangePage = React.useCallback(
215-
(event: unknown, newPage: number) => {
216-
setPage(newPage)
217-
},
218-
[]
219-
)
184+
const handleChangePage = React.useCallback((event: unknown, newPage: number) => {
185+
setPage(newPage)
186+
}, [])
220187

221-
const handleChangeRowsPerPage = React.useCallback(
222-
(event: React.ChangeEvent<HTMLInputElement>) => {
223-
setRowsPerPage(parseInt(event.target.value, 10))
224-
setPage(0)
225-
},
226-
[]
227-
)
188+
const handleChangeRowsPerPage = React.useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
189+
setRowsPerPage(parseInt(event.target.value, 10))
190+
setPage(0)
191+
}, [])
228192

229-
const handleChangeSearch = debounce(
230-
(event: React.ChangeEvent<HTMLInputElement>) => {
231-
const newSearch = event.target.value
232-
if (newSearch && newSearch.length < 4) return
233-
setSearch(newSearch)
234-
},
235-
300
236-
)
193+
const handleChangeSearch = debounce((event: React.ChangeEvent<HTMLInputElement>) => {
194+
const newSearch = event.target.value
195+
if (newSearch && newSearch.length < 4) return
196+
setSearch(newSearch)
197+
}, 300)
237198

238-
const handleRequestSort = (
239-
event: React.MouseEvent<unknown>,
240-
property: keyof ChatInstanceWithTokens
241-
) => {
199+
const handleRequestSort = (event: React.MouseEvent<unknown>, property: keyof ChatInstanceWithTokens) => {
242200
const isAsc = orderBy === property && order === 'asc'
243201
setOrder(isAsc ? 'desc' : 'asc')
244202
setOrderBy(property)
@@ -249,22 +207,13 @@ const ChatInstanceTable = () => {
249207
<Paper sx={{ width: '100%', mb: 2 }}>
250208
<Box>
251209
<InputLabel>
252-
<Checkbox
253-
checked={showActiveCourses}
254-
onChange={() => setShowActiveCourses(!showActiveCourses)}
255-
inputProps={{ 'aria-label': 'controlled' }}
256-
/>
210+
<Checkbox checked={showActiveCourses} onChange={() => setShowActiveCourses(!showActiveCourses)} inputProps={{ 'aria-label': 'controlled' }} />
257211

258212
{t(`course:showActiveCourses`)}
259213
</InputLabel>
260214
</Box>
261215
<Box sx={{ display: 'flex', alignItems: 'center' }}>
262-
<TextField
263-
label={t('admin:searchCourse')}
264-
variant="outlined"
265-
sx={{ flex: 1, m: 1 }}
266-
onChange={handleChangeSearch}
267-
/>
216+
<TextField label={t('admin:searchCourse')} variant="outlined" sx={{ flex: 1, m: 1 }} onChange={handleChangeSearch} />
268217
<TablePagination
269218
rowsPerPageOptions={[10, 50, 100]}
270219
component="div"
@@ -276,14 +225,7 @@ const ChatInstanceTable = () => {
276225
labelRowsPerPage={t('admin:rowsPerPage')}
277226
/>
278227
</Box>
279-
{!isLoading && (
280-
<ChatInstanceTableChatInstanceWithTokens
281-
rows={chatInstances}
282-
onRequestSort={handleRequestSort}
283-
order={order}
284-
orderBy={orderBy}
285-
/>
286-
)}
228+
{!isLoading && <ChatInstanceTableChatInstanceWithTokens rows={chatInstances} onRequestSort={handleRequestSort} order={order} orderBy={orderBy} />}
287229
</Paper>
288230
</Box>
289231
)

src/client/components/Admin/ChatInstances/useChatInstances.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,14 @@ interface ChatInstanceWithTokens extends ChatInstance {
88
tokenUsage: number
99
}
1010

11-
const useChatInstances = ({
12-
limit = 100,
13-
offset = 0,
14-
search = '',
15-
order = '',
16-
orderBy = '',
17-
showActiveCourses = false,
18-
}) => {
19-
const queryKey = [
20-
'chatInstances',
21-
{ limit, offset, search, order, orderBy, showActiveCourses },
22-
]
11+
const useChatInstances = ({ limit = 100, offset = 0, search = '', order = '', orderBy = '', showActiveCourses = false }) => {
12+
const queryKey = ['chatInstances', { limit, offset, search, order, orderBy, showActiveCourses }]
2313

2414
const queryFn = async (): Promise<{
2515
chatInstances: ChatInstanceWithTokens[]
2616
count: number
2717
}> => {
28-
const res = await apiClient.get(
29-
`/chatinstances?limit=${limit}&offset=${offset}&search=${search}&orderBy=${orderBy}&order=${order}&showActiveCourses=${showActiveCourses}`
30-
)
18+
const res = await apiClient.get(`/chatinstances?limit=${limit}&offset=${offset}&search=${search}&orderBy=${orderBy}&order=${order}&showActiveCourses=${showActiveCourses}`)
3119

3220
const { data } = res
3321

src/client/components/Admin/ChatInstances/utils.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import { ChatInstance, ChatInstanceUsage } from '../../../types'
22

3-
export const calculateCourseUsage = (
4-
usage: ChatInstanceUsage[],
5-
courses: ChatInstance[]
6-
) => {
3+
export const calculateCourseUsage = (usage: ChatInstanceUsage[], courses: ChatInstance[]) => {
74
const courseUsage = courses.map((course) => ({
85
course,
96
usageCount: 0,
107
}))
118

12-
const filteredUsage = usage.filter((u) =>
13-
courses.map((course) => course.id).includes(u.chatInstance.id)
14-
)
9+
const filteredUsage = usage.filter((u) => courses.map((course) => course.id).includes(u.chatInstance.id))
1510

1611
filteredUsage.forEach(({ usageCount, chatInstance }) => {
17-
const course = courseUsage.find(
18-
({ course: { id } }) => id === chatInstance.id
19-
)
12+
const course = courseUsage.find(({ course: { id } }) => id === chatInstance.id)
2013
if (course) course.usageCount += usageCount
2114
})
2215

src/client/components/Admin/EditTexts.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,13 @@ const Text = ({ info }: { info: InfoText }) => {
3838
<>
3939
<Stack gap={2} sx={{ my: 2 }}>
4040
<Typography variant="h6">FI</Typography>
41-
<TextField
42-
defaultValue={info.text.fi}
43-
multiline
44-
onChange={(e) => setFi(e.target.value)}
45-
/>
41+
<TextField defaultValue={info.text.fi} multiline onChange={(e) => setFi(e.target.value)} />
4642
<Typography variant="h6">SV</Typography>
47-
<TextField
48-
defaultValue={info.text.sv}
49-
multiline
50-
onChange={(e) => setSv(e.target.value)}
51-
/>
43+
<TextField defaultValue={info.text.sv} multiline onChange={(e) => setSv(e.target.value)} />
5244
<Typography variant="h6">EN</Typography>
53-
<TextField
54-
defaultValue={info.text.en}
55-
multiline
56-
onChange={(e) => setEn(e.target.value)}
57-
/>
45+
<TextField defaultValue={info.text.en} multiline onChange={(e) => setEn(e.target.value)} />
5846
</Stack>
59-
<Button
60-
onClick={() => handleSave()}
61-
variant="outlined"
62-
sx={{ mr: 2 }}
63-
>
47+
<Button onClick={() => handleSave()} variant="outlined" sx={{ mr: 2 }}>
6448
{t('common:save')}
6549
</Button>
6650
</>

src/client/components/Admin/Usage/CourseTable.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
1-
import {
2-
Table,
3-
TableContainer,
4-
TableBody,
5-
TableCell,
6-
TableHead,
7-
TableRow,
8-
Paper,
9-
Typography,
10-
Box,
11-
} from '@mui/material'
1+
import { Table, TableContainer, TableBody, TableCell, TableHead, TableRow, Paper, Typography, Box } from '@mui/material'
122
import { useTranslation } from 'react-i18next'
133

144
import { ChatInstanceUsage, Course } from '../../../types'
155
import useChatInstanceUsage from '../../../hooks/useChatInstanceUsage'
166
import useUserCourses from '../../../hooks/useUserCourses'
177

18-
const calculateCourseUsage = (
19-
usage: ChatInstanceUsage[],
20-
courses: Course[]
21-
) => {
8+
const calculateCourseUsage = (usage: ChatInstanceUsage[], courses: Course[]) => {
229
const courseUsage = courses.map((course) => ({
2310
course,
2411
usageCount: 0,
2512
}))
2613

2714
usage.forEach(({ usageCount, chatInstance }) => {
28-
const course = courseUsage.find(
29-
({ course: { id } }) => id === chatInstance.id
30-
)
15+
const course = courseUsage.find(({ course: { id } }) => id === chatInstance.id)
3116
if (course) course.usageCount += usageCount
3217
})
3318

3419
return courseUsage
3520
}
3621

37-
const sortUsage =
38-
(language: string) => (a: { course: Course }, b: { course: Course }) =>
39-
a.course.name[language].localeCompare(b.course.name[language])
22+
const sortUsage = (language: string) => (a: { course: Course }, b: { course: Course }) => a.course.name[language].localeCompare(b.course.name[language])
4023

4124
const CourseTable = () => {
4225
const { usage, isLoading } = useChatInstanceUsage()

0 commit comments

Comments
 (0)