1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

sorting audios on comment attach

This commit is contained in:
Fedor Katurov 2019-11-01 16:38:16 +07:00
parent 6e22481b4d
commit 5a46bef7ca
4 changed files with 53 additions and 14 deletions

View file

@ -22,7 +22,7 @@ const SortableAudioGrid = SortableContainer(
.filter(file => file && file.id) .filter(file => file && file.id)
.map((file, index) => ( .map((file, index) => (
<SortableImageGridItem key={file.id} index={index} collection={0}> <SortableImageGridItem key={file.id} index={index} collection={0}>
<AudioPlayer file={file} onDrop={onDrop} /> <AudioPlayer file={file} onDrop={onDrop} nonInteractive />
</SortableImageGridItem> </SortableImageGridItem>
))} ))}

View file

@ -23,11 +23,13 @@ const mapDispatchToProps = {
type Props = ReturnType<typeof mapStateToProps> & type Props = ReturnType<typeof mapStateToProps> &
typeof mapDispatchToProps & { typeof mapDispatchToProps & {
file: IFile; file: IFile;
nonInteractive?: boolean;
}; };
const AudioPlayerUnconnected = memo( const AudioPlayerUnconnected = memo(
({ ({
file, file,
nonInteractive,
player: { file: current, status }, player: { file: current, status },
playerSetFileAndPlay, playerSetFileAndPlay,
playerPlay, playerPlay,
@ -42,13 +44,15 @@ const AudioPlayerUnconnected = memo(
}); });
const onPlay = useCallback(() => { const onPlay = useCallback(() => {
if (nonInteractive) return;
if (current && current.id === file.id) { if (current && current.id === file.id) {
if (status === PLAYER_STATES.PLAYING) return playerPause(); if (status === PLAYER_STATES.PLAYING) return playerPause();
return playerPlay(); return playerPlay();
} }
playerSetFileAndPlay(file); playerSetFileAndPlay(file);
}, [file, current, status, playerPlay, playerPause, playerSetFileAndPlay]); }, [file, current, status, playerPlay, playerPause, playerSetFileAndPlay, nonInteractive]);
const onProgress = useCallback( const onProgress = useCallback(
({ detail }: { detail: IPlayerProgress }) => { ({ detail }: { detail: IPlayerProgress }) => {

View file

@ -6,6 +6,7 @@
align-items: center; align-items: center;
justify-content: stretch; justify-content: stretch;
flex: 1; flex: 1;
user-select: none;
&:global(.playing) { &:global(.playing) {
.progress { .progress {

View file

@ -24,6 +24,7 @@ import { AudioPlayer } from '~/components/media/AudioPlayer';
import { SortableImageGrid } from '~/components/editors/SortableImageGrid'; import { SortableImageGrid } from '~/components/editors/SortableImageGrid';
import { moveArrItem } from '~/utils/fn'; import { moveArrItem } from '~/utils/fn';
import { SortEnd } from 'react-sortable-hoc'; import { SortEnd } from 'react-sortable-hoc';
import { SortableAudioGrid } from '~/components/editors/SortableAudioGrid';
const mapStateToProps = (state: IState) => ({ const mapStateToProps = (state: IState) => ({
node: selectNode(state), node: selectNode(state),
@ -105,7 +106,7 @@ const CommentFormUnconnected: FC<IProps> = ({
const added_files = temp_ids const added_files = temp_ids
.map(temp_uuid => statuses[temp_uuid] && statuses[temp_uuid].uuid) .map(temp_uuid => statuses[temp_uuid] && statuses[temp_uuid].uuid)
.map(el => !!el && files[el]) .map(el => !!el && files[el])
.filter(el => !!el && !comment_data[id].files.some(file => file.id === el.id)); .filter(el => !!el && !comment_data[id].files.some(file => file && file.id === el.id));
const filtered_temps = temp_ids.filter( const filtered_temps = temp_ids.filter(
temp_id => temp_id =>
@ -124,13 +125,23 @@ const CommentFormUnconnected: FC<IProps> = ({
const comment = comment_data[id]; const comment = comment_data[id];
const images = useMemo(() => comment.files.filter(file => file.type === UPLOAD_TYPES.IMAGE), [ const images = useMemo(
comment.files, () => comment.files.filter(file => file && file.type === UPLOAD_TYPES.IMAGE),
]); [comment.files]
);
const audios = useMemo(() => comment.files.filter(file => file.type === UPLOAD_TYPES.AUDIO), [ const locked_images = useMemo(
comment.files, () =>
]); comment.temp_ids
.filter(temp => statuses[temp] && statuses[temp].type === UPLOAD_TYPES.IMAGE)
.map(temp_id => statuses[temp_id]),
[statuses, comment.temp_ids]
);
const audios = useMemo(
() => comment.files.filter(file => file && file.type === UPLOAD_TYPES.AUDIO),
[comment.files]
);
const onFileDrop = useCallback( const onFileDrop = useCallback(
(file_id: IFile['id']) => { (file_id: IFile['id']) => {
@ -159,6 +170,23 @@ const CommentFormUnconnected: FC<IProps> = ({
[images, audios] [images, audios]
); );
const onAudioMove = useCallback(
({ oldIndex, newIndex }: SortEnd) => {
nodeSetCommentData(
id,
assocPath(
['files'],
[
...images,
...(moveArrItem(oldIndex, newIndex, audios.filter(file => !!file)) as IFile[]),
],
comment_data[id]
)
);
},
[images, audios]
);
return ( return (
<CommentWrapper user={user}> <CommentWrapper user={user}>
<form onSubmit={onSubmit} className={styles.wrap}> <form onSubmit={onSubmit} className={styles.wrap}>
@ -179,15 +207,21 @@ const CommentFormUnconnected: FC<IProps> = ({
onSortEnd={onImageMove} onSortEnd={onImageMove}
axis="xy" axis="xy"
items={images} items={images}
locked={[]} locked={locked_images}
pressDelay={window.innerWidth < 768 ? 200 : 0} pressDelay={50}
helperClass={styles.helper} helperClass={styles.helper}
size={120} size={120}
/> />
{audios.map(file => ( <SortableAudioGrid
<AudioPlayer file={file} key={file.id} /> items={audios}
))} onDrop={onFileDrop}
onSortEnd={onAudioMove}
axis="y"
locked={[]}
pressDelay={50}
helperClass={styles.helper}
/>
</div> </div>
)} )}