Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query'
import 'bulma/css/bulma.min.css'
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'
import './animation.css'
import Home from './components/Home'
import LoginPage from './components/LoginPage'
import Nav from './components/Nav'
Expand All @@ -12,7 +13,6 @@ import { fetchFoodRatings, useUserData } from './contexts/UserDataContext'
import { images } from './data/images.json'
import { tasks } from './data/tasks.json'
import './main.css'
import './animation.css'
import { TaskInfo } from './types/Task'

function PrivateRoute({ children }: { children: JSX.Element }) {
Expand Down
20 changes: 20 additions & 0 deletions src/components/Error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState } from 'react'

export default function Error({ message }: { message: string }) {
const [isVisible, setIsVisible] = useState(true)

const handleClose = () => {
setIsVisible(false)
}

return (
<>
{isVisible && (
<div className="notification is-danger">
<button className="delete" onClick={handleClose} />
{message}
</div>
)}
</>
)
}
10 changes: 7 additions & 3 deletions src/components/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { supabase } from '../supabaseClient'
import Error from './Error'

export default function LoginPage() {
const [loading, setLoading] = useState(false)
const [email, setEmail] = useState('test@test')
const [password, setPassword] = useState('test')
const [error, setError] = useState<string | null>(null)
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const navigate = useNavigate()

const handleLogin = async (event: any) => {
event.preventDefault()

setError(null)
setLoading(true)
const { error } = await supabase.auth.signInWithPassword({
email,
password,
})

if (error) {
alert(error.message)
setError(`Error logging in: ${error.message}`)
} else {
navigate('/')
}
Expand Down Expand Up @@ -73,6 +76,7 @@ export default function LoginPage() {
</p>
</form>
</div>
{error && <Error message={error} />}
<h4
className="is-4 subtitle is-centered"
style={{ textAlign: 'center' }}
Expand Down
14 changes: 12 additions & 2 deletions src/components/RateFoodPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAuth } from '../contexts/AuthContext'
import { fetchFoodRatings, useUserData } from '../contexts/UserDataContext'
import { supabase } from '../supabaseClient'
import { FoodRatingData } from '../types/Task'
import Error from './Error'

export default function RateFoodPage() {
const queryClient = useQueryClient()
Expand All @@ -14,10 +15,15 @@ export default function RateFoodPage() {
const {
data: foodRatings,
isLoading,
isError,
isError: isFetchFoodRatingsError,
error: fetchFoodRatingsError,
isFetching,
} = useQuery({ queryKey: ['foodRatings'], queryFn: fetchFoodRatings })
const { mutate: recordRating } = useMutation({
const {
mutate: recordRating,
isError: isRecordRatingError,
error: recordRatingError,
} = useMutation({
mutationFn: async (foodRating: FoodRatingData) => {
return await supabase.from('food_ratings').insert(foodRating)
},
Expand Down Expand Up @@ -102,6 +108,10 @@ export default function RateFoodPage() {
</div>
)}
</div>
{isFetchFoodRatingsError && (
<Error message="Error fetching food ratings" />
)}
{isRecordRatingError && <Error message="Error recording rating" />}
</>
)}
</div>
Expand Down