Skip to content

Commit

Permalink
edit works, asyncon works
Browse files Browse the repository at this point in the history
  • Loading branch information
Ropold committed Nov 21, 2024
1 parent 94dc5e3 commit ed0593e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ export default function App() {


const handleSaveEdit = (id: string, editData: Restaurant) => {
if (!id) return;

axios
return axios
.put(`/api/restaurant/${id}`, editData)
.then((response) => {
setRestaurants(prevRestaurants =>
prevRestaurants.map(r => r.id === id ? response.data : r)
);
navigate(`/`);
})
.catch((error) => console.error("Error saving restaurant edits:", error));
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
import {useNavigate, useParams} from "react-router-dom";

type detailsEditProps = {
handleSaveEdit: (id:string, editData:Restaurant) => void;
handleSaveEdit: (id:string, editData:Restaurant) => Promise<any>;
}

export default function Details(props: Readonly<detailsEditProps>) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function Details(props: Readonly<detailsEditProps>) {
cols={40}
/>
</label>
<button type="button" onClick={()=>props.handleSaveEdit(restaurant.id, editData)}>Save</button>
<button type="button" onClick={()=>{props.handleSaveEdit(restaurant.id, editData).then(()=> fetchRestaurantDetails()); setEditingRestaurantId(null)}}>Save</button>
<button type="button" onClick={handleCancelEdit}>Cancel</button>
</form>
</div>
Expand Down

0 comments on commit ed0593e

Please sign in to comment.