Skip to content

Commit

Permalink
Merge pull request #111 from openstad/bugfix/currentuser-bugfix-and-c…
Browse files Browse the repository at this point in the history
…leanup

Fixed small bug that prevents a proper login, removed legacy config key
  • Loading branch information
LorenzoJokhan authored Jan 4, 2024
2 parents 6885b34 + de0879a commit 470d962
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 34 deletions.
101 changes: 68 additions & 33 deletions packages/data-store/src/hooks/use-comments.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
import { useState } from 'react';

export default function useComments(props) {

let self = this;

const projectId = props.projectId || props.config.projectId;
const resourceId = props.resourceId || props.config.resourceId;
const sentiment = props.sentiment || props.config.sentiment || null;
const projectId = props.projectId;
const resourceId = props.resourceId;
const sentiment = props.sentiment || null;

const { data, error, isLoading } = self.useSWR({ projectId, resourceId, sentiment }, 'comments.fetch');
const { data, error, isLoading } = self.useSWR(
{ projectId, resourceId, sentiment },
'comments.fetch'
);

// add functionality
let comments = data || [];
comments.create = function(newData) {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.create', newData, { action: 'create' });
}
comments.map( async comment => {
comment.update = function(newData) {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.update', newData, { action: 'update' });
}
comment.delete = function(newData) {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.delete', comment, { action: 'delete' });
}
comment.submitLike = function() {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.submitLike', comment, { action: 'update' });
}
comment.replies?.map( async reply => {
reply.update = function(newData) {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.update', newData, { action: 'update' });
}
reply.delete = function(newData) {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.delete', reply, { action: 'delete' });
}
reply.submitLike = function() {
return self.mutate({ projectId, resourceId, sentiment }, 'comments.submitLike', reply, { action: 'update' });
}
})
})

return [ comments, error, isLoading ];
comments.create = function (newData) {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.create',
newData,
{ action: 'create' }
);
};
comments.map(async (comment) => {
comment.update = function (newData) {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.update',
newData,
{ action: 'update' }
);
};
comment.delete = function (newData) {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.delete',
comment,
{ action: 'delete' }
);
};
comment.submitLike = function () {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.submitLike',
comment,
{ action: 'update' }
);
};
comment.replies?.map(async (reply) => {
reply.update = function (newData) {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.update',
newData,
{ action: 'update' }
);
};
reply.delete = function (newData) {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.delete',
reply,
{ action: 'delete' }
);
};
reply.submitLike = function () {
return self.mutate(
{ projectId, resourceId, sentiment },
'comments.submitLike',
reply,
{ action: 'update' }
);
};
});
});

return [comments, error, isLoading];
}

3 changes: 2 additions & 1 deletion packages/data-store/src/hooks/use-current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function useCurrentUser(props) {

// get user from props
let initialUser = props.openStadUser || props.config?.openStadUser || {};

if (initialUser.id && initialUser.projectId == self.projectId) {
return initialUser;
}
Expand All @@ -37,7 +38,7 @@ export default function useCurrentUser(props) {
history.replaceState(null, '', url);
}

const cmsUser = props.cmsUser || props.config.cmsUser || {};
const cmsUser = props.cmsUser || {};
// get cmsUser from session data - this is a fix for badly written cms logouts
let sessionCmsUser = session.get('cmsUser') || {};
if (sessionCmsUser && cmsUser) {
Expand Down

0 comments on commit 470d962

Please sign in to comment.