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

Ai seed Questions under AI search bar Rendered after the AI chat search panel open #1865

Merged
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
8 changes: 6 additions & 2 deletions src/components/App/Splash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ export const Splash = memo(({ children }: PropsWithChildren) => {
const [progress, setProgress] = useState(0)
const [isLoading, setIsLoading] = useState(true)
const { appMetaData, setAppMetaData } = useAppStore((s) => s)
const { stats, setStats, isFetching } = useDataStore((s) => s)
const { stats, setStats, isFetching, setSeedQuestions } = useDataStore((s) => s)

const fetchData = useCallback(async () => {
try {
if (!appMetaData) {
const aboutResponse = await getAboutData()

setAppMetaData(aboutResponse)

if (aboutResponse.seed_questions) {
setSeedQuestions(aboutResponse.seed_questions)
}
}

if (!stats) {
Expand All @@ -43,7 +47,7 @@ export const Splash = memo(({ children }: PropsWithChildren) => {

setProgress(100)
}
}, [appMetaData, setAppMetaData, setStats, stats])
}, [appMetaData, setAppMetaData, setStats, stats, setSeedQuestions])

useEffect(() => {
fetchData()
Expand Down
26 changes: 3 additions & 23 deletions src/components/App/UniverseQuestion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Flex } from '~/components/common/Flex'

import { TextareaAutosize } from '@mui/base'
import { Button } from '@mui/material'
import { useEffect, useState } from 'react'
import { useState } from 'react'
import ArrowForwardIcon from '~/components/Icons/ArrowForwardIcon'
import ExploreIcon from '~/components/Icons/ExploreIcon'
import HelpIcon from '~/components/Icons/HelpIcon'
import { getAboutData } from '~/network/fetchSourcesData'
import { useAiSummaryStore } from '~/stores/useAiSummaryStore'
import { useAppStore } from '~/stores/useAppStore'
import { useDataStore } from '~/stores/useDataStore'
Expand All @@ -16,30 +15,11 @@ import { colors } from '~/utils/colors'

export const UniverseQuestion = () => {
const [question, setQuestion] = useState('')
const [seedQuestions, setSeedQuestions] = useState<string[]>([])
const { fetchData, setAbortRequests } = useDataStore((s) => s)
const { fetchData, setAbortRequests, seedQuestions } = useDataStore((s) => s)
const [setBudget] = useUserStore((s) => [s.setBudget])
const setUniverseQuestionIsOpen = useAppStore((s) => s.setUniverseQuestionIsOpen)
const resetAiSummaryAnswer = useAiSummaryStore((s) => s.resetAiSummaryAnswer)

useEffect(() => {
const fetchSeedQuestions = async () => {
try {
const response = await getAboutData()

if (response.seed_questions) {
const shuffledQuestions = shuffleArray(response.seed_questions)

setSeedQuestions(shuffledQuestions)
}
} catch (error) {
console.error('Error fetching seed questions:', error)
}
}

fetchSeedQuestions()
}, [])

const handleSubmitQuestion = async (questionToSubmit: string) => {
if (questionToSubmit) {
resetAiSummaryAnswer()
Expand Down Expand Up @@ -77,7 +57,7 @@ export const UniverseQuestion = () => {
return array
}

const displayedSeedQuestions = seedQuestions.slice(0, 4)
const displayedSeedQuestions = seedQuestions ? shuffleArray(seedQuestions).slice(0, 4) : []

const isValidText = !!question && question.trim().length > 0

Expand Down
5 changes: 5 additions & 0 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
trendingTopics: Trending[]
stats: TStats | null
nodeTypes: string[]
seedQuestions: string[] | null

setTrendingTopics: (trendingTopics: Trending[]) => void
setDataNew: (data: GraphData) => void
Expand All @@ -72,6 +73,7 @@
setAbortRequests: (abortRequest: boolean) => void
nextPage: () => void
setFilters: (filters: Partial<FilterParams>) => void
setSeedQuestions: (questions: string[]) => void
}

const defaultData: Omit<
Expand All @@ -98,6 +100,7 @@
| 'nextPage'
| 'setDataNew'
| 'resetDataNew'
| 'setSeedQuestions'
> = {
categoryFilter: null,
dataInitial: null,
Expand Down Expand Up @@ -127,6 +130,7 @@
splashDataLoading: true,
abortRequest: false,
dataNew: null,
seedQuestions: null,
}

let abortController: AbortController | null = null
Expand Down Expand Up @@ -223,7 +227,7 @@
sidebarFilterCounts,
})
} catch (error) {
console.log(error)

Check warning on line 230 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run

Unexpected console statement

Check warning on line 230 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement
set({ isFetching: false })
set({ isLoadingNew: false })
}
Expand Down Expand Up @@ -258,8 +262,9 @@
setSources: (sources) => set({ sources }),
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setTeachMe: (showTeachMe) => set({ showTeachMe }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),
updateNode: (updatedNode) => {
console.log(updatedNode)

Check warning on line 267 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run

Unexpected console statement

Check warning on line 267 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement
},
addNewNode: (data) => {
const { dataInitial: existingData } = get()
Expand Down Expand Up @@ -303,7 +308,7 @@
})
},
removeNode: (id) => {
console.log(id)

Check warning on line 311 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run

Unexpected console statement

Check warning on line 311 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement
},
setAbortRequests: (abortRequest) => set({ abortRequest }),
})),
Expand Down
Loading