diff --git a/package.json b/package.json index 338c3c4..41383fd 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "react-router-dom": "^5.1.2", "react-scripts": "^3.4.0", "shx": "0.3.2", + "solid-auth-client": "^2.4.1", "solid-file-client": "^1.0.2", "uuid": "^7.0.2" }, diff --git a/src/components/navBar/navBar.js b/src/components/navBar/navBar.js index 0c7410d..728a7d2 100644 --- a/src/components/navBar/navBar.js +++ b/src/components/navBar/navBar.js @@ -20,6 +20,7 @@ import gitHubLogo from './../../assets/githubLogo/github.png'; import viadeLogo from './../../assets/logo/logo_alt.jpeg'; import viadeText from './../../assets/logo/logo_letters.jpeg'; import RouteManager from "./../../model/RouteManager"; +import ShareView from '../../pages/ShareView'; const routeManager = new RouteManager(); @@ -90,6 +91,7 @@ function MyNavBar(props) { } /> + } /> ); diff --git a/src/components/routeList/RouteCard.js b/src/components/routeList/RouteCard.js index 1ea54f2..802d5f7 100644 --- a/src/components/routeList/RouteCard.js +++ b/src/components/routeList/RouteCard.js @@ -15,6 +15,7 @@ function RouteCard(props) { {props.route.name} {props.route.description} Info + Share ); diff --git a/src/model/MyRoute.js b/src/model/MyRoute.js index d94574a..12b45da 100644 --- a/src/model/MyRoute.js +++ b/src/model/MyRoute.js @@ -61,7 +61,7 @@ class MyRoute { } getFileName() { - return this.name + "_" + this.id + ".json"; + return this.id + ".json"; } async uploadToPod(callback) { diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js new file mode 100644 index 0000000..1c45bdd --- /dev/null +++ b/src/pages/ShareView.js @@ -0,0 +1,117 @@ +import React from "react"; +import * as auth from 'solid-auth-client'; +import data from '@solid/query-ldflex'; +import Card from 'react-bootstrap/Card'; +import Button from 'react-bootstrap/Button'; +import { namedNode } from '@rdfjs/data-model'; +class ShareView extends React.Component { + + constructor(props) { + super(); + this.state = { + friends: [] + }; + this.readFriends(); + this.webId = null; + this.id = props.match.params.id; + } + + render() { + return ( + + + { + this.state.friends.map((friend) => { + return + + + + {friend.name} + {this.send(friend.inbox);}}>Share + + + ; + }) + } + + + ); + } + + async readFriends() { + let session = await auth.currentSession(); + this.webId = session.webId; + let friends = []; + for await (const friend of data.user.friends) { + const f = {}; + const n = await data[friend].vcard$fn; + const inbox = await data[friend].inbox; + const imageLd = await data[friend].vcard_hasPhoto; + + if (imageLd && imageLd.value) { + f.image = imageLd.value; + } else { + f.image = ""; + } + + f.webId = `${friend}`; + f.name = `${n}`; + f.inbox = `${inbox}`; + if (n === undefined) { + f.name = `${friend}`; + } + friends = [...friends, f]; + } + this.setState({ friends }); + } + + + async send(destination) { + var message = {}; + message.date = new Date(Date.now()); + message.id = message.date.getTime(); + message.sender = this.webId; + message.recipient = destination; + + let folder = "/viade/routes/"; + message.content = this.getWebIdWithoutProfile() + folder + this.id + ".json"; + + message.title = "Check out this route shared to you by " + this.getSessionName(); + message.url = message.recipient + message.id + ".json"; + + await this.buildMessage(message); + alert ("Your friend has received a notification with your route!"); + + } + + async buildMessage(message) { + var mess = message.url; + //message + await data[mess].schema$text.add(message.content); + await data[mess].rdfs$label.add("routeShared: message.title"); + await data[mess].schema$dateSent.add(message.date.toISOString()); + await data[mess].rdf$type.add(namedNode('https://schema.org/Message')); + await data[mess].schema$sender.add(namedNode(this.webId)); + } + + getSessionName(){ + var session = this.webId; + var tmp = session.split(".")[0]; + return tmp.split("//")[1]; + } + + getWebIdWithoutProfile(){ + let wId = this.webId; + let tmp = wId.split("profile")[0]; + return tmp; + + } + +} + +export default ShareView; \ No newline at end of file