mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
fetch uploadPolicy
This commit is contained in:
parent
b05f5276ee
commit
55059c7259
@ -1,8 +1,10 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import * as antd from "antd"
|
import * as antd from "antd"
|
||||||
import { Icons } from "components/Icons"
|
|
||||||
import { User } from "models"
|
|
||||||
import classnames from "classnames"
|
import classnames from "classnames"
|
||||||
|
|
||||||
|
import { User } from "models"
|
||||||
|
|
||||||
|
import { Icons } from "components/Icons"
|
||||||
import { PostAdditions } from "components/PostCard"
|
import { PostAdditions } from "components/PostCard"
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
@ -15,17 +17,19 @@ export default (props) => {
|
|||||||
const api = window.app.api.withEndpoints("main")
|
const api = window.app.api.withEndpoints("main")
|
||||||
|
|
||||||
const additionsRef = React.useRef(null)
|
const additionsRef = React.useRef(null)
|
||||||
|
|
||||||
const [pending, setPending] = React.useState([])
|
const [pending, setPending] = React.useState([])
|
||||||
const [loading, setLoading] = React.useState(false)
|
const [loading, setLoading] = React.useState(false)
|
||||||
const [uploaderVisible, setUploaderVisible] = React.useState(false)
|
const [uploaderVisible, setUploaderVisible] = React.useState(false)
|
||||||
const [focused, setFocused] = React.useState(false)
|
const [focused, setFocused] = React.useState(false)
|
||||||
|
|
||||||
const [userData, setUserData] = React.useState(null)
|
|
||||||
const [postData, setPostData] = React.useState({
|
const [postData, setPostData] = React.useState({
|
||||||
message: "",
|
message: "",
|
||||||
additions: []
|
additions: []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [uploadPolicy, setUploadPolicy] = React.useState(null)
|
||||||
|
|
||||||
const updatePostData = (update) => {
|
const updatePostData = (update) => {
|
||||||
setPostData({
|
setPostData({
|
||||||
...postData,
|
...postData,
|
||||||
@ -65,6 +69,16 @@ export default (props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchUploadPolicy = () => {
|
||||||
|
const policy = api.upload.policy().catch(error => {
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
if (policy) {
|
||||||
|
setUploadPolicy(policy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onUploadFile = async (req) => {
|
const onUploadFile = async (req) => {
|
||||||
// hide uploader
|
// hide uploader
|
||||||
setUploaderVisible(false)
|
setUploaderVisible(false)
|
||||||
@ -97,6 +111,12 @@ export default (props) => {
|
|||||||
return Boolean(messageLengthValid) && Boolean(pending.length === 0)
|
return Boolean(messageLengthValid) && Boolean(pending.length === 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removeAddition = (file_uid) => {
|
||||||
|
updatePostData({
|
||||||
|
additions: postData.additions.filter(addition => addition.file.uid !== file_uid)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const onDraggerChange = (change) => {
|
const onDraggerChange = (change) => {
|
||||||
console.log(change)
|
console.log(change)
|
||||||
|
|
||||||
@ -108,6 +128,8 @@ export default (props) => {
|
|||||||
case "done": {
|
case "done": {
|
||||||
let additions = postData.additions ?? []
|
let additions = postData.additions ?? []
|
||||||
|
|
||||||
|
console.log(change.file)
|
||||||
|
|
||||||
additions.push(...change.file.response)
|
additions.push(...change.file.response)
|
||||||
|
|
||||||
// remove pending file
|
// remove pending file
|
||||||
@ -123,7 +145,10 @@ export default (props) => {
|
|||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case "error": {
|
||||||
|
// remove pending file
|
||||||
|
setPending(pending.filter(uid => uid !== change.file.uid))
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -155,14 +180,11 @@ export default (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
User.data().then(user => {
|
fetchUploadPolicy()
|
||||||
setUserData(user)
|
|
||||||
})
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// set loading to true menwhile pending is not empty
|
// set loading to true menwhile pending is not empty
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
console.log(pending)
|
|
||||||
setLoading(pending.length !== 0)
|
setLoading(pending.length !== 0)
|
||||||
}, [pending])
|
}, [pending])
|
||||||
|
|
||||||
@ -185,7 +207,7 @@ export default (props) => {
|
|||||||
>
|
>
|
||||||
<div className="textInput">
|
<div className="textInput">
|
||||||
<div className="avatar">
|
<div className="avatar">
|
||||||
<img src={userData?.avatar} />
|
<img src={app.userData?.avatar} />
|
||||||
</div>
|
</div>
|
||||||
<antd.Input.TextArea
|
<antd.Input.TextArea
|
||||||
placeholder="What are you thinking?"
|
placeholder="What are you thinking?"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user