Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanireza65 committed Nov 27, 2023
1 parent af02997 commit 715b39e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
13 changes: 7 additions & 6 deletions bookmarks/vanilla/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const FOR_CLASS = "http://www.w3.org/ns/solid/terms#forClass"
export const BOOKMARK = 'http://www.w3.org/2002/01/bookmark#Bookmark'
export const __FOR_CLASS = "http://www.w3.org/ns/solid/terms#forClass"
export const __BOOKMARK = 'http://www.w3.org/2002/01/bookmark#Bookmark'

export const SOLID = {
INSTANCE: "http://www.w3.org/ns/solid/terms#instance",
INSTANCE_CONTAINER: "http://www.w3.org/ns/solid/terms#instanceContainer",
}
export const __PRIVATE_TYPEINDEX = "http://www.w3.org/ns/solid/terms#privateTypeIndex"
export const __PUBLIC_TYPEINDEX = "http://www.w3.org/ns/solid/terms#publicTypeIndex"

export const __SOLID_INSTANCE = "http://www.w3.org/ns/solid/terms#instance"
export const __SOLID_INSTANCE_CONTAINER = "http://www.w3.org/ns/solid/terms#instanceContainer"
19 changes: 9 additions & 10 deletions bookmarks/vanilla/src/utils/TypeIndexHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { getThingAll } from "@inrupt/solid-client";
import {
BOOKMARK
} from "@inrupt/vocab-common-rdf";
import { FOR_CLASS, SOLID } from "../constants";
import { __FOR_CLASS, __PRIVATE_TYPEINDEX, __PUBLIC_TYPEINDEX, __SOLID_INSTANCE, __SOLID_INSTANCE_CONTAINER } from "../constants";
// import { FOR_CLASS, SOLID } from "../constants";

export class TypeIndexHelper {
constructor() { }
Expand All @@ -23,15 +24,12 @@ export class TypeIndexHelper {
}

public static async getTypeIndex({ session, isPrivate }: { session: Session, isPrivate: boolean }) {
if (!session.info.webId) return
const profileDS = await getSolidDataset(session.info.webId, { fetch: session.fetch })

const me = getThing(profileDS, session.info.webId);
const me = await this.getProfile(session)

if (me) {
const predicate = isPrivate ? "privateTypeIndex" : "publicTypeIndex"

const typeIndex = getNamedNode(me, `http://www.w3.org/ns/solid/terms#${predicate}`)
// TODO: me doc exists
const typeIndex = getNamedNode(me, isPrivate ? __PRIVATE_TYPEINDEX : __PUBLIC_TYPEINDEX)

return typeIndex
} else {
Expand All @@ -55,12 +53,12 @@ export class TypeIndexHelper {
const instanceContainers: string[] = []

all.forEach(x => {
const forClass = getNamedNode(x, FOR_CLASS)
const forClass = getNamedNode(x, __FOR_CLASS)

if (forClass?.value === BOOKMARK.Bookmark) {

const instance = getNamedNode(x, SOLID.INSTANCE)?.value
const instanceContainer = getNamedNode(x, SOLID.INSTANCE_CONTAINER)?.value
const instance = getNamedNode(x, __SOLID_INSTANCE)?.value
const instanceContainer = getNamedNode(x, __SOLID_INSTANCE_CONTAINER)?.value

instance && instances?.push(instance)
instanceContainer && instanceContainers?.push(instanceContainer)
Expand All @@ -71,6 +69,7 @@ export class TypeIndexHelper {
instances,
instanceContainers
}
console.log("🚀 ~ file: TypeIndexHelper.ts:75 ~ TypeIndexHelper ~ getFromTypeIndex ~ bookmarkRegisteries:", bookmarkRegisteries)
return bookmarkRegisteries
}
}

0 comments on commit 715b39e

Please sign in to comment.