Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create commenting components #379

Merged
merged 29 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c071b6c
Create comments route
zarathustra323 Mar 9, 2020
1b4a56b
Create comment stream component
zarathustra323 Mar 9, 2020
31b05b2
Add login form to comment stream
zarathustra323 Mar 9, 2020
75fc80b
Show/hide login form
zarathustra323 Mar 10, 2020
85d96b6
Create post component
zarathustra323 Mar 10, 2020
76052d9
Display stream posts
zarathustra323 Mar 10, 2020
bf7adcd
Add moment
zarathustra323 Mar 10, 2020
57ece14
Format posted date
zarathustra323 Mar 10, 2020
be17a81
Add no comments message
zarathustra323 Mar 10, 2020
7c0ec65
Stringify stream identifiers
zarathustra323 Mar 10, 2020
bc6da55
Add displayName to active user frag
zarathustra323 Mar 10, 2020
b7113a0
Create comment body and display name fields
zarathustra323 Mar 10, 2020
304a179
Create comment create component
zarathustra323 Mar 10, 2020
9ffcb75
Display comment create form when logged-in
zarathustra323 Mar 10, 2020
8176fa8
Handle unapproved comments
zarathustra323 Mar 10, 2020
7ddd6d2
Handle comment submit with stream data
zarathustra323 Mar 10, 2020
3a6b5a4
Display three rows for comment bodty
zarathustra323 Mar 10, 2020
bf1768b
Create comment post route
zarathustra323 Mar 10, 2020
9e4af83
Handle loading more comments
zarathustra323 Mar 10, 2020
b43b0de
Support custom redirect
zarathustra323 Mar 11, 2020
ea755b7
Display when a comment has been flagged
zarathustra323 Mar 11, 2020
cc9c594
Add ability to flag/report comments
zarathustra323 Mar 12, 2020
a2e3567
Adjust report title
zarathustra323 Mar 12, 2020
b4b5602
Clear comment body on submit
zarathustra323 Mar 12, 2020
60763b1
Ensure display name updates properly
zarathustra323 Mar 12, 2020
63f2cbf
Style comments
zarathustra323 Mar 12, 2020
574eee5
Display comments on content pages
zarathustra323 Mar 12, 2020
5070600
Display error messages on comment create
zarathustra323 Mar 13, 2020
5355fa1
Handle archived streams
zarathustra323 Mar 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/marko-web-identity-x/api/fragments/active-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fragment ActiveUserFragment on AppUser {
email
givenName
familyName
displayName
organization
organizationTitle
countryCode
Expand Down
100 changes: 100 additions & 0 deletions packages/marko-web-identity-x/browser/comments/create.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<template>
<form :class="blockName" @submit.prevent="handleSubmit">
<fieldset :disabled="isLoading">
<display-name v-model="currentDisplayName" label="Posting As" />
<comment-body v-model="body" />
<button
type="submit"
class="btn btn-primary"
>
Submit
</button>
</fieldset>
<p v-if="error" class="mb-0 mt-3">
Error: {{ error.message }}
</p>
</form>
</template>

<script>
import post from '../utils/post';
import FormError from '../errors/form';
import DisplayName from '../form/fields/display-name.vue';
import CommentBody from '../form/fields/comment-body.vue';

export default {
/**
*
*/
components: { DisplayName, CommentBody },

/**
*
*/
props: {
stream: {
type: Object,
required: true,
},

displayName: {
type: String,
required: true,
},
},

/**
*
*/
data: () => ({
blockName: 'idx-create-comment',
isLoading: false,
error: null,
body: '',
updatedDisplayName: undefined,
}),

computed: {
/**
*
*/
currentDisplayName: {
get() {
return this.updatedDisplayName || this.displayName;
},
set(displayName) {
this.updatedDisplayName = displayName;
},
},
},

/**
*
*/
methods: {
/**
*
*/
async handleSubmit() {
this.error = null;
this.isLoading = true;
const { currentDisplayName, body, stream } = this;
try {
const res = await post('/comment', {
displayName: currentDisplayName,
body,
stream,
});
const data = await res.json();
if (!res.ok) throw new FormError(data.message, res.status);
this.body = '';
this.$emit('complete');
} catch (e) {
this.error = e;
} finally {
this.isLoading = false;
}
},
},
};
</script>
134 changes: 134 additions & 0 deletions packages/marko-web-identity-x/browser/comments/post.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<template>
<div :class="blockName" :data-id="id">
<div :class="element('header')">
<div :class="element('display-name')">
<span>Posted by {{ displayName }}</span>
<span v-if="!approved">(pending moderation)</span>
</div>
<div>
<span :class="element('created-at')">
{{ postedAt }}
</span>
<span v-if="hasActiveUser && !flagged">
<a
href="#report-post"
title="Report post as inappropriate."
@click.prevent="reportComment"
>
Report
</a>
</span>
</div>
</div>
<div :class="element('body')">
<p v-if="flagged" :class="element('flagged')">
This comment has been reported.
</p>
{{ body }}
</div>
</div>
</template>

<script>
import moment from 'moment';
import post from '../utils/post';
import FormError from '../errors/form';

export default {
/**
*
*/
props: {
id: {
type: String,
required: true,
},
body: {
type: String,
required: true,
},
displayName: {
type: String,
required: true,
},
createdAt: {
type: Number,
required: true,
},
approved: {
type: Boolean,
default: true,
},
flagged: {
type: Boolean,
default: false,
},
dateFormat: {
type: String,
default: 'MMM Do, YYYY h:mma',
},
activeUser: {
type: Object,
default: () => {},
},
},

/**
*
*/
data: () => ({
blockName: 'idx-comment-post',
isReporting: false,
error: null,
}),

/**
*
*/
computed: {
/**
*
*/
postedAt() {
const { createdAt } = this;
if (!createdAt) return null;
return moment(createdAt).format(this.dateFormat);
},

/**
*
*/
hasActiveUser() {
return this.activeUser && this.activeUser.email;
},
},

/**
*
*/
methods: {
/**
*
*/
element(name) {
return `${this.blockName}__${name}`;
},

async reportComment() {
if (this.isReporting) return;
this.error = null;
this.isReporting = true;
try {
const res = await post(`/comment/flag/${this.id}`);
const data = await res.json();
if (!res.ok) throw new FormError(data.message, res.status);
this.$emit('reported');
} catch (e) {
this.error = e;
} finally {
this.isReporting = false;
}
},
},
};
</script>