From 2937d1508c396cc0228d6c7811cebbc8395966be Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 31 Mar 2020 17:41:39 +0200 Subject: [PATCH 1/9] Initial commit - Created basic structure for route sharing --- package.json | 1 + src/components/navBar/navBar.js | 1 + src/components/routeList/RouteCard.js | 2 + src/pages/ShareView.js | 102 ++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 src/pages/ShareView.js diff --git a/package.json b/package.json index 533bc20..683b346 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,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 4e3533d..28177ec 100644 --- a/src/components/navBar/navBar.js +++ b/src/components/navBar/navBar.js @@ -78,6 +78,7 @@ function MyNavBar(props) { } /> + } /> ); diff --git a/src/components/routeList/RouteCard.js b/src/components/routeList/RouteCard.js index 1ea54f2..c25f667 100644 --- a/src/components/routeList/RouteCard.js +++ b/src/components/routeList/RouteCard.js @@ -2,6 +2,7 @@ import React from 'react'; import Card from 'react-bootstrap/Card'; import Button from 'react-bootstrap/Button'; import MyMap from './../myMap/MyMap'; +import ShareView from '../../pages/ShareView'; function RouteCard(props) { return ( @@ -15,6 +16,7 @@ function RouteCard(props) { {props.route.name} {props.route.description} + ); diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js new file mode 100644 index 0000000..0c07c4c --- /dev/null +++ b/src/pages/ShareView.js @@ -0,0 +1,102 @@ +import React from "react"; +import * as auth from 'solid-auth-client'; +import SolidFileClient from 'solid-file-client'; +import data from "@solid/query-ldflex"; + +class ShareView extends React.Component { + + constructor(props) { + super(); + this.routeId = props.match.params.id; + this.session = await auth.currentSession(); + this.webId= null; + this.friends = []; + } + + render() { + this.readFriends(); + return ( + + + + + + + + {this.printRows()} +
+
#NameShare
+ ); + } + + printRows(){ + let counter = 0; + while(counter < this.friends.length){ + + {counter} + {this.friends[counter].name} + + + + + } + } + + async readFriends(){ + var app = this; + this.friends = []; + app.friends = [... app.friends] + for await (const friend of data.user.friends){ + const f = {} + const n = await data[friend].vcard$fn; + const inbox = await data[friend].inbox; + f.webId= `${friend}` + f.name = `${n}` + f.inbox = `${inbox}` + if (n ==undefined){ + f.name = `${friend}` + } + app.friends = [... app.friends, f] + } + } + + async send(){ + var message = {} + message.date = new Date(Date.now()) + message.id = message.date.getTime() + message.sender = this.webId + message.recipient = this.recipient + message.content = this.shadowRoot.getElementById("messageContent").value.trim() + message.title = this.shadowRoot.getElementById("title").value.trim() + message.url = message.recipient+message.id+".ttl" + this.shadowRoot.getElementById("to").value = "" + this.shadowRoot.getElementById("title").value = "" + this.shadowRoot.getElementById("messageContent").value = "" + this.shadowRoot.getElementById("writePan").style.display = "none" + if(message.content.length > 0 && message.title.length > 0 && message.recipient.length > 0){ + this.buildMessage(message) + }else{ + alert("Recipient or title or content is empty") + } + + } + + async buildMessage(message){ + var mess = message.url + //message + await data[mess].schema$text.add(message.content); + await data[mess].rdfs$label.add(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)) + //log + var log = message.recipient+"log.ttl#"+message.id + await data[log].schema$message.add(namedNode(mess)) + await data[log].schema$dateSent.add(message.date.toISOString()) + await data[log].schema$sender.add(namedNode(this.webId)) + await data[log].rdfs$label.add(message.title) + } +} + +export default ShareView; \ No newline at end of file From 4f6c93f8d643ed9425edec8d6b32355fbf7fea64 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 31 Mar 2020 20:53:39 +0200 Subject: [PATCH 2/9] List friends for sharing --- src/components/navBar/navBar.js | 3 +- src/pages/ShareView.js | 102 -------------------------------- src/pages/ShareView.jsx | 56 ++++++++++++++++++ 3 files changed, 58 insertions(+), 103 deletions(-) delete mode 100644 src/pages/ShareView.js create mode 100644 src/pages/ShareView.jsx diff --git a/src/components/navBar/navBar.js b/src/components/navBar/navBar.js index 28177ec..b89b31c 100644 --- a/src/components/navBar/navBar.js +++ b/src/components/navBar/navBar.js @@ -17,6 +17,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(); @@ -78,7 +79,7 @@ function MyNavBar(props) { } /> - } /> + } /> ); diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js deleted file mode 100644 index 0c07c4c..0000000 --- a/src/pages/ShareView.js +++ /dev/null @@ -1,102 +0,0 @@ -import React from "react"; -import * as auth from 'solid-auth-client'; -import SolidFileClient from 'solid-file-client'; -import data from "@solid/query-ldflex"; - -class ShareView extends React.Component { - - constructor(props) { - super(); - this.routeId = props.match.params.id; - this.session = await auth.currentSession(); - this.webId= null; - this.friends = []; - } - - render() { - this.readFriends(); - return ( - - - - - - - - {this.printRows()} -
-
#NameShare
- ); - } - - printRows(){ - let counter = 0; - while(counter < this.friends.length){ - - {counter} - {this.friends[counter].name} - - - - - } - } - - async readFriends(){ - var app = this; - this.friends = []; - app.friends = [... app.friends] - for await (const friend of data.user.friends){ - const f = {} - const n = await data[friend].vcard$fn; - const inbox = await data[friend].inbox; - f.webId= `${friend}` - f.name = `${n}` - f.inbox = `${inbox}` - if (n ==undefined){ - f.name = `${friend}` - } - app.friends = [... app.friends, f] - } - } - - async send(){ - var message = {} - message.date = new Date(Date.now()) - message.id = message.date.getTime() - message.sender = this.webId - message.recipient = this.recipient - message.content = this.shadowRoot.getElementById("messageContent").value.trim() - message.title = this.shadowRoot.getElementById("title").value.trim() - message.url = message.recipient+message.id+".ttl" - this.shadowRoot.getElementById("to").value = "" - this.shadowRoot.getElementById("title").value = "" - this.shadowRoot.getElementById("messageContent").value = "" - this.shadowRoot.getElementById("writePan").style.display = "none" - if(message.content.length > 0 && message.title.length > 0 && message.recipient.length > 0){ - this.buildMessage(message) - }else{ - alert("Recipient or title or content is empty") - } - - } - - async buildMessage(message){ - var mess = message.url - //message - await data[mess].schema$text.add(message.content); - await data[mess].rdfs$label.add(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)) - //log - var log = message.recipient+"log.ttl#"+message.id - await data[log].schema$message.add(namedNode(mess)) - await data[log].schema$dateSent.add(message.date.toISOString()) - await data[log].schema$sender.add(namedNode(this.webId)) - await data[log].rdfs$label.add(message.title) - } -} - -export default ShareView; \ No newline at end of file diff --git a/src/pages/ShareView.jsx b/src/pages/ShareView.jsx new file mode 100644 index 0000000..ec022d8 --- /dev/null +++ b/src/pages/ShareView.jsx @@ -0,0 +1,56 @@ +import React from "react"; +import * as auth from 'solid-auth-client'; +import SolidFileClient from 'solid-file-client'; +import data from '@solid/query-ldflex'; +import Table from 'react-bootstrap/Table'; +import { namedNode } from '@rdfjs/data-model'; +class ShareView extends React.Component { + + constructor(props) { + super(); + this.routeId = props.match.params.id; + this.session = null; + this.webId= null; + this.friends = []; + } + + render() { + this.readFriends() + return ( +
+ { + this.friends.map((friend) =>{ + return
+

{friend.name}

+ +
; + })} +
+ ); + } + + printTable(){ + + } + + async readFriends(){ + this.session = await auth.currentSession(); + var app = this; + this.friends = []; + app.friends = [... app.friends] + for await (const friend of data.user.friends){ + const f = {} + const n = await data[friend].vcard$fn; + const inbox = await data[friend].inbox; + f.webId= `${friend}` + f.name = `${n}` + f.inbox = `${inbox}` + if (n ==undefined){ + f.name = `${friend}` + } + app.friends = [... app.friends, f] + } + } +} + +export default ShareView; \ No newline at end of file From d2d33c99e127186953af34df001b4a0b06de6542 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 31 Mar 2020 22:13:08 +0200 Subject: [PATCH 3/9] Visualization of the list of friends works --- src/components/navBar/navBar.js | 2 +- src/components/routeList/RouteCard.js | 1 - src/pages/ShareView.jsx | 44 +++++++++++++-------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/components/navBar/navBar.js b/src/components/navBar/navBar.js index b89b31c..fddd113 100644 --- a/src/components/navBar/navBar.js +++ b/src/components/navBar/navBar.js @@ -79,7 +79,7 @@ function MyNavBar(props) { } /> - } /> + } /> ); diff --git a/src/components/routeList/RouteCard.js b/src/components/routeList/RouteCard.js index c25f667..134af2b 100644 --- a/src/components/routeList/RouteCard.js +++ b/src/components/routeList/RouteCard.js @@ -2,7 +2,6 @@ import React from 'react'; import Card from 'react-bootstrap/Card'; import Button from 'react-bootstrap/Button'; import MyMap from './../myMap/MyMap'; -import ShareView from '../../pages/ShareView'; function RouteCard(props) { return ( diff --git a/src/pages/ShareView.jsx b/src/pages/ShareView.jsx index ec022d8..52c1cc6 100644 --- a/src/pages/ShareView.jsx +++ b/src/pages/ShareView.jsx @@ -8,48 +8,48 @@ class ShareView extends React.Component { constructor(props) { super(); - this.routeId = props.match.params.id; - this.session = null; - this.webId= null; - this.friends = []; + this.state = { + friends: [] + }; + this.readFriends(); } render() { - this.readFriends() return (
{ - this.friends.map((friend) =>{ - return
-

{friend.name}

- -
; - })} + this.state.friends.map((friend) => { + return
+

{friend.name}

+ +
; + }) + }
); } - - printTable(){ - + + async send() { + } - - async readFriends(){ + + async readFriends() { this.session = await auth.currentSession(); var app = this; - this.friends = []; - app.friends = [... app.friends] - for await (const friend of data.user.friends){ + 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; - f.webId= `${friend}` + f.webId = `${friend}` f.name = `${n}` f.inbox = `${inbox}` - if (n ==undefined){ + if (n == undefined) { f.name = `${friend}` } - app.friends = [... app.friends, f] + friends = [...friends, f] } + this.setState({ friends: friends }); } } From bbbf36238a81fe2d55de39cfc834d71754c62665 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 1 Apr 2020 19:27:40 +0200 Subject: [PATCH 4/9] Trying to send a test message to the inbox of a friend --- src/pages/{ShareView.jsx => ShareView.js} | 43 +++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) rename src/pages/{ShareView.jsx => ShareView.js} (52%) diff --git a/src/pages/ShareView.jsx b/src/pages/ShareView.js similarity index 52% rename from src/pages/ShareView.jsx rename to src/pages/ShareView.js index 52c1cc6..13366d7 100644 --- a/src/pages/ShareView.jsx +++ b/src/pages/ShareView.js @@ -12,6 +12,8 @@ class ShareView extends React.Component { friends: [] }; this.readFriends(); + this.webId = null; + this.messages = []; } render() { @@ -21,7 +23,7 @@ class ShareView extends React.Component { this.state.friends.map((friend) => { return

{friend.name}

- +
; }) } @@ -29,12 +31,8 @@ class ShareView extends React.Component { ); } - async send() { - - } - async readFriends() { - this.session = await auth.currentSession(); + this.webId = await auth.currentSession(); var app = this; let friends = []; for await (const friend of data.user.friends) { @@ -51,6 +49,39 @@ class ShareView extends React.Component { } this.setState({ friends: friends }); } + + + async send(destination) { + var message = {}; + message.date = new Date(Date.now()); + message.id = message.date.getTime(); + message.sender = await auth.currentSession(); + message.recipient = destination; + + message.content = "Holaa, esto es una prueba"; + + message.title = "Check out this route shared to you by " + this.getSessionName(); + message.url = message.recipient + message.id + ".json"; + + await this.buildMessage(message); + + } + + async buildMessage(message) { + var mess = message.url + //message + await data[mess].schema$text.add(message.content); + await data[mess].rdfs$label.add(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)); + } + + async getSessionName(){ + var session = await auth.currentSession(); + var tmp = session.webId.split(".")[0]; + return tmp.split("//")[1]; + } } export default ShareView; \ No newline at end of file From 90ad7f1a83310d087b9feef573803be87a560070 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 1 Apr 2020 20:05:42 +0200 Subject: [PATCH 5/9] Now you can send a test notification to your friends inbox --- src/pages/ShareView.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js index 13366d7..464540e 100644 --- a/src/pages/ShareView.js +++ b/src/pages/ShareView.js @@ -23,7 +23,7 @@ class ShareView extends React.Component { this.state.friends.map((friend) => { return

{friend.name}

- +
; }) } @@ -32,7 +32,8 @@ class ShareView extends React.Component { } async readFriends() { - this.webId = await auth.currentSession(); + let session = await auth.currentSession(); + this.webId = session.webId; var app = this; let friends = []; for await (const friend of data.user.friends) { @@ -48,6 +49,7 @@ class ShareView extends React.Component { friends = [...friends, f] } this.setState({ friends: friends }); + console.log(this.webId) } @@ -55,12 +57,12 @@ class ShareView extends React.Component { var message = {}; message.date = new Date(Date.now()); message.id = message.date.getTime(); - message.sender = await auth.currentSession(); + message.sender = this.webId; message.recipient = destination; message.content = "Holaa, esto es una prueba"; - message.title = "Check out this route shared to you by " + this.getSessionName(); + message.title = "Check out this route shared to you by " + await this.getSessionName(); message.url = message.recipient + message.id + ".json"; await this.buildMessage(message); @@ -68,18 +70,19 @@ class ShareView extends React.Component { } async buildMessage(message) { - var mess = message.url + console.log(message); + var mess = message.url; //message await data[mess].schema$text.add(message.content); - await data[mess].rdfs$label.add(message.title); + 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)); - } + } async getSessionName(){ - var session = await auth.currentSession(); - var tmp = session.webId.split(".")[0]; + var session = this.webId; + var tmp = session.split(".")[0]; return tmp.split("//")[1]; } } From 36072b1c9eae614034f480057c6050ac6f144981 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 1 Apr 2020 21:36:59 +0200 Subject: [PATCH 6/9] Changed route name when stored+Send URI in notificatons instead of test --- src/model/MyRoute.js | 2 +- src/pages/ShareView.js | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/model/MyRoute.js b/src/model/MyRoute.js index 1814bb5..56e1e39 100644 --- a/src/model/MyRoute.js +++ b/src/model/MyRoute.js @@ -54,7 +54,7 @@ class MyRoute { } getFileName() { - return this.name + "_" + this.id + ".json"; + return this.id + ".json"; } getComparableString() { diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js index 464540e..998b9ce 100644 --- a/src/pages/ShareView.js +++ b/src/pages/ShareView.js @@ -13,7 +13,7 @@ class ShareView extends React.Component { }; this.readFriends(); this.webId = null; - this.messages = []; + this.id = props.match.params.id; } render() { @@ -60,9 +60,10 @@ class ShareView extends React.Component { message.sender = this.webId; message.recipient = destination; - message.content = "Holaa, esto es una prueba"; + let folder = "/viade/routes/" + message.content = this.getWebIdWithoutProfile() + folder + this.id + ".json"; - message.title = "Check out this route shared to you by " + await this.getSessionName(); + message.title = "Check out this route shared to you by " + this.getSessionName(); message.url = message.recipient + message.id + ".json"; await this.buildMessage(message); @@ -80,11 +81,20 @@ class ShareView extends React.Component { await data[mess].schema$sender.add(namedNode(this.webId)); } - async getSessionName(){ + 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]; + console.log(tmp); + return tmp; + + } + } export default ShareView; \ No newline at end of file From ed9e29c0497b8fc9e7913d54fe3c901c378b4fb3 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 1 Apr 2020 22:36:07 +0200 Subject: [PATCH 7/9] Changed style for friends and "share" buttons --- src/components/routeList/RouteCard.js | 2 +- src/pages/ShareView.js | 42 +++++++++++++++++++++------ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/components/routeList/RouteCard.js b/src/components/routeList/RouteCard.js index 134af2b..802d5f7 100644 --- a/src/components/routeList/RouteCard.js +++ b/src/components/routeList/RouteCard.js @@ -15,7 +15,7 @@ function RouteCard(props) { {props.route.name} {props.route.description} - + ); diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js index 998b9ce..72ab15e 100644 --- a/src/pages/ShareView.js +++ b/src/pages/ShareView.js @@ -1,8 +1,8 @@ import React from "react"; import * as auth from 'solid-auth-client'; -import SolidFileClient from 'solid-file-client'; import data from '@solid/query-ldflex'; -import Table from 'react-bootstrap/Table'; +import Card from 'react-bootstrap/Card'; +import Button from 'react-bootstrap/Button'; import { namedNode } from '@rdfjs/data-model'; class ShareView extends React.Component { @@ -18,32 +18,55 @@ class ShareView extends React.Component { render() { return ( -
+
+
{ this.state.friends.map((friend) => { - return
-

{friend.name}

- -
; + return
+ + + + {friend.name} + + + +
+ //
+ //

{friend.name}

+ // + //
; }) }
+
); } async readFriends() { let session = await auth.currentSession(); this.webId = session.webId; - var app = this; 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) { + if (n === undefined) { f.name = `${friend}` } friends = [...friends, f] @@ -67,6 +90,7 @@ class ShareView extends React.Component { message.url = message.recipient + message.id + ".json"; await this.buildMessage(message); + alert ("Your friend has received a notification with your route!"); } From 87eae61d8a7ddabda156ec07ceb6049f0d942332 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 1 Apr 2020 22:47:48 +0200 Subject: [PATCH 8/9] Fixing codacy --- src/pages/ShareView.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js index 72ab15e..2b3e476 100644 --- a/src/pages/ShareView.js +++ b/src/pages/ShareView.js @@ -32,14 +32,10 @@ class ShareView extends React.Component { {friend.name} + onClick={() => {this.send(friend.inbox)}}>Share; -
- //
- //

{friend.name}

- // - //
; + ; }) } @@ -52,7 +48,7 @@ class ShareView extends React.Component { this.webId = session.webId; let friends = []; for await (const friend of data.user.friends) { - const f = {} + const f = {}; const n = await data[friend].vcard$fn; const inbox = await data[friend].inbox; const imageLd = await data[friend].vcard_hasPhoto; @@ -63,16 +59,15 @@ class ShareView extends React.Component { f.image = ""; } - f.webId = `${friend}` - f.name = `${n}` - f.inbox = `${inbox}` + f.webId = `${friend}`; + f.name = `${n}`; + f.inbox = `${inbox}`; if (n === undefined) { - f.name = `${friend}` + f.name = `${friend}`; } friends = [...friends, f] } this.setState({ friends: friends }); - console.log(this.webId) } @@ -83,7 +78,7 @@ class ShareView extends React.Component { message.sender = this.webId; message.recipient = destination; - let folder = "/viade/routes/" + let folder = "/viade/routes/"; message.content = this.getWebIdWithoutProfile() + folder + this.id + ".json"; message.title = "Check out this route shared to you by " + this.getSessionName(); @@ -95,7 +90,6 @@ class ShareView extends React.Component { } async buildMessage(message) { - console.log(message); var mess = message.url; //message await data[mess].schema$text.add(message.content); From 3198d623ee17edff13754e4dd50688c7a3d016e7 Mon Sep 17 00:00:00 2001 From: Diego Date: Wed, 1 Apr 2020 22:53:02 +0200 Subject: [PATCH 9/9] More codacy issues --- src/pages/ShareView.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/ShareView.js b/src/pages/ShareView.js index 2b3e476..1c45bdd 100644 --- a/src/pages/ShareView.js +++ b/src/pages/ShareView.js @@ -32,7 +32,7 @@ class ShareView extends React.Component { {friend.name} ; + onClick={() => {this.send(friend.inbox);}}>Share ; @@ -65,9 +65,9 @@ class ShareView extends React.Component { if (n === undefined) { f.name = `${friend}`; } - friends = [...friends, f] + friends = [...friends, f]; } - this.setState({ friends: friends }); + this.setState({ friends }); } @@ -108,7 +108,6 @@ class ShareView extends React.Component { getWebIdWithoutProfile(){ let wId = this.webId; let tmp = wId.split("profile")[0]; - console.log(tmp); return tmp; }