Skip to content

Commit

Permalink
feat: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Расул authored and Расул committed Feb 2, 2024
1 parent 03cfd78 commit 76a9b10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
16 changes: 7 additions & 9 deletions src/components/App/Helper/AskQuestion/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextareaAutosize } from '@mui/base'
import { FormControl, InputLabel, MenuItem, OutlinedInput, Select, SelectChangeEvent } from '@mui/material'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { MdSend } from 'react-icons/md'
import { PropagateLoader } from 'react-spinners'
import { toast } from 'react-toastify'
Expand All @@ -10,6 +10,7 @@ import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { ToastMessage } from '~/components/common/Toast/toastMessage'
import { useSocket } from '~/hooks/useSockets'
import { postAskQuestion } from '~/network/fetchGraphData'
import { useAppStore } from '~/stores/useAppStore'
import { useDataStore } from '~/stores/useDataStore'
Expand Down Expand Up @@ -41,8 +42,9 @@ export const AskQuestion = () => {
const [question, setQuestion] = useState('')
const [selectedValue, setSelectedValue] = useState<string>('Beginner')
const searchTerm = useAppStore((s) => s.currentSearch)
const isSocketSet: { current: boolean } = useRef<boolean>(false)
const socket: Socket | null = null

const socket: Socket | undefined = useSocket()

const [setBudget] = useUserStore((s) => [s.setBudget])

const [askedQuestions, askedQuestionsAnswers, setAskedQuestion, setAskedQuestionAnswer, hasQuestionInProgress] =
Expand All @@ -67,16 +69,12 @@ export const AskQuestion = () => {
)

useEffect(() => {
if (isSocketSet.current) {
if (!socket) {
return
}

if (handleAskQuestion) {
if (socket) {
socket.on('askquestionhook', handleAskQuestion)

isSocketSet.current = true
}
socket.on('askquestionhook', handleAskQuestion)
}
}, [handleAskQuestion, socket])

Expand Down
17 changes: 6 additions & 11 deletions src/components/App/Helper/TeachMe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { updateBudget } from '~/utils/setBudget'
import { AskQuestion } from '../AskQuestion'

import 'reactflow/dist/style.css'
import { useSocket } from '~/hooks/useSockets'

type ResponseType = {
tutorial: string
Expand All @@ -30,7 +31,7 @@ export const TeachMe = () => {
const [setBudget] = useUserStore((s) => [s.setBudget])

const isSocketSet: { current: boolean } = useRef<boolean>(false)
const socket: Socket | null = null
const socket: Socket | undefined = useSocket()

const [setTeachMeAnswer, setHasTeachingInProgress, setInstagraphAnswer, setHasInstagraphInProgress] = useTeachStore(
(s) => [s.setTeachMeAnswer, s.setHasTeachingInProgress, s.setInstagraphAnswer, s.setHasInstagraphInProgress],
Expand Down Expand Up @@ -61,24 +62,18 @@ export const TeachMe = () => {
)

useEffect(() => {
if (isSocketSet.current) {
if (!socket) {
return
}

if (handleTeachMe) {
if (socket) {
socket.on('teachmehook', handleTeachMe)

isSocketSet.current = true
}
socket.on('teachmehook', handleTeachMe)
}

if (handleInstagraph) {
if (socket) {
socket.on('instagraphhook', handleInstagraph)
socket.on('instagraphhook', handleInstagraph)

isSocketSet.current = true
}
isSocketSet.current = true
}
}, [socket, handleTeachMe, handleInstagraph])

Expand Down
3 changes: 2 additions & 1 deletion src/components/App/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Suspense, lazy, useCallback, useEffect } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import 'react-toastify/dist/ReactToastify.css'
import { Socket } from 'socket.io-client'
import styled from 'styled-components'
import { DataRetriever } from '~/components/DataRetriever'
import { GlobalStyle } from '~/components/GlobalStyle'
Expand Down Expand Up @@ -75,7 +76,7 @@ export const App = () => {
useDataStore((s) => s.setCategoryFilter),
]

const socket = useSocket()
const socket: Socket | undefined = useSocket()

const form = useForm<{ search: string }>({ mode: 'onChange' })

Expand Down

0 comments on commit 76a9b10

Please sign in to comment.