Skip to content

Commit

Permalink
updated gelocation function after login
Browse files Browse the repository at this point in the history
  • Loading branch information
VenketeshRushi committed Oct 29, 2023
1 parent 3199016 commit 5197d03
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 115 deletions.
63 changes: 1 addition & 62 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ function App() {
}, []);

async function checkUser() {
console.log(token);
if (!token || token.length <= 0) {
console.log("new user");
// console.log("new user");
return;
}

Expand Down Expand Up @@ -74,66 +73,6 @@ function App() {
}
}

// let options = {
// enableHighAccuracy: true,
// timeout: 5000,
// maximumAge: 0,
// };

// getLocation();

// async function success(pos) {
// let crd = pos.coords;

// console.log("Your current position is:");
// console.log(`Latitude : ${crd.latitude}`);
// console.log(`Longitude: ${crd.longitude}`);
// console.log(`More or less ${crd.accuracy} meters.`);
// try {
// let response = await axios.post(
// "/auth/addlocation",
// {
// latitude: crd.latitude,
// longitude: crd.longitude,
// },
// {
// headers: {
// "Content-Type": "application/json",
// },
// }
// );
// console.log(response);
// } catch (error) {
// console.log(error);
// }
// }

// function errors(err) {
// console.warn(`ERROR(${err.code}): ${err.message}`);
// }

// function getLocation() {
// if (navigator.geolocation) {
// navigator.permissions
// .query({ name: "geolocation" })
// .then(function (result) {
// if (result.state === "granted") {
// console.log(result.state);
// navigator.geolocation.getCurrentPosition(success);
// } else if (result.state === "prompt") {
// navigator.geolocation.getCurrentPosition(success, errors, options);
// } else if (result.state === "denied") {
// console.log("denied", result);
// }
// result.onchange = function () {
// console.log(result.state);
// };
// });
// } else {
// console.log("Geolocation is not available on this device.");
// }
// }

return (
<>
{!isOnline && <NoInternet isOnline={isOnline} />}
Expand Down
62 changes: 39 additions & 23 deletions src/components/home/ClothSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@ import { Box, Grid } from "@chakra-ui/react";
import { ClothGridBox } from "./GridBox";
import { HomeDescText, HomeText } from "./HomeText";

export const ClothSection = ({
heading,
description,
img,
gender,
handleSection,
}) => {
return (
<Box
m={"60px auto 60px"}
w={["94%", "94%", "94%", "94%", "80%"]}
textAlign={"center"}
fontWeight={"bolder"}

>

<HomeText>{heading}</HomeText>
<HomeDescText>{description}</HomeDescText>

export const ClothSection = ({ heading, description, img, gender, handleSection }) => {
return (
<Box
m={'60px auto 60px'}
w={['94%', '94%', '94%', '94%', '80%']}
textAlign={'center'}
>
<HomeText>{heading}</HomeText>
<HomeDescText>{description}</HomeDescText>

<Grid
onClick={() => {handleSection()}}
gap={['10px', '10px', '10px', '10px', '20px']}
templateColumns={["repeat(2, 1fr)", "repeat(2, 1fr)", "repeat(4, 1fr)", "repeat(4, 1fr)", "repeat(4, 1fr)"]}
>
<ClothGridBox source={img[0]} />
<ClothGridBox source={img[1]} />
<ClothGridBox source={img[2]} />
<ClothGridBox source={img[3]} />
</Grid>
</Box>
);
};
<Grid
onClick={() => {
handleSection();
}}
gap={["10px", "10px", "10px", "10px", "20px"]}
templateColumns={[
"repeat(2, 1fr)",
"repeat(2, 1fr)",
"repeat(4, 1fr)",
"repeat(4, 1fr)",
"repeat(4, 1fr)",
]}
>
<ClothGridBox source={img[0]} />
<ClothGridBox source={img[1]} />
<ClothGridBox source={img[2]} />
<ClothGridBox source={img[3]} />
</Grid>
</Box>
);
};
2 changes: 1 addition & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import axios from "axios";

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

// axios.defaults.baseURL = "http://localhost:8000";
// axios.defaults.baseURL = "http://localhost:3000";

ReactDOM.createRoot(document.getElementById("root")).render(
// <React.StrictMode>
Expand Down
27 changes: 25 additions & 2 deletions src/pages/Cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,41 @@ import { OrderSummary } from "../components/cart/OrderSummary";
import { useDispatch, useSelector } from "react-redux";
import { useEffect } from "react";
import { getCartProducts } from "../redux/Reducers/cartReducer";
import { setToast } from "../utils/extraFunctions";
import { logoutApi } from "../redux/Reducers/authReducer";
import { removeItem } from "../utils/cookiestorage";
import { useNavigate } from "react-router-dom";
import { removeItemLocal } from "../utils/localstorage";

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

const navigate = useNavigate();
const dispatch = useDispatch();
const toast = useToast();

useEffect(() => {
let payload = [token, toast];
dispatch(getCartProducts(payload));
getCartDetails();
}, []);

async function getCartDetails() {
try {
let payload = [token, toast];
let response = await dispatch(getCartProducts(payload)).unwrap();
} catch (rejectedValueOrSerializedError) {
console.log(
"rejectedValueOrSerializedError",
rejectedValueOrSerializedError
);
if (rejectedValueOrSerializedError.response.data.status === "Failed") {
removeItem("token");
removeItem("user");
dispatch(logoutApi());
setToast(toast, "Session expired. Please login again.", "success");
navigate("/login");
}
}
}
return (
<>
<Box
Expand Down
17 changes: 13 additions & 4 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ function Home() {
p={"6px 20px"}
borderRadius={30}
alignItems={"center"}
fontWeight={0}
_hover={{
bgColor: "black",
}}
fontWeight={"bolder"}
onClick={() => navigate("/sale")}
>
SHOP NOW
Expand All @@ -82,7 +82,7 @@ function Home() {
p={"6px 20px"}
borderRadius={30}
alignItems={"center"}
fontWeight={0}
fontWeight={"bolder"}
_hover={{
bgColor: "black",
}}
Expand All @@ -97,8 +97,8 @@ function Home() {
width={"89%"}
fontSize={"24px"}
textAlign={"left"}
fontWeight={"500"}
marginBottom={2}
fontWeight={"bolder"}
>
Featuerd
</Text>
Expand All @@ -122,6 +122,8 @@ function Home() {
flexDirection={"column"}
alignItems={"center"}
justifyContent={"center"}
cursor={"pointer"}
onClick={() => navigate("/sale")}
>
<Box
color={"white"}
Expand Down Expand Up @@ -161,6 +163,7 @@ function Home() {
borderRadius={20}
color={"black"}
alignItems={"center"}
onClick={() => navigate("/sale")}
>
Explore
</Button>
Expand All @@ -171,6 +174,7 @@ function Home() {
borderRadius={20}
color={"black"}
alignItems={"center"}
onClick={() => navigate("/men")}
>
Top 10 Gifts
</Button>
Expand All @@ -188,6 +192,8 @@ function Home() {
flexDirection={"column"}
alignItems={"center"}
justifyContent={"center"}
cursor={"pointer"}
onClick={() => navigate("/sale")}
>
<Box
color={"white"}
Expand All @@ -205,6 +211,7 @@ function Home() {
transition: "color 0.5s ease-out",
}}
fontWeight="bold"
onClick={() => navigate("/sale")}
>
Early Access
</Text>
Expand All @@ -215,6 +222,7 @@ function Home() {
}}
fontWeight="bold"
fontSize={"24px"}
onClick={() => navigate("/men")}
>
Top Selling
</Text>
Expand All @@ -226,6 +234,7 @@ function Home() {
borderRadius={20}
color={"black"}
alignItems={"center"}
onClick={() => navigate("/sale")}
>
Get It First
</Button>
Expand All @@ -236,7 +245,7 @@ function Home() {
<Box>
{clothData?.map((data, index) =>
loading ? (
<HomeProductLoader />
<HomeProductLoader key={index} />
) : error ? (
<Error />
) : (
Expand Down
Loading

0 comments on commit 5197d03

Please sign in to comment.