From 057c4eb64be70b59a729abd3b77601b0f4a462a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tora=C3=B1o?= Date: Mon, 4 Apr 2022 21:52:43 +0200 Subject: [PATCH] Integracion con los PODS en el carrito ya se puede entrar en los pods --- webapp/src/components/ShoppingCart.tsx | 16 ++++++-------- webapp/src/components/solid-pods/LoginPod.tsx | 21 +++++++++++++++++-- .../components/solid-pods/ProfileViewer.tsx | 16 +++++++++++++- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/webapp/src/components/ShoppingCart.tsx b/webapp/src/components/ShoppingCart.tsx index 71803a9..aad36a5 100644 --- a/webapp/src/components/ShoppingCart.tsx +++ b/webapp/src/components/ShoppingCart.tsx @@ -4,6 +4,9 @@ import { useEffect, useState } from 'react'; import { Rock } from '../shared/shareddtypes'; import CartItem from './CartItem'; import '../css/ShoppingCart.css'; +import ProfileViewer from './solid-pods/ProfileViewer'; +import { useSession } from '@inrupt/solid-ui-react'; +import LoginPod from './solid-pods/LoginPod'; @@ -28,7 +31,7 @@ const Cart: React.FC = ({ cartContent, handleAddToCart, handleRemoveFromC

Shopping Cart

{cartContent.length === 0 ?

No items in the cart

: null} - {/* {check2(cartContent)} */} +
{cartContent.map(item => ( @@ -41,15 +44,8 @@ const Cart: React.FC = ({ cartContent, handleAddToCart, handleRemoveFromC ))}

Total: {getTotalPrice().toFixed(2)} €

- + +
) diff --git a/webapp/src/components/solid-pods/LoginPod.tsx b/webapp/src/components/solid-pods/LoginPod.tsx index 6505fc5..0ebee27 100644 --- a/webapp/src/components/solid-pods/LoginPod.tsx +++ b/webapp/src/components/solid-pods/LoginPod.tsx @@ -2,16 +2,30 @@ import { useState, useEffect } from 'react'; import { SessionProvider, useSession } from "@inrupt/solid-ui-react"; import LoginForm from "./LoginForm" import ProfileViewer from "./ProfileViewer" +import React from 'react'; +import { Rock } from '../../shared/shareddtypes'; //import {createData} from "./code/insertExampleData" -function LoginPod(): JSX.Element { + +function LoginPod(): JSX.Element { //We use this state variable const [isLoggedIn, setIsLoggedIn] = useState(false); //With this we can control the login status for solid const { session } = useSession(); + +function getCartContent() { + const memoryCart = localStorage.getItem("cart"); + if (memoryCart) { + return JSON.parse(memoryCart); + } else { + return []; + } +} + + //We have logged in session.onLogin(()=>{ setIsLoggedIn(true) @@ -24,9 +38,12 @@ session.onLogout(()=>{ return ( - {(!isLoggedIn) ? : } + + {(!isLoggedIn) ? : } ) } export default LoginPod; + + diff --git a/webapp/src/components/solid-pods/ProfileViewer.tsx b/webapp/src/components/solid-pods/ProfileViewer.tsx index 29fd4bc..3731872 100644 --- a/webapp/src/components/solid-pods/ProfileViewer.tsx +++ b/webapp/src/components/solid-pods/ProfileViewer.tsx @@ -2,8 +2,13 @@ import { useSession, CombinedDataProvider, Image, LogoutButton, Text } from "@in import { Button, Card, CardActionArea, CardContent, Container, Typography } from "@material-ui/core"; import { FOAF, VCARD } from "@inrupt/lit-generated-vocab-common"; import GetPodAddress from './GetPodAddress'; +import { Rock } from "../../shared/shareddtypes"; -const ProfileViewer = () => { +type Props = { + cartContent: Rock[]; +}; + +const ProfileViewer: React.FC = ({cartContent}) => { const { session } = useSession(); return ( @@ -28,6 +33,15 @@ const ProfileViewer = () => { + );