feat: lint code

This commit is contained in:
Joel
2023-06-10 14:04:40 +08:00
parent 2e46f795a4
commit cfd0c9532f
36 changed files with 226 additions and 210 deletions

View File

@ -8,20 +8,22 @@ export enum MediaType {
}
const useBreakpoints = () => {
const [width, setWidth] = React.useState(globalThis.innerWidth);
const [width, setWidth] = React.useState(globalThis.innerWidth)
const media = (() => {
if (width <= 640) return MediaType.mobile;
if (width <= 768) return MediaType.tablet;
return MediaType.pc;
})();
if (width <= 640)
return MediaType.mobile
if (width <= 768)
return MediaType.tablet
return MediaType.pc
})()
React.useEffect(() => {
const handleWindowResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleWindowResize);
return () => window.removeEventListener("resize", handleWindowResize);
}, []);
const handleWindowResize = () => setWidth(window.innerWidth)
window.addEventListener('resize', handleWindowResize)
return () => window.removeEventListener('resize', handleWindowResize)
}, [])
return media;
return media
}
export default useBreakpoints
export default useBreakpoints

View File

@ -1,6 +1,6 @@
import { useState } from 'react'
import type { ConversationItem } from '@/types/app'
import produce from 'immer'
import type { ConversationItem } from '@/types/app'
const storageConversationIdKey = 'conversationIdInfo'
@ -29,9 +29,10 @@ function useConversation() {
// input can be updated by user
const [newConversationInputs, setNewConversationInputs] = useState<Record<string, any> | null>(null)
const resetNewConversationInputs = () => {
if (!newConversationInputs) return
setNewConversationInputs(produce(newConversationInputs, draft => {
Object.keys(draft).forEach(key => {
if (!newConversationInputs)
return
setNewConversationInputs(produce(newConversationInputs, (draft) => {
Object.keys(draft).forEach((key) => {
draft[key] = ''
})
}))
@ -59,8 +60,8 @@ function useConversation() {
setCurrInputs,
currConversationInfo,
setNewConversationInfo,
setExistConversationInfo
setExistConversationInfo,
}
}
export default useConversation;
export default useConversation