Skip to content

Commit

Permalink
frontend without styling
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-pohl committed Jun 3, 2024
1 parent 23f1a05 commit 8e44e11
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 8 deletions.
43 changes: 41 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-router-dom": "^6.23.1",
"styled-components": "^6.1.11"
},
"devDependencies": {
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Routes, Route } from "react-router-dom";
import RestaurantsPage from "./pages/RestaurantsPage.tsx";

import RestaurantDetails from "./components/RestaurantDetails/RestaurantDetails.tsx";
function App() {

return (
<>
<RestaurantsPage />
</>

<Routes>
<Route path="/" element={<RestaurantsPage />} />
<Route path="/restaurants/:id" element={<RestaurantDetails />} />
{/* Weitere Routen hier hinzufügen, falls nötig */}
</Routes>


/*<>
<RestaurantsPage />
</>*/
)
}

Expand Down
18 changes: 18 additions & 0 deletions frontend/src/components/RestaurantCard/RestaurantCard.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ export const StyledDetailsContainer = styled.div`

export const StyledDetailsTitle = styled.h2`
margin-bottom: 5px;
`;

export const StyledDetailsButton = styled.button`
background-color: #6200ea;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
&:hover {
background-color: #3700b3;
}
&:active {
background-color: #03dac5;
}
`;
13 changes: 12 additions & 1 deletion frontend/src/components/RestaurantCard/RestaurantCard.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import {RestaurantType} from "../../model/Restaurant.ts";
import { useNavigate } from "react-router-dom";
import {FaLocationDot} from "react-icons/fa6";
import RestaurantCardDetail from "../RestaurantCardDetail/RestaurantCardDetail.tsx";
import {
StyledArticle,
StyledDetailsContainer,
StyledDetailsTitle,
StyledFallbackImage,
StyledImageContainer
StyledImageContainer,
StyledDetailsButton
} from "./RestaurantCard.styled.ts";

type RestaurantCardProps = {
restaurant: RestaurantType,
}

export default function RestaurantCard({restaurant}: RestaurantCardProps) {
const navigate = useNavigate();

const handleDetailsClick = () => {
navigate(`/restaurants/${restaurant.id}`);
};



return (
<StyledArticle>
<StyledImageContainer>
Expand All @@ -23,6 +33,7 @@ export default function RestaurantCard({restaurant}: RestaurantCardProps) {
<StyledDetailsContainer>
<StyledDetailsTitle>{restaurant.title}</StyledDetailsTitle>
<RestaurantCardDetail icon={<FaLocationDot/>} value={restaurant.city}/>
<StyledDetailsButton onClick={handleDetailsClick}>Details</StyledDetailsButton>
</StyledDetailsContainer>
</StyledArticle>
)
Expand Down
50 changes: 50 additions & 0 deletions frontend/src/components/RestaurantDetails/RestaurantDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useEffect, useState } from "react";
import {useNavigate, useParams} from "react-router-dom";
import axios from "axios";
import { RestaurantType } from "../../model/Restaurant.ts";
import {StyledDetailsButton} from "../RestaurantCard/RestaurantCard.styled.ts";

export default function RestaurantDetails() {
const { id } = useParams<{ id: string }>();
const [restaurant, setRestaurant] = useState<RestaurantType>();
const [error, setError] = useState<string | null>(null);
const navigate = useNavigate();

useEffect(() => {
axios.get(`/api/restaurants/${id}`)
.then(response => {
setRestaurant(response.data);
})
.catch(error => {
setError("There was an error fetching the restaurant details!");
console.error(error);
});
}, [id]);

if (error) {
return <div>{error}</div>;
}

if (!restaurant) {
return <div>Loading...</div>;
}

const handleDetailsClick = () => {
navigate(`/`);
};

return (
<div>
<h1>{restaurant.title}</h1>
<p>{restaurant.city}</p>

<h1>sdofihsdijfpsdjf</h1>
<br/>
<h1>uosijdfoisdfoihsodihfosihdf</h1>
<br/>
<h1>hier Button um zurückzukommen auf mainpage</h1>
<StyledDetailsButton onClick={handleDetailsClick}>BACK</StyledDetailsButton>

</div>
);
}
5 changes: 4 additions & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import { BrowserRouter } from "react-router-dom";

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
)

0 comments on commit 8e44e11

Please sign in to comment.