Cover Image upload
This commit is contained in:
@@ -2,10 +2,11 @@ import * as React from 'react';
|
|||||||
import { Box, Typography, Divider, IconButton, Chip, TextField, Button } from '@mui/material';
|
import { Box, Typography, Divider, IconButton, Chip, TextField, Button } from '@mui/material';
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
||||||
import { ArticleMeta } from "../ArticleMeta";
|
|
||||||
import { ArticleEditorProps } from '../../types/props';
|
import { ArticleEditorProps } from '../../types/props';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
|
import ImageUploadField from "../ImageUploadField";
|
||||||
|
import { useUpload } from "../../providers/Upload";
|
||||||
|
|
||||||
const ArticleContainer = styled(Box)(({ theme }) => ({
|
const ArticleContainer = styled(Box)(({ theme }) => ({
|
||||||
maxWidth: '800px',
|
maxWidth: '800px',
|
||||||
@@ -29,12 +30,30 @@ export default function ArticleView({
|
|||||||
onBack,
|
onBack,
|
||||||
}: ArticleEditorProps) {
|
}: ArticleEditorProps) {
|
||||||
|
|
||||||
|
const { uploadFile } = useUpload();
|
||||||
|
|
||||||
const [title, setTitle] = React.useState(article?.title ?? "");
|
const [title, setTitle] = React.useState(article?.title ?? "");
|
||||||
const [description, setDescription] = React.useState(article?.description ?? "");
|
const [description, setDescription] = React.useState(article?.description ?? "");
|
||||||
const [tag, setTag] = React.useState(article?.tag ?? "");
|
const [tag, setTag] = React.useState(article?.tag ?? "");
|
||||||
const [img, setImg] = React.useState(article?.img ?? "");
|
const [img, setImg] = React.useState(article?.img ?? "");
|
||||||
|
const [uploadingCoverImage, setUploadingCoverImage] = React.useState(false);
|
||||||
const [content, setContent] = React.useState(article?.content ?? "");
|
const [content, setContent] = React.useState(article?.content ?? "");
|
||||||
|
|
||||||
|
const handleCoverImageUpload = async (file: File) => {
|
||||||
|
setUploadingCoverImage(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const img = await uploadFile(file);
|
||||||
|
if (img) {
|
||||||
|
setImg(img);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Avatar upload failed:", err);
|
||||||
|
} finally {
|
||||||
|
setUploadingCoverImage(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ArticleContainer>
|
<ArticleContainer>
|
||||||
{/* BACK BUTTON */}
|
{/* BACK BUTTON */}
|
||||||
@@ -71,18 +90,14 @@ export default function ArticleView({
|
|||||||
|
|
||||||
<Divider sx={{ mb: 3 }} />
|
<Divider sx={{ mb: 3 }} />
|
||||||
|
|
||||||
{/* COVER IMAGE URL */}
|
<ImageUploadField
|
||||||
<TextField
|
label="Cover Image"
|
||||||
label="Cover Image URL"
|
|
||||||
fullWidth
|
|
||||||
value={img}
|
value={img}
|
||||||
onChange={(e) => setImg(e.target.value)}
|
uploading={uploadingCoverImage}
|
||||||
sx={{ mb: 2 }}
|
onUpload={handleCoverImageUpload}
|
||||||
|
size={128}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* COVER IMAGE PREVIEW */}
|
|
||||||
{img && <CoverImage src={img} alt="cover" />}
|
|
||||||
|
|
||||||
<Divider sx={{ mb: 3 }} />
|
<Divider sx={{ mb: 3 }} />
|
||||||
|
|
||||||
{/* MARKDOWN EDITOR */}
|
{/* MARKDOWN EDITOR */}
|
||||||
|
|||||||
Reference in New Issue
Block a user