From c1ced9e4c1bb419743304f45c4b9387b54844336 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Wed, 2 Mar 2022 16:07:11 +0100 Subject: [PATCH] added `PostCreator` --- .../app/src/components/PostCreator/index.jsx | 98 +++++++++++++++++++ .../app/src/components/PostCreator/index.less | 77 +++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 packages/app/src/components/PostCreator/index.jsx create mode 100644 packages/app/src/components/PostCreator/index.less diff --git a/packages/app/src/components/PostCreator/index.jsx b/packages/app/src/components/PostCreator/index.jsx new file mode 100644 index 00000000..679e3a05 --- /dev/null +++ b/packages/app/src/components/PostCreator/index.jsx @@ -0,0 +1,98 @@ +import React from "react" +import * as antd from "antd" +import { Icons } from "components/Icons" +import { User } from "models" +import classnames from "classnames" + +import "./index.less" + +const maxMessageLength = 512 + +const PostCreatorInput = (props) => { + const [value, setValue] = React.useState("") + + const canPublish = () => { + return value.length !== 0 && value.length < maxMessageLength + } + + const onChange = (e) => { + setValue(e.target.value) + } + + const handleSubmit = () => { + if (canPublish()) { + if (typeof props.onSubmit === "function") { + props.onSubmit(value) + } + + setValue("") + } + } + + return
+
+ +
+ +
+ : } + /> +
+
+} + +export default class PostCreator extends React.Component { + state = { + loading: false, + } + api = window.app.request + + componentDidMount = async () => { + const userData = await User.data() + + this.setState({ + userData + }) + } + + onSubmit = async (value) => { + await this.setState({ loading: true }) + + const result = this.api.put.post({ + message: value, + }).catch(error => { + console.error(error) + antd.message.error(error) + + return false + }) + + this.setState({ loading: false }) + } + + render() { + return
+ +
+ } +} \ No newline at end of file diff --git a/packages/app/src/components/PostCreator/index.less b/packages/app/src/components/PostCreator/index.less new file mode 100644 index 00000000..0791e555 --- /dev/null +++ b/packages/app/src/components/PostCreator/index.less @@ -0,0 +1,77 @@ +.postCreator { + width : fit-content; + min-width : 35vw; + padding : 15px; + background-color: var(--background-color-accent); + + border-radius: 7px; + + .textInput { + display : flex; + width : 100%; + transition : height 150ms ease-in-out; + background-color: var(--background-color-accent); + + svg { + margin: 0 !important; + } + + .avatar { + width : fit-content; + height: 45px; + + display: flex; + + img { + width : 45px; + height : 45px; + border-radius: 12px; + } + } + + .textArea { + border-radius: 8px!important; + transition: all 150ms ease-in-out!important; + + &.active { + background-color: var(--background-color-primary); + } + } + + .ant-btn-primary { + z-index : 10; + position : relative; + border-radius : 0 10px 10px 0; + height : 100%; + vertical-align: bottom; + border : none; + box-shadow : none; + } + + .ant-input { + background-color: var(--background-color-accent); + + z-index : 10; + position : relative; + border-color : transparent !important; + box-shadow : none; + border-radius: 3px 0 0; + height : 100%; + padding : 5px 10px; + transition : height 150ms linear; + width : 100%; + } + + .ant-btn-primary[disabled] { + background-color: var(--background-color-accent); + } + + .ant-input:hover { + border-color: #1890ff; + } + + .ant-input-affix-wrapper { + height: 100%; + } + } +} \ No newline at end of file