Skip to content

Commit

Permalink
Fix #82
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Jan 26, 2024
1 parent 50cf2a7 commit 31a2d8f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const Bookmarks: FC<IProps> = () => {

useEffect(() => {
if (session && isLoggedIn) loadBookmarks();
}, [session, isLoggedIn, loadBookmarks]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session, isLoggedIn]);

const handleSubmit = async () => {
if (bookmarkToUpdate) {
Expand Down
48 changes: 32 additions & 16 deletions bookmarks/vanilla/src/modules/Bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,37 @@ export class Bookmark {
): Promise<IBookmark[]> {
const bookmarkDocUrls = await this.getAllBookmarkDocUrls(fetch, webId, defaultPrivateBookmarkDocUrl);
try {
const all = bookmarkDocUrls.map(async (indexUrl) => {
const ds = await getSolidDataset(indexUrl, { fetch: fetch });

const all = bookmarkDocUrls.map(async (bookmarkDocUrl) => {
const ds = await getSolidDataset(bookmarkDocUrl, { fetch: fetch });
// console.log('data set for', bookmarkDocUrl);
const things = getThingAll(ds).filter(thing => {
if (thing && thing.predicates && thing.predicates['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']) {
const types = thing.predicates['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'];
if (types && types.namedNodes && types.namedNodes.find((node: any) => node.value === 'http://www.w3.org/2002/01/bookmark#Bookmark'))
console.log();
return true;
// console.log('thing', thing, thing.predicates, thing.predicates[RDF.type], thing.predicates[RDF.type].namedNodes);
if (thing && thing.predicates && thing.predicates[RDF.type] && thing.predicates[RDF.type].namedNodes) {
const types = thing.predicates[RDF.type].namedNodes;
// console.log("thing types", types, JSON.stringify(types));
if (types && types.find((rdfType: string) => rdfType === BOOKMARK.Bookmark)) {
// console.log('found bookmark (type one)', thing.url);
return true;
}
if (types && types.find((rdfType: string) => rdfType === "http://www.w3.org/2002/01/bookmark#BookMark")) {
// console.log('found bookmark (type two)', thing.url);
return true;
}
if (types && types.find((rdfType: string) => rdfType === AS.Note)) {
// console.log('found bookmark (type three)', thing.url);
return true;
}
}
// console.log('found non-bookmark', thing.url);
return false;
})

});
// console.log('things', things);
const bookmarks = await things.map(thing => this.mapBookmark(thing))

const resources = bookmarks.filter(Bookmark => !Bookmark.url.endsWith('-metadata'))
const metadatas = bookmarks.filter(Bookmark => Bookmark.url.endsWith('-metadata'))

const responce = resources.map(bookmark => {
const response = resources.map(bookmark => {
const metadata = metadatas.find((meta: any) => meta.resource === bookmark.url) as any

return {
Expand All @@ -156,7 +168,7 @@ export class Bookmark {
}
})

return responce
return response
})
const allPromise = Promise.all([...all]);
const values = (await allPromise).flat();
Expand Down Expand Up @@ -241,9 +253,9 @@ export class Bookmark {
if (creator && !isValidUrl(creator))
throw new Error("creator is not a valid URL");

const [indexUrl] = await this.getAllBookmarkDocUrls(fetch, webId, defaultPrivateBookmarkDocUrl);
const [bookmarkDocUrl] = await this.getAllBookmarkDocUrls(fetch, webId, defaultPrivateBookmarkDocUrl);

const ds = await getSolidDataset(indexUrl, { fetch: fetch });
const ds = await getSolidDataset(bookmarkDocUrl, { fetch: fetch });

let newBookmarkThing = createThing();

Expand Down Expand Up @@ -292,7 +304,7 @@ export class Bookmark {

const updatedBookmarkList = setThing(ds, newBookmarkThing);
const updatedDataset = await saveSolidDatasetAt(
indexUrl,
bookmarkDocUrl,
updatedBookmarkList,
{ fetch: fetch }
);
Expand Down Expand Up @@ -361,7 +373,7 @@ export class Bookmark {
const updated = this.mapUpdated(thing);
const creator = this.mapCreator(thing);
const resource = getNamedNode(thing, __crdt_resource)?.value;
return {
const ret = {
url,
title,
link,
Expand All @@ -371,6 +383,8 @@ export class Bookmark {
...(creator && { creator }),
...(resource && { resource }),
};
console.log('mapped bookmark', thing.predicates, ret);
return ret;
}

/**
Expand All @@ -397,8 +411,10 @@ export class Bookmark {
* @internal
*/
private static mapLink(thing: ThingPersisted): string {
// console.log('mapping link', getLiteral(thing, BOOKMARK.recalls)?.value, )
return (
getLiteral(thing, BOOKMARK.recalls)?.value ??
getNamedNode(thing, BOOKMARK.recalls)?.value ??
getNamedNode(thing, AS.url)?.value ??
""
);
Expand Down

0 comments on commit 31a2d8f

Please sign in to comment.