Skip to content

Commit 5197d03

Browse files
updated gelocation function after login
1 parent 3199016 commit 5197d03

File tree

14 files changed

+200
-115
lines changed

14 files changed

+200
-115
lines changed

src/App.jsx

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ function App() {
4040
}, []);
4141

4242
async function checkUser() {
43-
console.log(token);
4443
if (!token || token.length <= 0) {
45-
console.log("new user");
44+
// console.log("new user");
4645
return;
4746
}
4847

@@ -74,66 +73,6 @@ function App() {
7473
}
7574
}
7675

77-
// let options = {
78-
// enableHighAccuracy: true,
79-
// timeout: 5000,
80-
// maximumAge: 0,
81-
// };
82-
83-
// getLocation();
84-
85-
// async function success(pos) {
86-
// let crd = pos.coords;
87-
88-
// console.log("Your current position is:");
89-
// console.log(`Latitude : ${crd.latitude}`);
90-
// console.log(`Longitude: ${crd.longitude}`);
91-
// console.log(`More or less ${crd.accuracy} meters.`);
92-
// try {
93-
// let response = await axios.post(
94-
// "/auth/addlocation",
95-
// {
96-
// latitude: crd.latitude,
97-
// longitude: crd.longitude,
98-
// },
99-
// {
100-
// headers: {
101-
// "Content-Type": "application/json",
102-
// },
103-
// }
104-
// );
105-
// console.log(response);
106-
// } catch (error) {
107-
// console.log(error);
108-
// }
109-
// }
110-
111-
// function errors(err) {
112-
// console.warn(`ERROR(${err.code}): ${err.message}`);
113-
// }
114-
115-
// function getLocation() {
116-
// if (navigator.geolocation) {
117-
// navigator.permissions
118-
// .query({ name: "geolocation" })
119-
// .then(function (result) {
120-
// if (result.state === "granted") {
121-
// console.log(result.state);
122-
// navigator.geolocation.getCurrentPosition(success);
123-
// } else if (result.state === "prompt") {
124-
// navigator.geolocation.getCurrentPosition(success, errors, options);
125-
// } else if (result.state === "denied") {
126-
// console.log("denied", result);
127-
// }
128-
// result.onchange = function () {
129-
// console.log(result.state);
130-
// };
131-
// });
132-
// } else {
133-
// console.log("Geolocation is not available on this device.");
134-
// }
135-
// }
136-
13776
return (
13877
<>
13978
{!isOnline && <NoInternet isOnline={isOnline} />}

src/components/home/ClothSection.jsx

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,43 @@ import { Box, Grid } from "@chakra-ui/react";
22
import { ClothGridBox } from "./GridBox";
33
import { HomeDescText, HomeText } from "./HomeText";
44

5+
export const ClothSection = ({
6+
heading,
7+
description,
8+
img,
9+
gender,
10+
handleSection,
11+
}) => {
12+
return (
13+
<Box
14+
m={"60px auto 60px"}
15+
w={["94%", "94%", "94%", "94%", "80%"]}
16+
textAlign={"center"}
17+
fontWeight={"bolder"}
18+
19+
>
20+
21+
<HomeText>{heading}</HomeText>
22+
<HomeDescText>{description}</HomeDescText>
523

6-
export const ClothSection = ({ heading, description, img, gender, handleSection }) => {
7-
return (
8-
<Box
9-
m={'60px auto 60px'}
10-
w={['94%', '94%', '94%', '94%', '80%']}
11-
textAlign={'center'}
12-
>
13-
<HomeText>{heading}</HomeText>
14-
<HomeDescText>{description}</HomeDescText>
15-
16-
<Grid
17-
onClick={() => {handleSection()}}
18-
gap={['10px', '10px', '10px', '10px', '20px']}
19-
templateColumns={["repeat(2, 1fr)", "repeat(2, 1fr)", "repeat(4, 1fr)", "repeat(4, 1fr)", "repeat(4, 1fr)"]}
20-
>
21-
<ClothGridBox source={img[0]} />
22-
<ClothGridBox source={img[1]} />
23-
<ClothGridBox source={img[2]} />
24-
<ClothGridBox source={img[3]} />
25-
</Grid>
26-
</Box>
27-
);
28-
};
24+
<Grid
25+
onClick={() => {
26+
handleSection();
27+
}}
28+
gap={["10px", "10px", "10px", "10px", "20px"]}
29+
templateColumns={[
30+
"repeat(2, 1fr)",
31+
"repeat(2, 1fr)",
32+
"repeat(4, 1fr)",
33+
"repeat(4, 1fr)",
34+
"repeat(4, 1fr)",
35+
]}
36+
>
37+
<ClothGridBox source={img[0]} />
38+
<ClothGridBox source={img[1]} />
39+
<ClothGridBox source={img[2]} />
40+
<ClothGridBox source={img[3]} />
41+
</Grid>
42+
</Box>
43+
);
44+
};

src/main.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import axios from "axios";
1212

1313
axios.defaults.baseURL = "https://nike-clone-tcmw.onrender.com";
1414

15-
// axios.defaults.baseURL = "http://localhost:8000";
15+
// axios.defaults.baseURL = "http://localhost:3000";
1616

1717
ReactDOM.createRoot(document.getElementById("root")).render(
1818
// <React.StrictMode>

src/pages/Cart.jsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,41 @@ import { OrderSummary } from "../components/cart/OrderSummary";
44
import { useDispatch, useSelector } from "react-redux";
55
import { useEffect } from "react";
66
import { getCartProducts } from "../redux/Reducers/cartReducer";
7+
import { setToast } from "../utils/extraFunctions";
8+
import { logoutApi } from "../redux/Reducers/authReducer";
9+
import { removeItem } from "../utils/cookiestorage";
10+
import { useNavigate } from "react-router-dom";
11+
import { removeItemLocal } from "../utils/localstorage";
712

813
function Cart() {
914
const token = useSelector((state) => state.auth.token);
1015

16+
const navigate = useNavigate();
1117
const dispatch = useDispatch();
1218
const toast = useToast();
1319

1420
useEffect(() => {
15-
let payload = [token, toast];
16-
dispatch(getCartProducts(payload));
21+
getCartDetails();
1722
}, []);
1823

24+
async function getCartDetails() {
25+
try {
26+
let payload = [token, toast];
27+
let response = await dispatch(getCartProducts(payload)).unwrap();
28+
} catch (rejectedValueOrSerializedError) {
29+
console.log(
30+
"rejectedValueOrSerializedError",
31+
rejectedValueOrSerializedError
32+
);
33+
if (rejectedValueOrSerializedError.response.data.status === "Failed") {
34+
removeItem("token");
35+
removeItem("user");
36+
dispatch(logoutApi());
37+
setToast(toast, "Session expired. Please login again.", "success");
38+
navigate("/login");
39+
}
40+
}
41+
}
1942
return (
2043
<>
2144
<Box

src/pages/Home.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ function Home() {
6767
p={"6px 20px"}
6868
borderRadius={30}
6969
alignItems={"center"}
70-
fontWeight={0}
7170
_hover={{
7271
bgColor: "black",
7372
}}
73+
fontWeight={"bolder"}
7474
onClick={() => navigate("/sale")}
7575
>
7676
SHOP NOW
@@ -82,7 +82,7 @@ function Home() {
8282
p={"6px 20px"}
8383
borderRadius={30}
8484
alignItems={"center"}
85-
fontWeight={0}
85+
fontWeight={"bolder"}
8686
_hover={{
8787
bgColor: "black",
8888
}}
@@ -97,8 +97,8 @@ function Home() {
9797
width={"89%"}
9898
fontSize={"24px"}
9999
textAlign={"left"}
100-
fontWeight={"500"}
101100
marginBottom={2}
101+
fontWeight={"bolder"}
102102
>
103103
Featuerd
104104
</Text>
@@ -122,6 +122,8 @@ function Home() {
122122
flexDirection={"column"}
123123
alignItems={"center"}
124124
justifyContent={"center"}
125+
cursor={"pointer"}
126+
onClick={() => navigate("/sale")}
125127
>
126128
<Box
127129
color={"white"}
@@ -161,6 +163,7 @@ function Home() {
161163
borderRadius={20}
162164
color={"black"}
163165
alignItems={"center"}
166+
onClick={() => navigate("/sale")}
164167
>
165168
Explore
166169
</Button>
@@ -171,6 +174,7 @@ function Home() {
171174
borderRadius={20}
172175
color={"black"}
173176
alignItems={"center"}
177+
onClick={() => navigate("/men")}
174178
>
175179
Top 10 Gifts
176180
</Button>
@@ -188,6 +192,8 @@ function Home() {
188192
flexDirection={"column"}
189193
alignItems={"center"}
190194
justifyContent={"center"}
195+
cursor={"pointer"}
196+
onClick={() => navigate("/sale")}
191197
>
192198
<Box
193199
color={"white"}
@@ -205,6 +211,7 @@ function Home() {
205211
transition: "color 0.5s ease-out",
206212
}}
207213
fontWeight="bold"
214+
onClick={() => navigate("/sale")}
208215
>
209216
Early Access
210217
</Text>
@@ -215,6 +222,7 @@ function Home() {
215222
}}
216223
fontWeight="bold"
217224
fontSize={"24px"}
225+
onClick={() => navigate("/men")}
218226
>
219227
Top Selling
220228
</Text>
@@ -226,6 +234,7 @@ function Home() {
226234
borderRadius={20}
227235
color={"black"}
228236
alignItems={"center"}
237+
onClick={() => navigate("/sale")}
229238
>
230239
Get It First
231240
</Button>
@@ -236,7 +245,7 @@ function Home() {
236245
<Box>
237246
{clothData?.map((data, index) =>
238247
loading ? (
239-
<HomeProductLoader />
248+
<HomeProductLoader key={index} />
240249
) : error ? (
241250
<Error />
242251
) : (

0 commit comments

Comments
 (0)