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

feat(discussion): show admin label #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/api-generated/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,9 @@ declare namespace ApiTypes {
bio: string;
avatar: ApiTypes.UserAvatarDto;
isAdmin: boolean;
isProblemAdmin: boolean;
isContestAdmin: boolean;
isDiscussionAdmin: boolean;
acceptedProblemCount: number;
submissionCount: number;
rating: number;
Expand Down
5 changes: 4 additions & 1 deletion src/locales/messages/en-US/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ return {
label: {
nonpublic: "Nonpublic",
problem_owner: "Problem owner",
discussion_publisher: "Initiator"
discussion_publisher: "Initiator",
admin: "Site admin",
problem_admin: "Problem admin",
discussion_admin: "Discussion admin"
},
actions: {
edit: "Edit",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/messages/ja-JP/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ return {
label: {
nonpublic: "[TBT] Nonpublic",
problem_owner: "[TBT] Problem owner",
discussion_publisher: "[TBT] Initiator"
discussion_publisher: "[TBT] Initiator",
admin: "[TBT] Site admin",
problem_admin: "[TBT] Problem admin",
discussion_admin: "[TBT] Discussion admin"
},
actions: {
edit: "[TBT] Edit",
Expand Down
5 changes: 4 additions & 1 deletion src/locales/messages/zh-CN/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ return {
label: {
nonpublic: "未公开",
problem_owner: "题目上传者",
discussion_publisher: "讨论发起者"
discussion_publisher: "讨论发起者",
admin: "站点管理员",
problem_admin: "题目管理员",
discussion_admin: "讨论管理员"
},
actions: {
edit: "编辑",
Expand Down
27 changes: 18 additions & 9 deletions src/pages/discussion/view/DiscussionViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,22 @@ let DiscussionItem: React.FC<DiscussionItemProps> = props => {
.filter(e => e)
.map((e, i) => <React.Fragment key={i}>{e}</React.Fragment>);

const label = !props.isPublic ? (
<Label className={style.label} icon="eye slash" color="red" content={_(".label.nonpublic")} basic />
) : props.publisher.id === props.discussion.problem?.meta?.ownerId ? (
<Label className={style.label} content={_(".label.problem_owner")} basic />
) : props.publisher.id === props.discussion.publisher.id && props.type === "Reply" ? (
<Label className={style.label} content={_(".label.discussion_publisher")} basic />
) : null;
const labels = [
!props.isPublic && (
<Label className={style.label} icon="eye slash" color="red" content={_(".label.nonpublic")} basic />
),
props.publisher.id === props.discussion.problem?.meta?.ownerId && (
<Label className={style.label} content={_(".label.problem_owner")} basic />
),
props.publisher.id === props.discussion.publisher.id && props.type === "Reply" && (
<Label className={style.label} content={_(".label.discussion_publisher")} basic />
),
props.publisher.isAdmin && <Label className={style.label} content={_(".label.admin")} basic />,
props.publisher.isProblemAdmin && props.discussion.problem && (
<Label className={style.label} content={_(".label.problem_admin")} basic />
),
props.publisher.isDiscussionAdmin && <Label className={style.label} content={_(".label.discussion_admin")} basic />
].filter(Boolean);

return (
<div
Expand Down Expand Up @@ -348,10 +357,10 @@ let DiscussionItem: React.FC<DiscussionItemProps> = props => {
</>
)}
</span>
{label && (
{labels.length && (
<>
<div className={style.labelDivider} />
{label}
{labels}
</>
)}
</div>
Expand Down