Skip to content

Commit

Permalink
(WIP) Add first pass pseudocode to getOrUpdateContext function and up…
Browse files Browse the repository at this point in the history
…date getParams in filtering functions
  • Loading branch information
marcellamaki committed Apr 1, 2021
1 parent 9bb70c8 commit 55ba11f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions packages/hashi/src/kolibri.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export default class Kolibri extends BaseShim {

// const nameSpace = self.nameSpace;

// const nameSpace = self.nameSpace;

class Shim {
/*
* Method to query contentnodes from Kolibri and return
Expand Down
45 changes: 24 additions & 21 deletions packages/hashi/src/mainClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ export default class MainClient {
this.contentNamespace = null;
this.startUrl = null;
this.__setData = this.__setData.bind(this);

// this.mediator.registerMessageHandler({
// nameSpace,
// event: events.GETCONTENT,
// callback: () => {
// // this.mediator.sendMessage({ nameSpace, event: events.REQUESTINGDATA, data: true });
// },
// });
}
initialize(contentState, userData, startUrl, contentNamespace) {
/*
Expand Down Expand Up @@ -135,20 +127,25 @@ export default class MainClient {

// if filtering by optional params
if (message.options) {
let hash = window.location.hash.split('/');
let id = hash[hash.length - 1];
ContentNodeResource.fetchCollection({ id }).then(contentNodes => {
if (contentNodes) {
message.status = 'success';
} else {
message.status = 'failure';
}
let getParams = {};
let options = message.options;
if (options.parent && options.parent == 'self') {
// need to fetch this value when this
// function is move to a location that has access
// to `content`
// getParams.parent = rootNode;
} else if (options.parent) {
getParams.parent = options.parent;
}
options.ids ? (getParams.ids = options.ids) : null;
options.page ? (getParams.page = options.page) : null;
options.pageSize ? (getParams.ids = options.pageSize) : null;
ContentNodeResource.fetchCollection({ getParams }).then(contentNodes => {
contentNodes ? (message.status = 'success') : (message.status = 'failure');
let response = {};
response.page = message.options.page ? message.options.page : 1;
response.pageSize = message.options.pageSize ? message.options.pageSize : 50;
console.log(response);
let results = contentNodes.filter(node => node.id == id);
response.results = results;
response.results = contentNodes;
message.data = response;
message.type = 'response';
this.mediator.sendMessage({
Expand Down Expand Up @@ -179,7 +176,6 @@ export default class MainClient {
}

__navigateTo(message) {
console.log('navigating');
let id = message.nodeId;
ContentNodeResource.fetchModel({ id }).then(contentNode => {
let routeBase, context;
Expand All @@ -202,7 +198,14 @@ export default class MainClient {
}

__getOrUpdateContext(message) {
console.log(message);
// to update context with the incoming context
if (message.context) {
router.push({ query: { context: message.context } }).catch(() => {});
} else {
// just return the existing query
const urlParams = new URLSearchParams(window.location.search);
return urlParams.has('context') ? urlParams.get('context') : null;
}
}

get data() {
Expand Down

0 comments on commit 55ba11f

Please sign in to comment.