mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
Audio title editing
This commit is contained in:
parent
da47da9d6a
commit
fff3770b1e
7 changed files with 304 additions and 242 deletions
|
@ -28,9 +28,21 @@ const AudioGrid: FC<IProps> = ({ files, setFiles, locked }) => {
|
||||||
[setFiles, files]
|
[setFiles, files]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onTitleChange = useCallback(
|
||||||
|
(changeId: IFile['id'], title: IFile['metadata']['title']) => {
|
||||||
|
setFiles(
|
||||||
|
files.map(file =>
|
||||||
|
file && file.id === changeId ? { ...file, metadata: { ...file.metadata, title } } : file
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[setFiles, files]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SortableAudioGrid
|
<SortableAudioGrid
|
||||||
onDrop={onDrop}
|
onDrop={onDrop}
|
||||||
|
onTitleChange={onTitleChange}
|
||||||
onSortEnd={onMove}
|
onSortEnd={onMove}
|
||||||
axis="xy"
|
axis="xy"
|
||||||
items={files}
|
items={files}
|
||||||
|
|
|
@ -12,17 +12,19 @@ const SortableAudioGrid = SortableContainer(
|
||||||
items,
|
items,
|
||||||
locked,
|
locked,
|
||||||
onDrop,
|
onDrop,
|
||||||
|
onTitleChange,
|
||||||
}: {
|
}: {
|
||||||
items: IFile[];
|
items: IFile[];
|
||||||
locked: IUploadStatus[];
|
locked: IUploadStatus[];
|
||||||
onDrop: (file_id: IFile['id']) => void;
|
onDrop: (file_id: IFile['id']) => void;
|
||||||
|
onTitleChange: (file_id: IFile['id'], title: IFile['metadata']['title']) => void;
|
||||||
}) => (
|
}) => (
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
{items
|
{items
|
||||||
.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} nonInteractive />
|
<AudioPlayer file={file} onDrop={onDrop} onTitleChange={onTitleChange} isEditing />
|
||||||
</SortableImageGridItem>
|
</SortableImageGridItem>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useCallback, useState, useEffect, memo } from 'react';
|
import React, { useCallback, useState, useEffect, memo, useMemo } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { selectPlayer } from '~/redux/player/selectors';
|
import { selectPlayer } from '~/redux/player/selectors';
|
||||||
import * as PLAYER_ACTIONS from '~/redux/player/actions';
|
import * as PLAYER_ACTIONS from '~/redux/player/actions';
|
||||||
|
@ -8,6 +8,7 @@ import { Player, IPlayerProgress } from '~/utils/player';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import { Icon } from '~/components/input/Icon';
|
import { Icon } from '~/components/input/Icon';
|
||||||
|
import { InputText } from '~/components/input/InputText';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
player: selectPlayer(state),
|
player: selectPlayer(state),
|
||||||
|
@ -23,15 +24,17 @@ const mapDispatchToProps = {
|
||||||
type Props = ReturnType<typeof mapStateToProps> &
|
type Props = ReturnType<typeof mapStateToProps> &
|
||||||
typeof mapDispatchToProps & {
|
typeof mapDispatchToProps & {
|
||||||
file: IFile;
|
file: IFile;
|
||||||
nonInteractive?: boolean;
|
isEditing?: boolean;
|
||||||
onDrop?: (id: IFile['id']) => void;
|
onDrop?: (id: IFile['id']) => void;
|
||||||
|
onTitleChange?: (file_id: IFile['id'], title: IFile['metadata']['title']) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const AudioPlayerUnconnected = memo(
|
const AudioPlayerUnconnected = memo(
|
||||||
({
|
({
|
||||||
file,
|
file,
|
||||||
onDrop,
|
onDrop,
|
||||||
nonInteractive,
|
isEditing,
|
||||||
|
onTitleChange,
|
||||||
player: { file: current, status },
|
player: { file: current, status },
|
||||||
playerSetFileAndPlay,
|
playerSetFileAndPlay,
|
||||||
playerPlay,
|
playerPlay,
|
||||||
|
@ -46,7 +49,7 @@ const AudioPlayerUnconnected = memo(
|
||||||
});
|
});
|
||||||
|
|
||||||
const onPlay = useCallback(() => {
|
const onPlay = useCallback(() => {
|
||||||
if (nonInteractive) return;
|
if (isEditing) 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();
|
||||||
|
@ -54,7 +57,7 @@ const AudioPlayerUnconnected = memo(
|
||||||
}
|
}
|
||||||
|
|
||||||
playerSetFileAndPlay(file);
|
playerSetFileAndPlay(file);
|
||||||
}, [file, current, status, playerPlay, playerPause, playerSetFileAndPlay, nonInteractive]);
|
}, [file, current, status, playerPlay, playerPause, playerSetFileAndPlay, isEditing]);
|
||||||
|
|
||||||
const onProgress = useCallback(
|
const onProgress = useCallback(
|
||||||
({ detail }: { detail: IPlayerProgress }) => {
|
({ detail }: { detail: IPlayerProgress }) => {
|
||||||
|
@ -80,6 +83,21 @@ const AudioPlayerUnconnected = memo(
|
||||||
onDrop(file.id);
|
onDrop(file.id);
|
||||||
}, [file, onDrop]);
|
}, [file, onDrop]);
|
||||||
|
|
||||||
|
const title = useMemo(
|
||||||
|
() =>
|
||||||
|
(file.metadata &&
|
||||||
|
(file.metadata.title ||
|
||||||
|
[file.metadata.id3artist, file.metadata.id3title].filter(el => el).join(' - '))) ||
|
||||||
|
file.orig_name ||
|
||||||
|
'',
|
||||||
|
[file.metadata]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onRename = useCallback((val: string) => onTitleChange(file.id, val), [
|
||||||
|
onTitleChange,
|
||||||
|
file.id,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const active = current && current.id === file.id;
|
const active = current && current.id === file.id;
|
||||||
setPlaying(current && current.id === file.id);
|
setPlaying(current && current.id === file.id);
|
||||||
|
@ -91,11 +109,6 @@ const AudioPlayerUnconnected = memo(
|
||||||
};
|
};
|
||||||
}, [file, current, setPlaying, onProgress]);
|
}, [file, current, setPlaying, onProgress]);
|
||||||
|
|
||||||
const title =
|
|
||||||
file.metadata &&
|
|
||||||
(file.metadata.title ||
|
|
||||||
[file.metadata.id3artist, file.metadata.id3title].filter(el => !!el).join(' - '));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={onPlay} className={classNames(styles.wrap, { playing })}>
|
<div onClick={onPlay} className={classNames(styles.wrap, { playing })}>
|
||||||
{onDrop && (
|
{onDrop && (
|
||||||
|
@ -112,13 +125,21 @@ const AudioPlayerUnconnected = memo(
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{isEditing ? (
|
||||||
|
<div className={styles.input}>
|
||||||
|
<InputText value={title} handler={onRename} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
|
<div className={styles.title}>
|
||||||
<div className={styles.title}>{title || 'Unknown'}</div>
|
<div className={styles.title}>{title || 'Unknown'}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className={styles.progress} onClick={onSeek}>
|
<div className={styles.progress} onClick={onSeek}>
|
||||||
<div className={styles.bar} style={{ width: `${progress.progress}%` }} />
|
<div className={styles.bar} style={{ width: `${progress.progress}%` }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,3 +130,9 @@
|
||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
flex: 1;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 0 48px 0 0;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { FC, useCallback, KeyboardEventHandler, useEffect, useMemo } from 'react';
|
import React, { FC, useCallback, KeyboardEventHandler, useEffect, useMemo, memo } from 'react';
|
||||||
import { Textarea } from '~/components/input/Textarea';
|
import { Textarea } from '~/components/input/Textarea';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import { Filler } from '~/components/containers/Filler';
|
import { Filler } from '~/components/containers/Filler';
|
||||||
|
@ -41,7 +41,8 @@ type IProps = ReturnType<typeof mapStateToProps> &
|
||||||
is_before?: boolean;
|
is_before?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CommentFormUnconnected: FC<IProps> = ({
|
const CommentFormUnconnected: FC<IProps> = memo(
|
||||||
|
({
|
||||||
node: { comment_data, is_sending_comment },
|
node: { comment_data, is_sending_comment },
|
||||||
uploads: { statuses, files },
|
uploads: { statuses, files },
|
||||||
id,
|
id,
|
||||||
|
@ -155,10 +156,26 @@ const CommentFormUnconnected: FC<IProps> = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
const onFileDrop = useCallback(
|
const onFileDrop = useCallback(
|
||||||
(file_id: IFile['id']) => {
|
(fileId: IFile['id']) => {
|
||||||
nodeSetCommentData(
|
nodeSetCommentData(
|
||||||
id,
|
id,
|
||||||
assocPath(['files'], comment.files.filter(file => file.id != file_id), comment_data[id])
|
assocPath(['files'], comment.files.filter(file => file.id != fileId), comment_data[id])
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[comment_data, id, nodeSetCommentData]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onTitleChange = useCallback(
|
||||||
|
(fileId: IFile['id'], title: IFile['metadata']['title']) => {
|
||||||
|
nodeSetCommentData(
|
||||||
|
id,
|
||||||
|
assocPath(
|
||||||
|
['files'],
|
||||||
|
comment.files.map(file =>
|
||||||
|
file.id === fileId ? { ...file, metadata: { ...file.metadata, title } } : file
|
||||||
|
),
|
||||||
|
comment_data[id]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[comment_data, id, nodeSetCommentData]
|
[comment_data, id, nodeSetCommentData]
|
||||||
|
@ -236,6 +253,7 @@ const CommentFormUnconnected: FC<IProps> = ({
|
||||||
<SortableAudioGrid
|
<SortableAudioGrid
|
||||||
items={audios}
|
items={audios}
|
||||||
onDrop={onFileDrop}
|
onDrop={onFileDrop}
|
||||||
|
onTitleChange={onTitleChange}
|
||||||
onSortEnd={onAudioMove}
|
onSortEnd={onAudioMove}
|
||||||
axis="y"
|
axis="y"
|
||||||
locked={locked_audios}
|
locked={locked_audios}
|
||||||
|
@ -278,7 +296,8 @@ const CommentFormUnconnected: FC<IProps> = ({
|
||||||
</Group>
|
</Group>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const CommentForm = connect(
|
const CommentForm = connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
|
|
|
@ -64,6 +64,7 @@ export interface IFile {
|
||||||
node_id?: UUID;
|
node_id?: UUID;
|
||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
|
orig_name: string;
|
||||||
path: string;
|
path: string;
|
||||||
full_path: string;
|
full_path: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
|
@ -19,13 +19,14 @@ export const EMPTY_FILE: IFile = {
|
||||||
user_id: null,
|
user_id: null,
|
||||||
node_id: null,
|
node_id: null,
|
||||||
|
|
||||||
name: 'mario-collage-800x450.jpg',
|
name: '',
|
||||||
path: '/wp-content/uploads/2017/09/',
|
orig_name: '',
|
||||||
full_path: '/wp-content/uploads/2017/09/mario-collage-800x450.jpg',
|
path: '',
|
||||||
url: 'https://cdn.arstechnica.net/wp-content/uploads/2017/09/mario-collage-800x450.jpg',
|
full_path: '',
|
||||||
size: 2400000,
|
url: '',
|
||||||
type: 'image',
|
size: 0,
|
||||||
mime: 'image/jpeg',
|
type: null,
|
||||||
|
mime: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EMPTY_UPLOAD_STATUS: IUploadStatus = {
|
export const EMPTY_UPLOAD_STATUS: IUploadStatus = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue