@@ -126,20 +126,20 @@ export class PeoplePicker {
126126 createNewGroup ( bookBaseUrl ) {
127127 const groupIndexNode = rdf . namedNode ( `${ bookBaseUrl } groups.ttl` )
128128 const graphUrl = `${ bookBaseUrl } Group/${ uuid . v4 ( ) . slice ( 0 , 8 ) } .ttl`
129- const groupGraphNode = rdf . namedNode ( graphUrl )
129+ const graphNode = rdf . namedNode ( graphUrl )
130130 const groupNode = rdf . namedNode ( `${ graphUrl } #this` )
131131 // NOTE that order matters here. Unfortunately this type of update is
132132 // non-atomic in that solid requires us to send two PATCHes, either of which
133133 // might fail.
134- const patchPromises = [ groupGraphNode , groupIndexNode ]
134+ const patchPromises = [ graphNode , groupIndexNode ]
135135 . map ( namedGraph => {
136136 const typeStatement = rdf . st ( groupNode , ns . rdf ( 'type' ) , ns . vcard ( 'Group' ) , namedGraph )
137137 const nameStatement = rdf . st ( groupNode , ns . vcard ( 'fn' ) , 'Untitled Group' , namedGraph )
138138 return webClient . patch ( namedGraph . value , [ ] , [ typeStatement , nameStatement ] )
139139 . then ( ( ) => kb . add ( [ typeStatement , nameStatement ] ) )
140140 } )
141141 return Promise . all ( patchPromises )
142- . then ( ( ) => ( { groupNode, groupGraphNode } ) )
142+ . then ( ( ) => ( { groupNode, graphNode } ) )
143143 . catch ( err => {
144144 throw new Error ( `Couldn't create new group. PATCH failed for (${ err . xhr . responseURL } )` )
145145 } )
@@ -252,9 +252,9 @@ export class GroupBuilder {
252252 makeDropTarget ( dropContainer , uris => {
253253 uris . map ( uri => {
254254 this . add ( uri )
255- . catch ( ( ) => {
255+ . catch ( err => {
256256 this . element . appendChild (
257- errorMessageBlock ( document , escape ( ' Could not load the given WebId' ) )
257+ errorMessageBlock ( document , escape ( ` Could not add the given WebId. ( ${ err } )` ) )
258258 )
259259 } )
260260 } )
@@ -304,26 +304,28 @@ export class GroupBuilder {
304304 kb . fetcher . nowOrWhenFetched ( webId , ( ok , err ) => {
305305 if ( ! ok ) {
306306 this . onGroupChanged ( err )
307- reject ( err )
308- } else {
309- // make sure it's a valid person, group, or entity (for now just handle
310- // webId)
311- const webIdNode = rdf . namedNode ( webId )
312- const rdfClass = kb . any ( webIdNode , ns . rdf ( 'type' ) )
313- if ( ! rdfClass || ! rdfClass . equals ( ns . foaf ( 'Person' ) ) ) {
314- reject ( new Error ( 'Only people supported right now' ) )
315- }
316- // TODO: sync this back to the server
317- const statement = [ this . groupNode , ns . vcard ( 'hasMember' ) , webIdNode , this . groupGraph ]
318- if ( kb . match ( ...statement ) . length < 1 ) {
319- kb . add ( ...statement )
320- // TODO: sync
321- }
322- this . onGroupChanged ( null , 'added' , webIdNode )
323- resolve ( webIdNode )
324- this . render ( )
307+ return reject ( err )
308+ }
309+ // make sure it's a valid person, group, or entity (for now just handle
310+ // webId)
311+ const webIdNode = rdf . namedNode ( webId )
312+ const rdfClass = kb . any ( webIdNode , ns . rdf ( 'type' ) )
313+ if ( ! rdfClass || ! rdfClass . equals ( ns . foaf ( 'Person' ) ) ) {
314+ return reject ( new Error ( `Only people supported right now. (tried to add something of type ${ rdfClass . value } )` ) )
325315 }
316+ return resolve ( webIdNode )
326317 } )
318+ } ) . then ( webIdNode => {
319+ const statement = rdf . st ( this . groupNode , ns . vcard ( 'hasMember' ) , webIdNode , this . groupGraph )
320+ if ( kb . holdsStatement ( statement ) ) {
321+ return webIdNode
322+ }
323+ return webClient . patch ( this . groupGraph . value , [ ] , [ statement ] )
324+ . then ( ( ) => {
325+ kb . add ( statement )
326+ this . onGroupChanged ( null , 'added' , webIdNode )
327+ this . render ( )
328+ } )
327329 } )
328330 }
329331
0 commit comments