Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use instead of #217

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/ChatBox/ContactHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { configurationDrawerVisibleState, onlineState } from 'src/stores/global'
import { EmojiPickerProps } from 'src/types/global'
import Avatar from '../Avatar'
import EmojiPicker from '../EmojiPicker'
import toast from '../Snackbar'
import Toast from '../Snackbar'

const ContactHeader: FC = () => {
const loading = useRecoilValue(loadingState)
Expand Down Expand Up @@ -51,15 +51,15 @@ const ContactHeader: FC = () => {

const openAvatarPicker = () => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}
setAvatarPickerVisible(true)
}

const openSummaryInput = () => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}
if (!currConversation) return
Expand All @@ -69,7 +69,7 @@ const ContactHeader: FC = () => {

const openConfigurationDrawer = () => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}
setConfigurationDrawerVisible(true)
Expand Down Expand Up @@ -110,7 +110,7 @@ const ContactHeader: FC = () => {

const deleteCurrConversation = async () => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}
if (currConversation) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/ChatBox/InputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ const InputBox: FC = () => {
const handleRequest = () => {
if (!validate()) return

requests[currProduct]()
if (requests[currProduct]) {
requests[currProduct]()
}
resetInput()
}

Expand Down Expand Up @@ -122,6 +124,7 @@ const InputBox: FC = () => {
placeholder="Type a message..."
value={prompt}
rows={1}
// FIXME: The webkit(safari) doesn't support `onCompositionStart` or `onCompositionEnd`.
onCompositionStart={() => setIsTyping(true)}
onCompositionEnd={() => setIsTyping(false)}
onChange={(e) => setPrompt(e.target.value)}
Expand Down
1 change: 1 addition & 0 deletions src/components/ChatBox/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FC, memo } from 'react'
import ReactMarkdown from 'react-markdown'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { oneDark as mdCodeTheme } from 'react-syntax-highlighter/dist/esm/styles/prism'
// @ts-ignore
import rehypeMathjax from 'rehype-mathjax'
import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'
Expand Down
6 changes: 3 additions & 3 deletions src/components/ConversationList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Conversation } from 'src/types/conversation'
import { v4 } from 'uuid'
import Divider from '../Divider'
import { OutlinePlusIcon } from '../Icons'
import toast from '../Snackbar'
import Toast from '../Snackbar'
import ConversationItem from './ConversationItem'
import ChatEmpty from './EmptyItem'

Expand All @@ -28,7 +28,7 @@ const ConversationList: FC<Props> = ({ conversations }) => {

const addConversation = async () => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}

Expand All @@ -49,7 +49,7 @@ const ConversationList: FC<Props> = ({ conversations }) => {

const switchConversation = (conversation: Conversation) => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}
setCurrConversation(conversation)
Expand Down
8 changes: 4 additions & 4 deletions src/components/ImportAndExportDexie/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BaseDirectory, writeTextFile } from '@tauri-apps/plugin-fs'
import Dexie from 'dexie'
import { exportDB, importDB } from 'dexie-export-import'
import { ChangeEvent, FC, useRef } from 'react'
import toast from '../Snackbar'
import Toast from '../Snackbar'

const ImportAndExportDexie: FC = () => {
const inputRef = useRef<HTMLInputElement>(null)
Expand All @@ -22,13 +22,13 @@ const ImportAndExportDexie: FC = () => {
baseDir: BaseDirectory.Download
})

toast.success(
Toast.success(
`The ${filename} has been saved in your local Download Directory.`
)
} catch (e) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
toast.error(e.toString())
Toast.error(e.toString())
}
}

Expand All @@ -42,7 +42,7 @@ const ImportAndExportDexie: FC = () => {
} catch (e: unknown) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
toast.error(e.message)
Toast.error(e.message)
} finally {
if (inputRef.current) {
inputRef.current.value = ''
Expand Down
18 changes: 10 additions & 8 deletions src/components/InputSlider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ const InputSlider: FC<Props> = ({
</div>

<TextField
InputLabelProps={{ shrink: true }}
slotProps={{
inputLabel: { shrink: true },
htmlInput: {
inputMode: 'numeric',
pattern: '[0-9]*',
step,
min,
max
}
}}
type="number"
value={value}
onChange={handleInputChange}
onBlur={handleBlur}
size="small"
inputProps={{
inputMode: 'numeric',
pattern: '[0-9]*',
step,
min,
max
}}
sx={{
width: 100
}}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { currProductState } from 'src/stores/global'
import { Companies, Products } from 'src/types/global'
import Avatar from '../Avatar'
import Divider from '../Divider'
import toast from '../Snackbar'
import Toast from '../Snackbar'
import items, { iconClassName } from './Items'

const companyLogo = {
Expand All @@ -34,7 +34,7 @@ const Sidebar: FC = () => {

const onProductChange = async (e: MouseEvent, product: Products) => {
if (loading) {
toast.warning(BAN_ACTIVE_HINT)
Toast.warning(BAN_ACTIVE_HINT)
return
}
window.localStorage.setItem('currProductState', product)
Expand Down
14 changes: 7 additions & 7 deletions src/components/Snackbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ export const SnackbarUtilsConfig = () => {
return <InnerSnackbarUtilsConfig setUseSnackbarRef={setUseSnackbarRef} />
}

const toast = {
const Toast = {
success(msg: string) {
this.toast(msg, 'success')
this.Toast(msg, 'success')
},
warning(msg: string) {
this.toast(msg, 'warning')
this.Toast(msg, 'warning')
},
info(msg: string) {
this.toast(msg, 'info')
this.Toast(msg, 'info')
},
error(msg: string) {
this.toast(msg, 'error')
this.Toast(msg, 'error')
},
toast(msg: string, variant: VariantType = 'default') {
Toast(msg: string, variant: VariantType = 'default') {
useSnackbarRef.enqueueSnackbar(msg, { variant })
}
}

export default toast
export default Toast
4 changes: 2 additions & 2 deletions src/containers/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ChangeEvent, FC } from 'react'
import ChatGPTImg from 'src/assets/chatbot.png'
import { SolidSettingsBrightnessIcon } from 'src/components/Icons'
import ImportAndExportDexie from 'src/components/ImportAndExportDexie'
import toast from 'src/components/Snackbar'
import Toast from 'src/components/Snackbar'
import { useAppData, useSettings, useTheme } from 'src/hooks'
import { Companies, ThemeMode } from 'src/types/global'
import { Settings as SettingsParams } from 'src/types/settings'
Expand All @@ -36,7 +36,7 @@ const Settings: FC = () => {
const filename = await saveFileToAppDataDir(file)
if (filename) {
updateSettings({ ...settings, assistantAvatarFilename: filename })
toast.success('Assistant avatar updated successfully.')
Toast.success('Assistant avatar updated successfully.')
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { useRecoilState } from 'recoil'
import toast from 'src/components/Snackbar'
import Toast from 'src/components/Snackbar'
import { useDB } from 'src/hooks'
import { settingsState } from 'src/stores/settings'
import { Companies, ThemeMode } from 'src/types/global'
Expand Down Expand Up @@ -52,7 +52,7 @@ const useSettings = () => {
setSettings(newSettings)
}

toast.success('Settings updated successfully.')
Toast.success('Settings updated successfully.')
}

const getSettings = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encodingForModel, TiktokenModel } from 'js-tiktoken'
import { DateTime } from 'luxon'
import toast from 'src/components/Snackbar'
import Toast from 'src/components/Snackbar'
import { Products, ThemeMode } from 'src/types/global'
import { v4 } from 'uuid'
import { getFileExtension } from 'yancey-js-util'
Expand Down Expand Up @@ -59,4 +59,4 @@ export const getTokensCount = (content: string, model: TiktokenModel) =>

// Output a simple error if request failed.
// TODO: Output the error message thrown by the OpenAI or Azure API.
export const showApiRequestErrorToast = () => toast.error(`Request failed.`)
export const showApiRequestErrorToast = () => Toast.error(`Request failed.`)
Loading