Skip to content

Commit

Permalink
fix: add timeline on mobile post (#1863)
Browse files Browse the repository at this point in the history
* fix: add selected timeline id on import post, remove view details timeline on post

* fix: add video upload on mobile

* fix: add timeline id on mobile
  • Loading branch information
alvin371 authored Jun 15, 2023
1 parent 65cddb8 commit c415e5d
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/components/ExperienceTimelineCard/Experience.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,6 @@ export const Experience: React.FC<ExperienceProps> = props => {
? 'Custom'
: capitalize(userExperience.experience.visibility)}
</Typography>
<Link
href={`/experience/[experienceId]`}
as={`/experience/${experienceId}`}
passHref>
<Typography variant="body2" color="primary">
{i18n.t('Experience.List.Menu.View')}
</Typography>
</Link>
</div>
</CardContent>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/components/PostCreate/PostCreate.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const useStyles = makeStyles((theme: Theme) =>
alignItems: 'center',
position: 'relative',
[theme.breakpoints.down('xs')]: {
flexDirection: 'column',
flexDirection: 'row',
alignItems: 'flex-start',
padding: 0,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/PostCreate/PostCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const PostCreate: React.FC<PostCreateProps> = props => {
selectedUserIds: post.selectedUserIds,
NSFWTag: post.NSFWTag,
visibility: post.visibility ?? PostVisibility.PUBLIC,
selectedTimelineIds: post.selectedTimelineIds,
selectedTimelineIds: timelineId,
});
}
}
Expand Down
71 changes: 67 additions & 4 deletions src/components/common/CKEditor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import { CKEditor } from '@ckeditor/ckeditor5-react';

import React from 'react';
import React, { useState } from 'react';

import { Button } from '@material-ui/core';

import { EditorProps } from './Editor.interface';
import { useStyles } from './Editor.style';
import { MediaEmbedToolbarButton } from './MediaEmbedButton';
import { CustomAdapterPlugin } from './adapters';

import * as UserAPI from 'src/lib/api/user';

type File = {
originalname: string;
mimeType: string;
size: number;
url: string;
};
const VideoPreview = ({ videoURL }) => {
return (
<div style={{ width: '150px', height: 'auto', margin: '10px' }}>
<video
controls
style={{ width: '150px', height: 'auto', maxHeight: '75px' }}>
<source src={videoURL} type="video/mp4" />
Your browser does not support the video tag.
</video>
</div>
);
};

export const Editor: React.FC<EditorProps> = props => {
const { mobile, onChange, isErrorEditor, placeholder } = props;
const { userId, mobile, onChange, isErrorEditor, placeholder } = props;

const styles = useStyles({ mobile, counter: true });
const [modalOpen, setModalOpen] = useState(false);
const [uploadedVideos, setUploadedVideos] = useState([]);
const handleUploadButtonClick = () => {
setModalOpen(true);
};

const handleSearch = async (query: string) => {
const { data } = await UserAPI.searchUsers(1, query);
Expand Down Expand Up @@ -58,13 +85,19 @@ export const Editor: React.FC<EditorProps> = props => {
},
image: {
upload: {
types: ['png', 'jpeg', 'webp', 'gif'],
types: ['png', 'jpeg', 'webp', 'gif', 'mp4'],
},
toolbar: [],
},
};

console.log('isError', isErrorEditor);
const handleFileSelected = (uploadedVideosData: File[]) => {
const videoURL = uploadedVideosData[0].url; // Assuming you only upload one video at a time

setUploadedVideos([...uploadedVideos, videoURL]);
setModalOpen(false);
};

return (
<div
className={`${styles.root} ${styles.large}`}
Expand All @@ -91,6 +124,36 @@ export const Editor: React.FC<EditorProps> = props => {
console.error({ event, editor });
}}
/>

<Button
variant="contained"
color="primary"
size="small"
fullWidth
onClick={handleUploadButtonClick}
style={{ margin: '10px auto' }}>
Upload Video
</Button>

<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(2, 150px)',
gridGap: '10px',
}}>
{uploadedVideos.map((videoURL, index) => (
<VideoPreview key={index} videoURL={videoURL} />
))}
</div>

{modalOpen && (
<MediaEmbedToolbarButton
userId={userId} // Pass the required props to the MediaEmbedToolbarButton component
onFileSelected={handleFileSelected}
modalOpen={modalOpen}
onClose={() => setModalOpen(false)}
/>
)}
</div>
);
};
Expand Down
58 changes: 58 additions & 0 deletions src/components/common/CKEditor/MediaEmbedButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { useState } from 'react';

import { Upload } from 'components/Upload';
import { Modal } from 'components/atoms/Modal';
import * as UploadAPI from 'src/lib/api/upload';
import i18n from 'src/locale';

export const MediaEmbedToolbarButton = ({
userId,
onFileSelected,
modalOpen,
...props
}) => {
const [progress, setProgress] = useState(0);
const [open, setOpen] = useState(modalOpen ?? false);

const handleFileSelected = async (files: File[]) => {
if (files.length === 0) return;

try {
const { files: uploadedFiles } = await UploadAPI.videoMobile(files[0], {
onUploadProgress: (event: ProgressEvent) => {
const total = Math.round((100 * event.loaded) / event.total);

setProgress(total);
},
});

onFileSelected(uploadedFiles);

setProgress(0);
setOpen(false);
} catch (error) {
console.error('ERROR', error);
}
};

return (
<Modal
title={i18n.t('Post_Create.Upload.Video.Title')}
align="left"
titleSize="small"
maxWidth="xl"
open={open}
onClose={() => setOpen(false)}>
<Upload
type="video"
progress={progress}
loading={progress > 0}
onFileSelected={handleFileSelected}
accept={['video/mp4', 'video/x-m4v', 'video/*']}
maxSize={100}
placeholder={i18n.t('Post_Create.Upload.Video.Placeholder')}
usage="post"
/>
</Modal>
);
};
20 changes: 20 additions & 0 deletions src/lib/api/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,23 @@ export const video = async (

return data;
};

export const videoMobile = async (
file: File,
options: UploadOptions,
): Promise<ResponseFileUpload> => {
const formData = new FormData();
formData.append('file', file);

const { data } = await MyriadAPI().request<ResponseFileUpload>({
url: `/upload/video`,
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
onUploadProgress: options.onUploadProgress,
});

return data;
};

0 comments on commit c415e5d

Please sign in to comment.