Skip to content

Commit 69d7597

Browse files
committed
Fix scroll to bottom btn appearing always after page load
1 parent d1aeaf1 commit 69d7597

File tree

11 files changed

+30
-38
lines changed

11 files changed

+30
-38
lines changed

e2e/prompts.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test.describe('Prompts', () => {
4848
await expect(page.getByTestId('assistant-instructions-input')).toContainText('mocktest testi onnistui')
4949
})
5050

51-
test.only('Course prompt creation, chat link with prompt, and deletion', async ({ page }) => {
51+
test('Course prompt creation, chat link with prompt, and deletion', async ({ page }) => {
5252
await page.goto('/courses/test-course/prompts')
5353

5454
const newPromptName = `testausprompti-${test.info().workerIndex}`

src/client/components/ChatV2/ChatBox.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ export const ChatBox = ({
2222
fileName,
2323
tokenUsageWarning,
2424
tokenUsageAlertOpen,
25-
saveConsent,
26-
setSaveConsent,
2725
setChatLeftSidePanelOpen,
28-
chatLeftSidePanelOpen,
29-
saveChat,
30-
notOptoutSaving,
3126
setFileName,
3227
handleCancel,
3328
handleContinue,
@@ -40,12 +35,7 @@ export const ChatBox = ({
4035
fileName: string
4136
tokenUsageWarning: string
4237
tokenUsageAlertOpen: boolean
43-
saveConsent: boolean
44-
setSaveConsent: React.Dispatch<boolean>
4538
setChatLeftSidePanelOpen: (open: boolean) => void
46-
chatLeftSidePanelOpen: boolean
47-
saveChat: boolean
48-
notOptoutSaving: boolean
4939
setFileName: (name: string) => void
5040
handleCancel: () => void
5141
handleContinue: (message: string) => void
@@ -70,12 +60,12 @@ export const ChatBox = ({
7060

7161
const { t } = useTranslation()
7262

73-
// useKeyboardCommands({
74-
// resetChat: handleReset,
75-
// openModelSelector: () => {
76-
// setIsModelSelectorOpen(true)
77-
// },
78-
// }) // @todo what key combination to open model selector
63+
useKeyboardCommands({
64+
resetChat: handleReset,
65+
openModelSelector: () => {
66+
// setIsModelSelectorOpen(true) // @todo what key combination to open model selector
67+
},
68+
})
7969

8070
const isShiftEnterSend = user?.preferences?.sendShortcutMode === 'shift+enter' || !user?.preferences?.sendShortcutMode
8171

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { ChatMessage, MessageGenerationInfo, ToolCallResultEvent } from '..
1212
import type { RagIndexAttributes } from '../../../shared/types'
1313
import { getLanguageValue } from '../../../shared/utils'
1414
import { useIsEmbedded } from '../../contexts/EmbeddedContext'
15-
import { useChatScroll } from '../../hooks/useChatScroll'
15+
import { useChatScroll } from './useChatScroll'
1616
import useCourse from '../../hooks/useCourse'
1717
import useCurrentUser from '../../hooks/useCurrentUser'
1818
import useInfoTexts from '../../hooks/useInfoTexts'
@@ -503,14 +503,9 @@ export const ChatV2 = () => {
503503
fileInputRef={fileInputRef}
504504
fileName={fileName}
505505
setFileName={setFileName}
506-
saveConsent={saveConsent}
507-
setSaveConsent={setSaveConsent}
508506
setChatLeftSidePanelOpen={setChatLeftSidePanelOpen}
509-
chatLeftSidePanelOpen={chatLeftSidePanelOpen}
510507
tokenUsageWarning={tokenUsageWarning}
511508
tokenUsageAlertOpen={tokenUsageAlertOpen}
512-
saveChat={!!course && course.saveDiscussions}
513-
notOptoutSaving={!!course && course.notOptoutSaving}
514509
handleCancel={handleCancel}
515510
handleContinue={(newMessage) => handleSubmit(newMessage, true)}
516511
handleSubmit={(newMessage) => {

src/client/components/ChatV2/PromptSelector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const PromptSelector = ({
9494
))}
9595
</>
9696
)}
97+
{myPrompts.length === 0 && coursePrompts.length === 0 && <MenuItem disabled>{t('settings:noPrompts')}</MenuItem>}
9798
</Menu>
9899
</Box>
99100
)

src/client/components/ChatV2/SaveMyPromptModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const SaveMyPromptModal = ({ isOpen, setIsOpen, onSave, systemMessage, ex
3232
>
3333
<form
3434
onSubmit={async (e) => {
35-
console.log('Saving', name)
3635
e.preventDefault()
3736
await onSave(name, promptToSave)
3837
setIsOpen(false)

src/client/components/ChatV2/SettingsModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({
153153
}, [mandatoryPrompt, urlPrompt])
154154

155155
const handleClose = async () => {
156-
console.log('handleClose', activePrompt, systemMessage)
157156
// When no prompt is selected, set the custom system message to the value of the system message textfield
158157
if (!activePrompt) {
159158
setCustomSystemMessage(systemMessage)

src/client/hooks/useChatScroll.ts renamed to src/client/components/ChatV2/useChatScroll.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import { useEffect, useRef, useState, useTransition } from 'react'
22

33
let isUserDisabled = false
44

5+
const isAtBottom = () => {
6+
const element = document.documentElement
7+
const dist = element.scrollHeight - element.clientHeight - element.scrollTop
8+
return Math.abs(dist) <= 3
9+
}
10+
511
export const useChatScroll = () => {
612
// Todo: on long conversations this state update is not optimal. Ideally move it down the component tree.
7-
const [isAutoScrolling, setIsAutoScrolling] = useState(false)
13+
const [isAutoScrolling, setIsAutoScrolling] = useState(true)
814

915
const prevHeight = useRef(0)
1016

@@ -40,10 +46,15 @@ export const useChatScroll = () => {
4046
}
4147

4248
useEffect(() => {
49+
// Check scroll status after a delay
50+
setTimeout(() => {
51+
if (!isAtBottom()) {
52+
setIsAutoScrolling(false)
53+
}
54+
}, 100)
55+
4356
const handleAttachAutoScroll = () => {
44-
const element = document.documentElement
45-
const isAtBottom = Math.abs(element.scrollHeight - element.clientHeight - element.scrollTop) <= 3
46-
if (isAtBottom) {
57+
if (isAtBottom()) {
4758
setIsAutoScrolling(true)
4859
isUserDisabled = false
4960
}

src/client/components/Rag/RagIndex.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const RagIndex: React.FC = () => {
4545
type="file"
4646
onChange={async (event) => {
4747
const files = event.target.files
48-
console.log('Files selected:', files)
4948
if (files && files.length > 0) {
5049
await uploadMutation.mutateAsync(files)
5150
refetch()

src/client/locales/en.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
"confirmDeletePrompt": "Are you sure you want to delete the prompt '{{name}}'?",
138138
"selectedSource": "No selected source",
139139
"sourceDescription": "Materials specified by the teacher can be used as a source in the course chat. You can select the source below.",
140-
"other": "Other settings"
140+
"other": "Other settings",
141+
"noPrompts": "No prompts"
141142
},
142143
"email": {
143144
"save": "Save as email",
@@ -354,4 +355,4 @@
354355
"nameLabel": "Collection name",
355356
"nameHelperText": "Use a descriptive name (for example the full name of the course)"
356357
}
357-
}
358+
}

src/client/locales/fi.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
"default": "Oletus",
138138
"confirmDeletePrompt": "Haluatko varmasti poistaa alustuksen '{{name}}'?",
139139
"sourceDescription": "Kurssichatissa voidaan käyttää lähteenä opettajan määrittämiä materiaaleja. Voit valita lähteen alta.",
140-
"other": "Muut asetukset"
140+
"other": "Muut asetukset",
141+
"noPrompts": "Ei alustuksia"
141142
},
142143
"chats": {
143144
"header": "Auki olevat kurssichatit",
@@ -354,4 +355,4 @@
354355
"nameLabel": "Kokoelman nimi",
355356
"nameHelperText": "Käytä kuvaavaa nimeä (esim. kurssin koko nimi)"
356357
}
357-
}
358+
}

0 commit comments

Comments
 (0)