mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 13:09:17 +00:00
render placeholder when processing assets
This commit is contained in:
parent
6f4fb0f331
commit
e64490f994
@ -1,4 +1,5 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
|
import { Skeleton } from 'antd';
|
||||||
import { CarouselWrapper } from './Carousel.styled';
|
import { CarouselWrapper } from './Carousel.styled';
|
||||||
import { RightOutlined, LeftOutlined, CloseOutlined } from '@ant-design/icons';
|
import { RightOutlined, LeftOutlined, CloseOutlined } from '@ant-design/icons';
|
||||||
import ReactResizeDetector from 'react-resize-detector';
|
import ReactResizeDetector from 'react-resize-detector';
|
||||||
@ -6,7 +7,7 @@ import ReactResizeDetector from 'react-resize-detector';
|
|||||||
import login from '../login.png';
|
import login from '../login.png';
|
||||||
import test from '../test.png';
|
import test from '../test.png';
|
||||||
|
|
||||||
export function Carousel({ items, itemRenderer, itemRemove }) {
|
export function Carousel({ ready, items, itemRenderer, itemRemove }) {
|
||||||
const [slots, setSlots] = useState([]);
|
const [slots, setSlots] = useState([]);
|
||||||
const [carouselRef, setCarouselRef] = useState(false);
|
const [carouselRef, setCarouselRef] = useState(false);
|
||||||
const [itemIndex, setItemIndex] = useState(0);
|
const [itemIndex, setItemIndex] = useState(0);
|
||||||
@ -81,37 +82,39 @@ export function Carousel({ items, itemRenderer, itemRemove }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let assets = [];
|
let assets = [];
|
||||||
for (let i = 0; i < items.length; i++) {
|
if (ready) {
|
||||||
assets.push((
|
for (let i = 0; i < items.length; i++) {
|
||||||
<ReactResizeDetector handleWidth={true} handleHeight={false}>
|
assets.push((
|
||||||
{({ width, height }) => {
|
<ReactResizeDetector handleWidth={true} handleHeight={false}>
|
||||||
itemWidth.current.set(i, width);
|
{({ width, height }) => {
|
||||||
return (
|
itemWidth.current.set(i, width);
|
||||||
<div class="item noselect">
|
return (
|
||||||
<div class="asset">{ itemRenderer(items[i]) }</div>
|
<div class="item noselect">
|
||||||
<RemoveItem index={i} />
|
<div class="asset">{ itemRenderer(items[i]) }</div>
|
||||||
</div>
|
<RemoveItem index={i} />
|
||||||
);
|
</div>
|
||||||
}}
|
);
|
||||||
</ReactResizeDetector>
|
}}
|
||||||
));
|
</ReactResizeDetector>
|
||||||
}
|
));
|
||||||
if (items.length > 0) {
|
|
||||||
assets.push(<div class="space"> </div>)
|
|
||||||
}
|
|
||||||
if (itemIndex >= items.length) {
|
|
||||||
if (items.length > 0) {
|
|
||||||
setItemIndex(items.length - 1);
|
|
||||||
}
|
}
|
||||||
else {
|
if (items.length > 0) {
|
||||||
setItemIndex(0);
|
assets.push(<div class="space"> </div>)
|
||||||
|
}
|
||||||
|
if (itemIndex >= items.length) {
|
||||||
|
if (items.length > 0) {
|
||||||
|
setItemIndex(items.length - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setItemIndex(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setSlots(assets);
|
setSlots(assets);
|
||||||
setScroll();
|
setScroll();
|
||||||
setArrows();
|
setArrows();
|
||||||
}, [items]);
|
}, [ready, items]);
|
||||||
|
|
||||||
const onRefSet = (r) => {
|
const onRefSet = (r) => {
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
@ -120,6 +123,20 @@ export function Carousel({ items, itemRenderer, itemRemove }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ready) {
|
||||||
|
return (
|
||||||
|
<CarouselWrapper>
|
||||||
|
<div class="carousel">
|
||||||
|
<Skeleton.Image style={{ height: 128 }} />
|
||||||
|
</div>
|
||||||
|
<div class="arrows">
|
||||||
|
<div class="arrow" onClick={onRight}><RightOutlined style={{ visibility: scrollRight }} /></div>
|
||||||
|
<div class="arrow" onClick={onLeft}><LeftOutlined style={{ visibility: scrollLeft }} /></div>
|
||||||
|
</div>
|
||||||
|
</CarouselWrapper>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (slots.length != 0) {
|
if (slots.length != 0) {
|
||||||
return (
|
return (
|
||||||
<CarouselWrapper>
|
<CarouselWrapper>
|
||||||
|
@ -85,7 +85,7 @@ export function AddTopic() {
|
|||||||
<AddTopicWrapper>
|
<AddTopicWrapper>
|
||||||
<div class="container noselect">
|
<div class="container noselect">
|
||||||
<div class="carousel">
|
<div class="carousel">
|
||||||
<Carousel items={state.assets} itemRenderer={renderItem} itemRemove={removeItem} />
|
<Carousel ready={true} items={state.assets} itemRenderer={renderItem} itemRemove={removeItem} />
|
||||||
</div>
|
</div>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<Input.TextArea placeholder="Message" autoSize={{ minRows: 2, maxRows: 6 }} onKeyPress={onKey}
|
<Input.TextArea placeholder="Message" autoSize={{ minRows: 2, maxRows: 6 }} onKeyPress={onKey}
|
||||||
|
@ -35,7 +35,7 @@ export function TopicItem({ topic }) {
|
|||||||
<CommentOutlined />
|
<CommentOutlined />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Carousel items={state.assets} itemRenderer={renderAsset} />
|
<Carousel ready={state.ready} items={state.assets} itemRenderer={renderAsset} />
|
||||||
<div class="message">{ state.message?.text }</div>
|
<div class="message">{ state.message?.text }</div>
|
||||||
</div>
|
</div>
|
||||||
</TopicItemWrapper>
|
</TopicItemWrapper>
|
||||||
|
@ -13,8 +13,7 @@ export function useTopicItem(topic) {
|
|||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
message: null,
|
message: null,
|
||||||
created: null,
|
created: null,
|
||||||
status: null,
|
ready: false,
|
||||||
transform: null,
|
|
||||||
assets: [],
|
assets: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,17 +27,24 @@ export function useTopicItem(topic) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
|
if (!topic?.data) {
|
||||||
|
console.log("invalid topic:", topic);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { status, transform, data } = topic.data.topicDetail;
|
const { status, transform, data } = topic.data.topicDetail;
|
||||||
let message;
|
let message;
|
||||||
|
let ready = false;
|
||||||
let assets = [];
|
let assets = [];
|
||||||
if (status === 'confirmed') {
|
if (status === 'confirmed') {
|
||||||
try {
|
try {
|
||||||
message = JSON.parse(data);
|
message = JSON.parse(data);
|
||||||
|
if (message.assets) {
|
||||||
|
assets = message.assets;
|
||||||
|
delete message.assets;
|
||||||
|
}
|
||||||
if (transform === 'complete') {
|
if (transform === 'complete') {
|
||||||
if (message.assets) {
|
ready = true;
|
||||||
assets = message.assets;
|
|
||||||
delete message.assets;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
@ -50,11 +56,11 @@ export function useTopicItem(topic) {
|
|||||||
const { guid, created } = topic.data.topicDetail;
|
const { guid, created } = topic.data.topicDetail;
|
||||||
if (profile.state.profile.guid == guid) {
|
if (profile.state.profile.guid == guid) {
|
||||||
const { name, handle, imageUrl } = profile.actions.getProfile();
|
const { name, handle, imageUrl } = profile.actions.getProfile();
|
||||||
updateState({ name, handle, imageUrl, status, message, transform, assets, created });
|
updateState({ name, handle, imageUrl, status, message, transform, assets, ready, created });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const { name, handle, imageUrl } = card.actions.getCardProfileByGuid(guid);
|
const { name, handle, imageUrl } = card.actions.getCardProfileByGuid(guid);
|
||||||
updateState({ name, handle, imageUrl, status, message, transform, assets, created });
|
updateState({ name, handle, imageUrl, status, message, transform, assets, ready, created });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [profile, card, conversation, topic]);
|
}, [profile, card, conversation, topic]);
|
||||||
|
Loading…
Reference in New Issue
Block a user