Skip to content

Commit

Permalink
[FEATURE] add sticky comment support (#509)
Browse files Browse the repository at this point in the history
* feat: add mark sticky button

* feat: add sticky field for sql storage

* feat: comment list sort by sticky

* feat(client): support sticky badge

* refactor(vercel): export sticky field and refactor sticky sort logic

Co-authored-by: Mr.Hope <zhangbowang1998@gmail.com>
  • Loading branch information
lizheming and Mister-Hope committed Sep 21, 2021
1 parent 4e1fc7e commit e4225d3
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/waline.pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE wl_comment (
nick varchar(255) DEFAULT NULL,
pid int DEFAULT NULL,
rid int DEFAULT NULL,
sticky int DEFAULT NULL,
status varchar(50) NOT NULL DEFAULT '',
ua text,
url varchar(255) DEFAULT NULL,
Expand Down
1 change: 1 addition & 0 deletions assets/waline.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CREATE TABLE `wl_Comment` (
`nick` varchar(255) DEFAULT NULL,
`pid` int(11) DEFAULT NULL,
`rid` int(11) DEFAULT NULL,
`sticky` int(11) DEFAULT NULL,
`status` varchar(50) NOT NULL DEFAULT '',
`ua` text,
`url` varchar(255) DEFAULT NULL,
Expand Down
Binary file modified assets/waline.sqlite
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/admin/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"waiting": "Waiting",
"spam": "Spam",
"mark as spam": "Mark as Spam",
"disable sticky": "Disable sticky",
"sticky": "Sticky",
"edit": "Edit",
"reply": "Reply",
"delete": "Delete",
Expand Down
2 changes: 2 additions & 0 deletions packages/admin/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"waiting": "待审核",
"spam": "垃圾",
"mark as spam": "标记垃圾",
"disable sticky": "取消置顶",
"sticky": "置顶评论",
"edit": "编辑",
"reply": "回复",
"delete": "删除",
Expand Down
2 changes: 2 additions & 0 deletions packages/admin/src/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"waiting": "待審核",
"spam": "垃圾",
"mark as spam": "標記垃圾",
"disable sticky": "取消置頂",
"sticky": "置頂評論",
"edit": "編輯",
"reply": "回覆",
"delete": "刪除",
Expand Down
19 changes: 19 additions & 0 deletions packages/admin/src/pages/manage-comments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ export default function () {
}
},
},
{
key: 'sticky',
show: comment && !comment.rid && comment.status === 'approved',
name: comment && comment.sticky ? t('disable sticky') : t('sticky'),
async action(e) {
e.preventDefault();

const sticky = !comment.sticky;
list.data.forEach((cmt) => {
if (cmt.objectId === comment.objectId) {
cmt.sticky = sticky;
}
});
await updateComment(comment.objectId, { sticky });
setList({ ...list });
},
},
{
key: 'edit',
show: comment,
Expand Down Expand Up @@ -387,6 +404,7 @@ export default function () {
status,
rid,
pid,
sticky,
insertedAt,
},
idx
Expand Down Expand Up @@ -608,6 +626,7 @@ export default function () {
status,
rid,
pid,
sticky,
}).map(({ key, disable, name, action }) =>
disable ? (
<span className="weak" key={key}>
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/components/CommentCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
v-text="locale.admin"
/>

<span v-if="comment.sticky" class="vbadge" v-text="locale.sticky" />

<span class="vtime" v-text="timeAgo(comment.insertedAt, locale)" />

<button
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/config/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const enLocale: Locale = {
login: 'Login',
logout: 'logout',
admin: 'Admin',
sticky: 'Sticky',
word: 'Words',
wordHint:
'Please input comments between $0 and $1 words!\n Current word number: $2',
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/config/i18n/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const jpLocale: Locale = {
login: 'ログインする',
logout: 'ログアウト',
admin: '管理者',
sticky: 'トップに置く',
word: 'ワード',
wordHint:
'コメントは $0 から $1 ワードの間でなければなりません!\n 現在の単語番号: $2',
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/config/i18n/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Locale {
login: string;
logout: string;
admin: string;
sticky: string;
word: string;
wordHint: string;
}
1 change: 1 addition & 0 deletions packages/client/src/config/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const zhCNLocale: Locale = {
login: '登录',
logout: '退出',
admin: '博主',
sticky: '置顶',
word: '字',
wordHint: '评论字数应在 $0 到 $1 字之间!\n当前字数:$2',
};
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/config/i18n/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const zhTWLocale: Locale = {
login: '登錄',
logout: '退出',
admin: '博主',
sticky: '置頂',
word: '字',
wordHint: '評論字數應在 $0 到 $1 字之間!\n當前字數:$2',
};
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface Comment extends Exclude<CommentData, 'ua'> {
updateAt: string;
objectId: string;
children?: Comment[];
sticky?: boolean;
}
8 changes: 5 additions & 3 deletions packages/server/src/controller/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ module.exports = class extends BaseRest {
'rid',
'ua',
'user_id',
'sticky',
],
}
);
Expand All @@ -193,9 +194,10 @@ module.exports = class extends BaseRest {

const rootCount = comments.filter(({ rid }) => !rid).length;
const pageOffset = Math.max((page - 1) * pageSize, 0);
const rootComments = comments
.filter(({ rid }) => !rid)
.slice(pageOffset, pageOffset + pageSize);
const rootComments = [
...comments.filter(({ rid, sticky }) => !rid && sticky),
...comments.filter(({ rid, sticky }) => !rid && !sticky),
].slice(pageOffset, pageOffset + pageSize);

return this.json({
page,
Expand Down

0 comments on commit e4225d3

Please sign in to comment.