-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from openstad/bugfix/currentuser-bugfix-and-c…
…leanup Fixed small bug that prevents a proper login, removed legacy config key
- Loading branch information
Showing
2 changed files
with
70 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters