Skip to content

Commit

Permalink
resolving error
Browse files Browse the repository at this point in the history
  • Loading branch information
meenalnimje committed Feb 3, 2024
1 parent 9593a08 commit f47f523
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const query = gql`
}
`

let uri = 'http://localhost:3000/api/graphql'
let uri = '/api/graphql'
console.log('graphql_uri', uri)
const client = new ApolloClient({
link: new HttpLink({ uri, fetch }),
Expand Down
6 changes: 5 additions & 1 deletion src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ import { query } from '../queries/queries'

export default function Home() {
const [universityData, setUniversityData] = useState(null)
const [loading, setLoading] = useState(false)
async function fetchData() {
try {
setLoading(true)
const result = await client.query({ query })
setUniversityData(result?.data?.universityList)
} catch (error) {
console.log('Error fetching data:', error)
} finally {
setLoading(false)
}
}
useEffect(() => {
Expand All @@ -34,7 +38,7 @@ export default function Home() {
<div className="text-9xl font-bold mt-28">
<Image src={bacpacTitle} alt="BACPAC" className="w-full h-full" />
</div>
<SearchBar data={universityData} />
<SearchBar data={universityData} loading={loading} />
<div className="login-part w-5/12 mt-24 flex flex-col items-center">
<div className="flex items-center mb-5 w-full justify-center">
<BsStars className="text-[#6744FF] text-4xl -ml-3 center" />
Expand Down
29 changes: 15 additions & 14 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
import fetch from 'cross-fetch'

// uri = 'https://web-app-client-flame.vercel.app/api/graphql'
let uri
switch (process.env.NEXT_PUBLIC_LOCAL_STATE) {
case 'development':
uri = 'http://localhost:3000/api/graphql'
break
case 'test':
uri = 'http://localhost:3000/api/graphql'
break
case 'production':
uri = 'https://web-app-client-lraro1uh2-bacpacs-projects.vercel.app'
break
default:
break
}
let uri = '/api/graphql'
// switch (process.env.NEXT_PUBLIC_LOCAL_STATE) {
// case 'development':
// uri = 'http://localhost:3000/api/graphql'
// break
// case 'test':
// uri = 'http://localhost:3000/api/graphql'
// break
// case 'production':
// // uri = 'https://web-app-client-git-bi-46-review-1-bacpacs-projects.vercel.app/api/graphql'
// uri = 'https://web-app-client-flame.vercel.app/api/graphql'
// break
// default:
// break
// }
console.log('graphql_uri', uri)
const client = new ApolloClient({
link: new HttpLink({ uri, fetch }),
Expand Down
5 changes: 3 additions & 2 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CollegeResult from '../app/components/CollegeResult'
import searchAlgorithm from '../utils/searchAlgorithm'
import { useState } from 'react'

const SearchBar = ({ data }) => {
const SearchBar = ({ data, loading }) => {
const [open, setOpen] = useState(false)
const [filterData, setFilterData] = useState([])
const handleSearch = (e) => {
Expand All @@ -13,7 +13,8 @@ const SearchBar = ({ data }) => {
setFilterData(filterData)
}
let searchResults = filterData?.map((item, index) => <CollegeResult info={item} serialNo={index} key={index} />)
if (searchResults.length === 0) searchResults = <div>No results found</div>
if (!loading && searchResults.length === 0) searchResults = <div>No results found</div>
if (loading) searchResults = <div>Loading....</div>
return (
<div className="search-box mt-4 w-5/12 h-12 rounded-2xl">
<div className="search-icon w-12 absolute h-12 flex justify-center items-center">
Expand Down

0 comments on commit f47f523

Please sign in to comment.