mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
split PostAdditions
component & new addition model
This commit is contained in:
parent
eec2f03ccb
commit
bef9d7552f
@ -46,7 +46,7 @@ const getMaxHeight = (node) => {
|
|||||||
|
|
||||||
const getCollapsedHeight = () => ({ height: 0, opacity: 0 })
|
const getCollapsedHeight = () => ({ height: 0, opacity: 0 })
|
||||||
|
|
||||||
function PostHeader(props) {
|
export function PostHeader(props) {
|
||||||
const [timeAgo, setTimeAgo] = React.useState(0)
|
const [timeAgo, setTimeAgo] = React.useState(0)
|
||||||
|
|
||||||
const goToProfile = () => {
|
const goToProfile = () => {
|
||||||
@ -107,30 +107,40 @@ function PostHeader(props) {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const PostContent = React.memo((props) => {
|
export const PostAdditions = React.memo((props) => {
|
||||||
let { message, additions } = props.data
|
let { additions } = props
|
||||||
|
|
||||||
let carruselRef = React.useRef(null)
|
let carruselRef = React.useRef(null)
|
||||||
|
|
||||||
// first filter if is an string
|
// fullfil url string additions
|
||||||
additions = additions.filter(file => typeof file === "string")
|
additions = additions.map((addition) => {
|
||||||
|
if (typeof addition === "string") {
|
||||||
|
addition = {
|
||||||
|
url: addition,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// then filter if is an uri
|
return addition
|
||||||
additions = additions.filter(file => /^(http|https):\/\//.test(file))
|
})
|
||||||
|
|
||||||
|
// then filter if has an valid uri
|
||||||
|
additions = additions.filter(addition => /^(http|https):\/\//.test(addition.url))
|
||||||
|
|
||||||
|
additions = additions.map((addition, index) => {
|
||||||
|
const { url, id, name } = addition
|
||||||
|
|
||||||
additions = additions.map((uri, index) => {
|
|
||||||
const MediaRender = loadable(async () => {
|
const MediaRender = loadable(async () => {
|
||||||
let extension = null
|
let extension = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// get media type by parsing the uri
|
// get media type by parsing the url
|
||||||
const mediaTypeExt = /\.([a-zA-Z0-9]+)$/.exec(uri)
|
const mediaTypeExt = /\.([a-zA-Z0-9]+)$/.exec(url)
|
||||||
|
|
||||||
if (mediaTypeExt) {
|
if (mediaTypeExt) {
|
||||||
extension = mediaTypeExt[1]
|
extension = mediaTypeExt[1]
|
||||||
} else {
|
} else {
|
||||||
// try to get media by creating requesting the uri
|
// try to get media by creating requesting the url
|
||||||
const response = await fetch(uri, {
|
const response = await fetch(url, {
|
||||||
method: "HEAD",
|
method: "HEAD",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -148,7 +158,7 @@ const PostContent = React.memo((props) => {
|
|||||||
|
|
||||||
switch (mediaType.split("/")[0]) {
|
switch (mediaType.split("/")[0]) {
|
||||||
case "image": {
|
case "image": {
|
||||||
return () => <img src={uri} />
|
return () => <img src={url} />
|
||||||
}
|
}
|
||||||
case "video": {
|
case "video": {
|
||||||
return () => <video controls>
|
return () => <video controls>
|
||||||
@ -180,6 +190,22 @@ const PostContent = React.memo((props) => {
|
|||||||
</div>
|
</div>
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return <div className="additions">
|
||||||
|
<antd.Carousel
|
||||||
|
ref={carruselRef}
|
||||||
|
arrows={true}
|
||||||
|
nextArrow={<Icons.ChevronRight />}
|
||||||
|
prevArrow={<Icons.ChevronLeft />}
|
||||||
|
autoplay={props.autoCarrousel}
|
||||||
|
>
|
||||||
|
{additions}
|
||||||
|
</antd.Carousel>
|
||||||
|
</div>
|
||||||
|
})
|
||||||
|
|
||||||
|
export const PostContent = React.memo((props) => {
|
||||||
|
let { message, additions } = props.data
|
||||||
|
|
||||||
// parse message
|
// parse message
|
||||||
const regexs = [
|
const regexs = [
|
||||||
{
|
{
|
||||||
@ -203,23 +229,11 @@ const PostContent = React.memo((props) => {
|
|||||||
{message}
|
{message}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{additions.length > 0 &&
|
{additions.length > 0 && <PostAdditions additions={additions} />}
|
||||||
<div className="additions">
|
|
||||||
<antd.Carousel
|
|
||||||
ref={carruselRef}
|
|
||||||
arrows={true}
|
|
||||||
nextArrow={<Icons.ChevronRight />}
|
|
||||||
prevArrow={<Icons.ChevronLeft />}
|
|
||||||
autoplay={props.autoCarrousel}
|
|
||||||
>
|
|
||||||
{additions}
|
|
||||||
</antd.Carousel>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
})
|
})
|
||||||
|
|
||||||
const PostActions = (props) => {
|
export const PostActions = (props) => {
|
||||||
const handleSelfMenuAction = async (event) => {
|
const handleSelfMenuAction = async (event) => {
|
||||||
const fn = props.actions[event.key]
|
const fn = props.actions[event.key]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user