forked from Gitlink/forgeplus-react
feat: issue and jouranl support emoji #1
|
@ -3,10 +3,11 @@ import { Link } from "react-router-dom";
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getImageUrl } from "educoder";
|
import { getImageUrl } from "educoder";
|
||||||
import { Form, Popconfirm, Tag, Spin } from "antd";
|
import { Form, Popconfirm, Tag, Spin, Popover, Icon, Button } from "antd";
|
||||||
import Attachments from "../Upload/attachment";
|
import Attachments from "../Upload/attachment";
|
||||||
import RenderHtml from "../../components/render-html";
|
import RenderHtml from "../../components/render-html";
|
||||||
import Comments from "../comments/comments";
|
import Comments from "../comments/comments";
|
||||||
|
import update from 'immutability-helper'
|
||||||
import "./order.css";
|
import "./order.css";
|
||||||
|
|
||||||
class Detail extends Component {
|
class Detail extends Component {
|
||||||
|
@ -50,6 +51,8 @@ class Detail extends Component {
|
||||||
.get(url)
|
.get(url)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
// todo 增加后台返回
|
||||||
|
result.data.emojiComment = {}
|
||||||
this.setState({
|
this.setState({
|
||||||
data: result.data,
|
data: result.data,
|
||||||
isSpins: false
|
isSpins: false
|
||||||
|
@ -190,7 +193,54 @@ class Detail extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { projectsId, orderId, owner } = this.props.match.params;
|
const { projectsId, orderId, owner } = this.props.match.params;
|
||||||
|
const { current_user } = this.props
|
||||||
const { data, isSpins } = this.state;
|
const { data, isSpins } = this.state;
|
||||||
|
const emojiList = ["😀", "😅"];
|
||||||
|
|
||||||
|
const update_emoji_comment = (emoji) => {
|
||||||
|
// 无emoji评论
|
||||||
|
if (!data.emojiComment || !data.emojiComment[emoji] || data.emojiComment[emoji].users.length == 0) {
|
||||||
|
var emojiComment = data.emojiComment ? data.emojiComment : {}
|
||||||
|
emojiComment[emoji] = {
|
||||||
|
"users": [owner],
|
||||||
|
"total": 1
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
data: update(data, { emojiComment: { $set: emojiComment } })
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 有emoji评论
|
||||||
|
var userList = data.emojiComment[emoji].users
|
||||||
|
var addNewUser = true
|
||||||
|
for (var i = 0; i < userList.length; i++) {
|
||||||
|
if (userList[i] == owner) {
|
||||||
|
userList.splice(i, 1);
|
||||||
|
addNewUser = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (addNewUser) {
|
||||||
|
userList.push(owner)
|
||||||
|
}
|
||||||
|
var emojiComment = data.emojiComment
|
||||||
|
emojiComment[emoji] = {
|
||||||
|
"users": userList,
|
||||||
|
"total": userList.length
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
data: update(data, { emojiComment: { $set: emojiComment } })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const emojiComment = (
|
||||||
|
emojiList.map((emoji) => {
|
||||||
|
return <Button type="link" className="detail_emoji_comment_menu_item"
|
||||||
|
onClick={(e) => update_emoji_comment(emoji)} key={emoji}>{emoji}</Button>
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const get_color = (type) => {
|
const get_color = (type) => {
|
||||||
if (type === "高") {
|
if (type === "高") {
|
||||||
return "#e67e22";
|
return "#e67e22";
|
||||||
|
@ -300,6 +350,35 @@ class Detail extends Component {
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
|
<div className="detail_emoji_comment" >
|
||||||
|
<style>
|
||||||
|
{`
|
||||||
|
.ant-popover-inner-content {
|
||||||
|
padding: 2px 5px;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
{current_user && current_user.login ? (
|
||||||
|
<Popover content={emojiComment} trigger="click">
|
||||||
|
<Button shape="circle"><Icon type="smile" theme="outlined" /></Button>
|
||||||
|
</Popover>
|
||||||
|
) : ("")
|
||||||
|
}
|
||||||
|
{current_user && current_user.login && data && data.emojiComment ? (
|
||||||
|
Object.keys(data.emojiComment).map(key => {
|
||||||
|
const item = data.emojiComment[key]
|
||||||
|
if (item.users.length == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return <Popover className="detail_emoji_pop" content={item.users.join(",")} key={key}>
|
||||||
|
<Button className="detail_emoji_button" shape="round" onClick={(e) => update_emoji_comment(key)}>
|
||||||
|
{key}+{item.total}
|
||||||
|
</Button>
|
||||||
|
</Popover>
|
||||||
|
})
|
||||||
|
) : ("")
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,24 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.detail_emoji_comment {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
.detail_emoji_comment_menu {
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
.detail_emoji_comment_menu_item {
|
||||||
|
padding-left: 0px;
|
||||||
|
padding-right: 0px;
|
||||||
|
}
|
||||||
|
.detail_emoji_pop {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
.detail_emoji_button {
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.detail_right {
|
.detail_right {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|
|
@ -5,11 +5,12 @@ import axios from "axios";
|
||||||
import Upload from "../Upload/Index";
|
import Upload from "../Upload/Index";
|
||||||
import UploadImg from "../Images/upload.png";
|
import UploadImg from "../Images/upload.png";
|
||||||
import { getImageUrl } from "educoder";
|
import { getImageUrl } from "educoder";
|
||||||
import { List, Popconfirm, Pagination, Button, Tabs, Avatar } from "antd";
|
import { List, Popconfirm, Pagination, Button, Tabs, Popover, Icon } from "antd";
|
||||||
import Attachments from "../Upload/attachment";
|
import Attachments from "../Upload/attachment";
|
||||||
import MDEditor from "../../modules/tpm/challengesnew/tpm-md-editor";
|
import MDEditor from "../../modules/tpm/challengesnew/tpm-md-editor";
|
||||||
import RenderHtml from "../../components/render-html";
|
import RenderHtml from "../../components/render-html";
|
||||||
import ChildrenComments from "./children_comments";
|
import ChildrenComments from "./children_comments";
|
||||||
|
import update from 'immutability-helper'
|
||||||
import "../Order/order.css";
|
import "../Order/order.css";
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
class comments extends Component {
|
class comments extends Component {
|
||||||
|
@ -308,6 +309,62 @@ class comments extends Component {
|
||||||
new_journal_id,
|
new_journal_id,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { current_user, only_show_content } = this.props;
|
const { current_user, only_show_content } = this.props;
|
||||||
|
const emojiList = ["😀", "😅"];
|
||||||
|
|
||||||
|
const update_emoji_comment = (item, emoji) => {
|
||||||
|
// 无emoji评论
|
||||||
|
if (!item.emojiComment || !item.emojiComment[emoji] || item.emojiComment[emoji].users.length == 0) {
|
||||||
|
const idx = journalsdata.issue_journals.findIndex(function (journal) {
|
||||||
|
return journal.id == item.id;
|
||||||
|
})
|
||||||
|
var emojiComment = item.emojiComment ? item.emojiComment : {}
|
||||||
|
emojiComment[emoji] = {
|
||||||
|
"users": [current_user.login],
|
||||||
|
"total": 1
|
||||||
|
}
|
||||||
|
var journal = journalsdata.issue_journals[idx]
|
||||||
|
journal.emojiComment = emojiComment
|
||||||
|
this.setState({
|
||||||
|
journalsdata: update(journalsdata, { issue_journals: { [idx]: { $set: journal } } })
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 有emoji评论
|
||||||
|
var userList = item.emojiComment[emoji].users
|
||||||
|
var addNewUser = true
|
||||||
|
for (var i = 0; i < userList.length; i++) {
|
||||||
|
if (userList[i] == current_user.login) {
|
||||||
|
userList.splice(i, 1);
|
||||||
|
addNewUser = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (addNewUser) {
|
||||||
|
userList.push(current_user.login)
|
||||||
|
}
|
||||||
|
|
||||||
|
const idx = journalsdata.issue_journals.findIndex(function (journal) {
|
||||||
|
return journal.id == item.id;
|
||||||
|
})
|
||||||
|
var emojiComment = item.emojiComment
|
||||||
|
emojiComment[emoji] = {
|
||||||
|
"users": userList,
|
||||||
|
"total": userList.length
|
||||||
|
}
|
||||||
|
var journal = journalsdata.issue_journals[idx]
|
||||||
|
journal.emojiComment = emojiComment
|
||||||
|
this.setState({
|
||||||
|
journalsdata: update(journalsdata, { issue_journals: { [idx]: { $set: journal } } })
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
const emojiComment = (item) => {
|
||||||
|
return emojiList.map((emoji) => {
|
||||||
|
return <Button type="link" className="detail_emoji_comment_menu_item"
|
||||||
|
onClick={(e) => update_emoji_comment(item, emoji)} key={emoji}>{emoji}</Button>
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
const new_comment = (is_reply, item_id) => {
|
const new_comment = (is_reply, item_id) => {
|
||||||
return (
|
return (
|
||||||
|
@ -315,7 +372,7 @@ class comments extends Component {
|
||||||
<Link
|
<Link
|
||||||
to={`/${current_user && current_user.login}`}
|
to={`/${current_user && current_user.login}`}
|
||||||
className="show-user-link mr10"
|
className="show-user-link mr10"
|
||||||
>
|
>1
|
||||||
<img
|
<img
|
||||||
className="radius"
|
className="radius"
|
||||||
src={getImageUrl(
|
src={getImageUrl(
|
||||||
|
@ -416,7 +473,29 @@ class comments extends Component {
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
<div className="grid-item mt5">
|
<div className="grid-item mt5">
|
||||||
|
<div>
|
||||||
<span className="color-grey-8">{item.created_at}</span>
|
<span className="color-grey-8">{item.created_at}</span>
|
||||||
|
{current_user && current_user.login ? (
|
||||||
|
<Popover content={emojiComment(item)} trigger="click" className="ml10">
|
||||||
|
<Button shape="circle"><Icon type="smile" theme="outlined" /></Button>
|
||||||
|
</Popover>
|
||||||
|
) : ("")
|
||||||
|
}
|
||||||
|
{current_user && current_user.login && item.emojiComment ? (
|
||||||
|
Object.keys(item.emojiComment).map(key => {
|
||||||
|
const comments = item.emojiComment[key]
|
||||||
|
if (comments.users.length == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return <Popover className="detail_emoji_pop" content={comments.users.join(",")} key={key}>
|
||||||
|
<Button className="detail_emoji_button" shape="round" onClick={(e) => update_emoji_comment(item, key)}>
|
||||||
|
{key}+{comments.total}
|
||||||
|
</Button>
|
||||||
|
</Popover>
|
||||||
|
})
|
||||||
|
) : ("")
|
||||||
|
}
|
||||||
|
</div>
|
||||||
<span className="text-right">
|
<span className="text-right">
|
||||||
{current_user &&
|
{current_user &&
|
||||||
(current_user.admin ||
|
(current_user.admin ||
|
||||||
|
|
Loading…
Reference in New Issue