Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: loading skeloteon for My Reseravtion page #19

Merged
merged 4 commits into from
Nov 13, 2023
Merged
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
16 changes: 8 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const App = () => (
<LoginStyle>
<Login />
</LoginStyle>
)}
)}
/>
<Route
path="/register"
element={(
<LoginStyle>
<Register />
</LoginStyle>
)}
)}
/>
<Route element={<RequireAuth />}>
<Route
Expand All @@ -47,23 +47,23 @@ const App = () => (
<CenterContainer>
<Aeroplanes />
</CenterContainer>
)}
)}
/>
<Route
path="/details"
element={(
<CenterContainer>
<AeroPlaneDetails />
</CenterContainer>
)}
)}
/>
<Route
path="/reservations"
element={(
<CenterContainer>
<Reservations />
</CenterContainer>
)}
)}
/>

<Route
Expand All @@ -72,7 +72,7 @@ const App = () => (
<CenterContainer>
<Reserve />
</CenterContainer>
)}
)}
/>

<Route
Expand All @@ -81,15 +81,15 @@ const App = () => (
<CenterContainer>
<AddAeroplane />
</CenterContainer>
)}
)}
/>
<Route
path="/delete_aeroplane"
element={(
<CenterContainer>
<DeleteAeroplane />
</CenterContainer>
)}
)}
/>
</Route>
</Routes>
Expand Down
1 change: 0 additions & 1 deletion src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {
} from 'react';
import { Link, useNavigate, useLocation } from 'react-router-dom';
import axios from '../api/axios';

import AuthContext from '../context/AuthProvider';

const LOGIN_URL = '/login';
Expand Down
4 changes: 4 additions & 0 deletions src/components/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState, useEffect } from 'react';
import { NavLink, useNavigate } from 'react-router-dom';
import toast from 'react-hot-toast';
import { useNavigation } from './NavigationContext';
import logo from '../assets/app-logo.png';
import NavFooter from './NavFooter';
import useAuth from '../hooks/useAuth';
import axios from '../api/axios';

import NavBarMobile from './NavBarMobile';

const Navigation = () => {
Expand All @@ -26,7 +28,9 @@ const Navigation = () => {
'Content-Type': 'application/json',
},
});
toast.success('Logout Successfully');
} catch (err) {
toast.error('Opps😥 failed To logout');
throw Error(err);
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/components/Reservations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,38 @@ import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchReservedAeroplanes } from '../redux/aeroplanes/aeroplanesActions';
import ReservationCard from './ReservationCard';
import ReserveCardLoading from './ReserveCardLoading';

const Reservations = () => {
const dispatch = useDispatch();
const userAeroplanes = useSelector((state) => state.reservations.reservation);
const loading = useSelector((state) => state.aeroplanes.reservedAeroplanesLoading);
const error = useSelector((state) => state.aeroplanes.reservedAeroplanesError);
const loading = useSelector((state) => state.reservations.loading);
const error = useSelector(
(state) => state.aeroplanes.reservedAeroplanesError,
);
useEffect(() => {
dispatch(fetchReservedAeroplanes());
}, [dispatch]);

if (loading) {
return <p>Loading</p>;
return <ReserveCardLoading />;
}

if (error) {
return (

<div className="d-flex justify-content-center align-items-center">

<p>Something went wrong</p>
</div>
);
}

const aeroplaneCards = userAeroplanes.map((aeroplane, index) => (
<div className="col-lg-6 col-12 mb-4" key={aeroplane.id}>
<ReservationCard aeroplane={aeroplane} index={index} style={{ marginRight: '40px' }} />
<ReservationCard
aeroplane={aeroplane}
index={index}
style={{ marginRight: '40px' }}
/>
</div>
));

Expand All @@ -38,9 +43,7 @@ const Reservations = () => {
<h3 className="fw-normal"> Reservations</h3>
</div>
{userAeroplanes && userAeroplanes.length > 0 ? (
<div className="row">
{ aeroplaneCards }
</div>
<div className="row">{aeroplaneCards}</div>
) : (
<div className="d-flex justify-content-center align-items-center">
<p>No reserved aeroplanes found.</p>
Expand Down
21 changes: 21 additions & 0 deletions src/components/ReserveCardLoading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import ReservationCardLoading from '../ui/reservationCardLoading';

const ReserveCardLoading = () => (
<div className="row container">
<div className="col-lg-6 col-12 mb-4">
<ReservationCardLoading />
</div>
<div className="col-lg-6 col-12 mb-4">
<ReservationCardLoading />
</div>
<div className="col-lg-6 col-12 mb-4">
<ReservationCardLoading />
</div>
<div className="col-lg-6 col-12 mb-4">
<ReservationCardLoading />
</div>
</div>
);

export default ReserveCardLoading;
9 changes: 9 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ html {
}

section {
margin-top: 70px;
width: 100%;
max-width: 420px;
min-height: 400px;
Expand Down Expand Up @@ -284,6 +285,14 @@ button {
border-radius: 0.125rem;
}

.skeleton-card {
width: 320px;
height: 2rem;
margin-top: 0.25rem;
margin-bottom: 0.2rem;
border-radius: 0.125rem;
}

@keyframes skeleton-loading {
0% {
background-color: hsl(200, 13%, 42%);
Expand Down
4 changes: 3 additions & 1 deletion src/redux/reservations/reservationSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ const reservationSlice = createSlice({
.addCase(fetchReservedAeroplanes.pending, (state) => {
state.loading = true;
})

.addCase(fetchReservedAeroplanes.fulfilled, (state, action) => {
state.loading = false;
state.reservation = action.payload;
})
.addCase(fetchReservedAeroplanes.rejected, (state) => {
state.loading = false;
});
},
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/reservationCardLoading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

const ReservationCardLoading = () => (
<li style={{ width: '17rem' }} className="list-group-item">
<p className=" skeleton skeleton-card" />
<p className=" skeleton skeleton-card" />
<p className=" skeleton skeleton-card" />
<p className=" skeleton skeleton-card" />
<p className=" skeleton skeleton-card" />
<p className=" skeleton skeleton-card" />
<p className=" skeleton skeleton-card" />
</li>
);

export default ReservationCardLoading;