Skip to content

Commit

Permalink
Merge branch 'develop' into SMA-91-Rest-api-should-return-400-when-da…
Browse files Browse the repository at this point in the history
…ta-is-invalid
  • Loading branch information
MatejFrnka authored Apr 23, 2024
2 parents 70a7024 + 4a1f9d1 commit 7ef960e
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 74 deletions.
22 changes: 22 additions & 0 deletions backend/sportsmatch/src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
spring.datasource.url=jdbc:postgresql://quirky-bugbear-7185.7tc.aws-eu-central-1.cockroachlabs.cloud:26257/sportsmingle?sslmode=verify-full
spring.datasource.username=matt
spring.datasource.password={ask for it}
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.generate_statistics=true
spring.h2.console.enabled=true
spring.mvc.hiddenmethod.filter.enabled=true

spring.jpa.defer-datasource-initialization=true
spring.sql.init.mode=always

app.sportsmingle.initialization.database-init=true
app.sportsmingle.jwt.secret={ask for it}
app.sportsmingle.frontend.url=sportsmingle.app

app.sportsmingle.num-game-threshold=5,15,25
app.sportsmingle.k-factors=25.0,15.0,10.0
app.sportsmingle.k-factor-default=5.0
1 change: 1 addition & 0 deletions frontend/sportsmatch-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BACKEND_URL=http://localhost:8080
1 change: 1 addition & 0 deletions frontend/sportsmatch-app/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_BACKEND_URL=
1 change: 1 addition & 0 deletions frontend/sportsmatch-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import HostEvent from './pages/HostEvent'
import { useEffect } from 'react'

function App() {
OpenAPI.BASE = import.meta.env.VITE_BACKEND_URL
OpenAPI.TOKEN = localStorage.getItem('token')!

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions frontend/sportsmatch-app/src/components/AllSportsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function AllSportsList(p: AllSportsProps) {
onChange={(query: string) => {
setSearchQuery(query)
}}
placeholder="Find your sport"
/>
{sportList}
<div className="row">
Expand Down
17 changes: 2 additions & 15 deletions frontend/sportsmatch-app/src/components/HostEventComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
HostEventDTO,
EventDTO,
ApiError,
OpenAPI,
ExSecuredEndpointService,
} from '../generated/api'
import DatePicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
Expand Down Expand Up @@ -44,8 +42,6 @@ function HostEventComponent() {
const [nearbyEvents, setNearbyEvents] = useState<EventDTO[]>([])
const [selectedEvent, setSelectedEvent] = useState<EventDTO>()
const { isOpen, toggle } = useModal()
const [usersRank, setUsersRank] = useState(0)
const [userIsInRank, setUserIsInRank] = useState(false)
const [searchQuery, setSearchQuery] = useState<string>('') // no implementation yet

console.log(searchQuery)
Expand Down Expand Up @@ -136,16 +132,10 @@ function HostEventComponent() {

// handle join event pop up after cliking on the event
const handleEventSelection = (e: EventDTO) => {
window.scrollTo(0, 0)
if (isOpen) {
toggle()
}
setSelectedEvent(e)
if (usersRank >= e.minElo && usersRank <= e.maxElo) {
setUserIsInRank(true)
} else {
setUserIsInRank(false)
}
toggle()
}

Expand Down Expand Up @@ -290,15 +280,12 @@ function HostEventComponent() {
onChange={(query: string) => {
setSearchQuery(query)
}}
placeholder="search"
/>
</div>
</div>
<Modal isOpen={isOpen} toggle={toggle} preventClosing={true}>
<JoinEventComponent
toggle={toggle}
isInRank={userIsInRank}
event={selectedEvent!}
/>
<JoinEventComponent toggle={toggle} event={selectedEvent!} />
</Modal>
<div className="row">
<div className="col">
Expand Down
62 changes: 59 additions & 3 deletions frontend/sportsmatch-app/src/components/JoinEventComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useEffect, useState } from 'react'
import {
OpenAPI,
EventsControllerService,
ApiError,
EventDTO,
ExSecuredEndpointService,
UserDTO,
} from '../generated/api'
import '../styles/JoinEvent.css'
import { Link } from 'react-router-dom'

interface JoinEventProps {
isInRank: boolean // a boolean to check if user's rank meets the event's requirement
event: EventDTO
toggle: () => void
}
Expand All @@ -24,6 +27,39 @@ export default function JoinEventComponent(p: JoinEventProps) {
}
}

const [userIsInRank, setUserIsInRank] = useState(false)
const [currentUser, setCurrentUser] = useState<UserDTO>({})

// retrieving users rank
useEffect(() => {
if (localStorage.getItem('token')) {
const fetchUsersRank = async () => {
OpenAPI.TOKEN = localStorage.getItem('token')!
try {
const response = await ExSecuredEndpointService.getUserMainPage()
if (response) {
setCurrentUser(response as UserDTO)
}
} catch (error) {
console.error(error as ApiError)
}
}
fetchUsersRank()
}
}, [])

// checking user's rank
useEffect(() => {
if (
currentUser.elo! >= p.event.minElo &&
currentUser.elo! <= p.event.maxElo
) {
setUserIsInRank(true)
} else {
setUserIsInRank(false)
}
}, [currentUser, p.event.minElo, p.event.maxElo])

const getDateAndTime = (type: string) => {
const dateStart: string[] = p.event.dateStart.split(' ')
if (type === 'date') {
Expand All @@ -37,7 +73,7 @@ export default function JoinEventComponent(p: JoinEventProps) {

return (
<>
{p.isInRank ? (
{userIsInRank ? (
<div className="container-sm join-event-wrapper">
<div className="row">
<div className="col-12">
Expand Down Expand Up @@ -80,7 +116,7 @@ export default function JoinEventComponent(p: JoinEventProps) {
</div>
</div>
</div>
) : (
) : currentUser.name ? (
<div className="container-sm join-event-wrapper">
<div className="row">
<div className="col-12">
Expand All @@ -103,6 +139,26 @@ export default function JoinEventComponent(p: JoinEventProps) {
</div>
</div>
</div>
) : (
<div className="container-sm join-event-wrapper">
<div className="row">
<div className="col-12">
<h1 className="joint-event-title">Hang On a Sec!</h1>
</div>
<div className="row">
<div className="col-12">
<Link to="/login">Please login to join</Link>
</div>
</div>
</div>
<div className="row">
<div className="col-12">
<button className="join-event-btn-grey" onClick={p.toggle}>
Cancel
</button>
</div>
</div>
</div>
)}
</>
)
Expand Down
3 changes: 2 additions & 1 deletion frontend/sportsmatch-app/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../styles/Sport.css'

interface Params {
onChange: (query: string) => void
placeholder: string
}

export function SearchBar(p: Params) {
Expand All @@ -16,7 +17,7 @@ export function SearchBar(p: Params) {
<TbSearch className="search-icon" />
<input
type="text"
placeholder="Find your sports"
placeholder={p.placeholder}
className="input-search"
onChange={handleSearch}
/>
Expand Down
82 changes: 27 additions & 55 deletions frontend/sportsmatch-app/src/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,36 @@ import SportEvent from '../components/SportEvent'
import LoadingSpinner from '../components/LoadingSpinner'
import { SearchBar } from '../components/SearchBar'
import { useEffect, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { useNavigate } from 'react-router-dom'
import '../styles/Index.css'
import {
ApiError,
EventDTO,
EventsControllerService,
ExSecuredEndpointService,
OpenAPI,
} from '../generated/api'
import { ApiError, EventDTO, EventsControllerService } from '../generated/api'
import useModal from '../hooks/UseModal'
import Modal from '../components/Modal'
import JoinEventComponent from '../components/JoinEventComponent'

export default function MainPage() {
const [searchQuery, setSearchQuery] = useState<string>('') // no implementation yet
const [searchQuery, setSearchQuery] = useState<string>('')
const [filteredEvent, setFilteredEvent] = useState<EventDTO[]>([])
const [selectedSports, setSelectedSports] = useState<string[]>([])
const [clearFilters, setClearFilters] = useState<boolean>(false)
const [selectedEvent, setSelectedEvent] = useState<EventDTO>()
const [usersRank, setUsersRank] = useState(0)
const [userIsInRank, setUserIsInRank] = useState(false)
const location = useLocation()
const navigate = useNavigate()
const { isOpen, toggle } = useModal()
const [page, setPage] = useState<number>(0)
const size = 5

// search bar is not yet implemented
useEffect(() => {
console.log(`query`, searchQuery)
}, [searchQuery])
const size = 3

// handle sports name selected from sportButtoncomponent
const handleSportSelectionChange = (selectedButtonSports: string[]) => {
setSelectedSports(selectedButtonSports)
}

// setting the page to 0 when selected sports change to clear the filteredEvent
useEffect(() => {
setPage(0)
}, [selectedSports])

const clear = () => {
navigate(location.pathname, { state: undefined })
setPage(0)
setSelectedSports([])
setClearFilters(true)
setTimeout(() => {
Expand Down Expand Up @@ -83,35 +74,13 @@ export default function MainPage() {

// handle join event pop up after cliking on the event
const handleEventSelection = (e: EventDTO) => {
window.scrollTo(0, 0)
if (isOpen) {
toggle()
}
setSelectedEvent(e)
if (usersRank >= e.minElo && usersRank <= e.maxElo) {
setUserIsInRank(true)
} else {
setUserIsInRank(false)
}
toggle()
}

// retrieving users rank
useEffect(() => {
const fetchUsersRank = async () => {
OpenAPI.TOKEN = localStorage.getItem('token')!
try {
const response = await ExSecuredEndpointService.getUserMainPage()
if (response) {
setUsersRank(response.elo)
}
} catch (error) {
console.error(error as ApiError)
}
}
fetchUsersRank()
})

const handleLetsPlay = () => {
navigate('/app')
}
Expand Down Expand Up @@ -158,31 +127,34 @@ export default function MainPage() {
onChange={(query: string) => {
setSearchQuery(query)
}}
placeholder="Find your place"
/>
</div>
</div>
<Modal isOpen={isOpen} toggle={toggle} preventClosing={true}>
<JoinEventComponent
toggle={toggle}
isInRank={userIsInRank}
event={selectedEvent!}
/>
<JoinEventComponent toggle={toggle} event={selectedEvent!} />
</Modal>
<div className="row">
<div className="col">
<div className="nearby-events-container">
{filteredEvent.length === 0 ? (
<LoadingSpinner />
) : (
filteredEvent.map((event, index) => (
<div
className="nearby-events"
key={index}
onClick={() => handleEventSelection(event)}
>
<SportEvent event={event} />
</div>
))
filteredEvent
.filter((e) =>
e.placeDTO.name
.toLowerCase()
.includes(searchQuery.toLowerCase()),
)
.map((event, index) => (
<div
className="nearby-events"
key={index}
onClick={() => handleEventSelection(event)}
>
<SportEvent event={event} />
</div>
))
)}
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions frontend/sportsmatch-app/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_BACKEND_URL: string
}

interface ImportMeta {
readonly env: ImportMetaEnv
}

0 comments on commit 7ef960e

Please sign in to comment.