Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
< Back
<div>
<span>Moderation queue for {blog.name}</span>
<span>Nasty comments ({nastyComments.length})</span>
{nastyComments.map(comment => (
))}
</div>
)
const enhance = compose(
withPropsOnChange(['match'], ({ match }) => ({
blogId: match.params.blogId,
})),
withObservables(['id'], ({ blogId, database }) => ({
blog: database.collections.get('blogs').findAndObserve(blogId),
})),
withObservables(['blog'], ({ blog }) => ({
nastyComments: blog.nastyComments.observe(),
})),
)
export default withDatabase(enhance(ModerationQueue))
import React from 'react'
import withObservables from '@nozbe/with-observables'
import style from './style'
const RawComment = ({ comment }) => (
<div>
{comment.isNasty && '☹️ '}
{comment.body}
</div>
)
const enhance = withObservables(['comment'], ({ comment }) => ({
comment: comment.observe(),
}))
export default enhance(RawComment)
countObservable={blog.nastyComments.observeCount()}
to={to}
isActive={isActive}
onClick={onClick} />
)
const RawPostItem = ({ post, to, onClick, isActive }) => (
)
const PostItem = compose(
withObservables(['post'], ({ post }) => ({
post: post.observe(),
})),
withHandlers({
onClick: ({ onClick, post, showMain }) => e => {
onClick(e, post.id)
showMain()
},
}),
)(RawPostItem)
const NastyCommentsItem = compose(
withHandlers({
onClick: ({ onClick, blog, showMain }) => e => {
onClick(e, blog.id)
showMain()
},
<>
)}
ListFooterComponent={() => (
<button title="Add comment" style="{styles.button}">
)}
keyExtractor={extractId} />
)
}
}
const enhance = withObservables(['post'], ({ post }) => ({
post: post.observe(),
comments: post.comments.observe(),
}))
export default enhance(Post)
</button>
const BlogList = ({ blogs, setActiveItem, activeItem, showPostList }) => (
<div>
{blogs.map(blog => (
))}
{!blogs.length && <span>Click “Generate x records” above!</span>}
</div>
)
const enhance = compose(
withObservables(['search'], ({ database, search }) => ({
blogs: database.collections
.get('blogs')
.query(Q.where('name', Q.like(`%${Q.sanitizeLikeString(search)}%`))),
})),
withStateHandlers(
{
activeItem: null,
},
{
setActiveItem: () => (e, postId) => {
return {
activeItem: postId,
}
},
},
),
)
const BlogItem = withObservables(['blog'], ({ blog }) => ({
blog: blog.observe(),
}))(RawBlogItem)
const BlogList = ({ blogs, navigation }) => (
)
const enhance = withObservables([], ({ database }) => ({
blogs: database.collections
.get('blogs')
.query()
.observe(),
}))
export default enhance(BlogList)
const renderComment = ({ item }) =>
const ModerationQueue = ({ blog, nastyComments }) => (
(
<>
)}
data={nastyComments}
renderItem={renderComment}
keyExtractor={extractId} />
)
const enhance = withObservables(['blog'], ({ blog }) => ({
blog: blog.observe(),
nastyComments: blog.nastyComments.observe(),
}))
export default enhance(ModerationQueue)
<button title="Add comment">
)
}
const enhance = compose(
withPropsOnChange(['match'], ({ match }) => ({
postId: match.params.postId,
})),
withObservables(['postId'], ({ postId, database }) => ({
post: database.collections.get('posts').findAndObserve(postId),
})),
withObservables(['post'], ({ post }) => ({
comments: post.comments.observe(),
})),
withHandlers({
addComment: props => async () => {
const comment = prompt('Write a comment')
await props.post.addComment(comment)
},
}),
)
export default withDatabase(enhance(Post))
</button>
key={post.id}
to={`/blog/${blog.id}/post/${post.id}`}
isActive={post.id === activeItem}
onClick={setActiveItem}
showMain={showMain}
/>
))}
)
}
const enhance = compose(
withPropsOnChange(['match'], ({ match }) => ({
blogId: match.params.blogId,
})),
withObservables(['id'], ({ blogId, database }) => ({
blog: database.collections.get('blogs').findAndObserve(blogId),
})),
withObservables(['blog'], ({ blog }) => ({
posts: blog.posts.observe(),
})),
withStateHandlers(
{
activeItem: null,
},
{
setActiveItem: () => (e, postId) => ({
activeItem: postId,
}),
},
),
withHandlers({
<span>Nasty comments ({nastyComments.length})</span>
{nastyComments.map(comment => (
))}
)
const enhance = compose(
withPropsOnChange(['match'], ({ match }) => ({
blogId: match.params.blogId,
})),
withObservables(['id'], ({ blogId, database }) => ({
blog: database.collections.get('blogs').findAndObserve(blogId),
})),
withObservables(['blog'], ({ blog }) => ({
nastyComments: blog.nastyComments.observe(),
})),
)
export default withDatabase(enhance(ModerationQueue))