Skip to content

Commit

Permalink
Website
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Mar 3, 2024
1 parent 3df8a26 commit 9d6f374
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
15 changes: 12 additions & 3 deletions packages/comment-widget/src/base-comment-item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LitElement, html, css } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import './user-avatar';
import { timeAgo } from './utils/date';
import { formatDate, timeAgo } from './utils/date';
import baseStyles from './styles/base';
import varStyles from './styles/var';

Expand All @@ -13,6 +13,9 @@ export class BaseCommentItem extends LitElement {
@property({ type: String })
userDisplayName: string | undefined;

@property({ type: String })
userWebsite: string | undefined;

@property({ type: String })
creationTime: string | undefined;

Expand All @@ -35,8 +38,14 @@ export class BaseCommentItem extends LitElement {
</div>
<div class="item__main">
<div class="item__meta">
<div class="item__author">${this.userDisplayName}</div>
<div class="item__meta-info">${timeAgo(this.creationTime)}</div>
${this.userWebsite
? html`<a class="item__author" target="_blank" href=${this.userWebsite}>
${this.userDisplayName}
</a>`
: html`<div class="item__author">${this.userDisplayName}</div>`}
<div class="item__meta-info" title=${formatDate(this.creationTime)}>
${timeAgo(this.creationTime)}
</div>
${!this.approved ? html`<div class="item__meta-info">审核中</div>` : ''}
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/comment-widget/src/comment-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class CommentItem extends LitElement {
.content="${this.comment?.spec.content || ''}"
.creationTime="${this.comment?.spec.creationTime}"
.approved=${this.comment?.spec.approved}
.userWebsite=${this.comment?.spec.owner.annotations?.['website']}
>
<base-comment-item-action
slot="action"
Expand Down
8 changes: 6 additions & 2 deletions packages/comment-widget/src/comment-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class CommentWidget extends LitElement {

override render() {
return html`<div class="comment-widget">
<comment-form @reload="${this.fetchComments}"></comment-form>
<comment-form @reload="${() => this.fetchComments(1)}"></comment-form>
${this.loading
? html`<loading-block></loading-block>`
: html`
Expand Down Expand Up @@ -130,12 +130,16 @@ export class CommentWidget extends LitElement {
this.currentUser = data.user.metadata.name === 'anonymousUser' ? undefined : data.user;
}

async fetchComments() {
async fetchComments(page?: number) {
try {
if (this.comments.items.length === 0) {
this.loading = true;
}

if (page) {
this.comments.page = page;
}

const queryParams = [
`group=${this.group}`,
`kind=${this.kind}`,
Expand Down
1 change: 1 addition & 0 deletions packages/comment-widget/src/reply-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class ReplyItem extends LitElement {
.creationTime="${this.reply?.metadata.creationTimestamp ?? undefined}"
.approved=${this.reply?.spec.approved}
.breath=${this.isQuoteReplyHovered}
.userWebsite=${this.reply?.spec.owner.annotations?.['website']}
>
<base-comment-item-action
slot="action"
Expand Down

0 comments on commit 9d6f374

Please sign in to comment.