fix: DraggableListItem with memo
This commit is contained in:
parent
6c46a4b32e
commit
f65bdf340a
@ -51,7 +51,6 @@ export default function ButtonsOptions({
|
|||||||
|
|
||||||
const openedModal = () => {
|
const openedModal = () => {
|
||||||
resetSomeField({ openedModalSettings: "open" });
|
resetSomeField({ openedModalSettings: "open" });
|
||||||
console.log(openedModalSettings);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { memo } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { Draggable } from "react-beautiful-dnd";
|
import { Draggable } from "react-beautiful-dnd";
|
||||||
import { Box, ListItem, Typography, useTheme } from "@mui/material";
|
import { Box, ListItem, Typography, useTheme } from "@mui/material";
|
||||||
@ -6,18 +7,23 @@ import QuestionsPageCard from "./QuestionPageCard";
|
|||||||
|
|
||||||
import { questionStore, updateQuestionsList } from "@root/questions";
|
import { questionStore, updateQuestionsList } from "@root/questions";
|
||||||
|
|
||||||
|
import {Question} from "@root/questions"
|
||||||
|
|
||||||
type DraggableListItemProps = {
|
type DraggableListItemProps = {
|
||||||
index: number;
|
index: number;
|
||||||
isDragging: boolean;
|
isDragging: boolean;
|
||||||
|
questionData: Question;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DraggableListItem = ({
|
export default memo(({
|
||||||
index,
|
index,
|
||||||
isDragging,
|
isDragging,
|
||||||
|
questionData
|
||||||
}: DraggableListItemProps) => {
|
}: DraggableListItemProps) => {
|
||||||
const quizId = Number(useParams().quizId);
|
const quizId = Number(useParams().quizId);
|
||||||
const { listQuestions } = questionStore();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
console.log("Мой индекс "+index)
|
||||||
|
console.log(questionData)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Draggable draggableId={String(index)} index={index}>
|
<Draggable draggableId={String(index)} index={index}>
|
||||||
@ -27,7 +33,7 @@ export const DraggableListItem = ({
|
|||||||
{...provided.draggableProps}
|
{...provided.draggableProps}
|
||||||
sx={{ userSelect: "none", padding: 0 }}
|
sx={{ userSelect: "none", padding: 0 }}
|
||||||
>
|
>
|
||||||
{listQuestions[quizId][index].deleted ? (
|
{questionData.deleted ? (
|
||||||
<Box
|
<Box
|
||||||
{...provided.dragHandleProps}
|
{...provided.dragHandleProps}
|
||||||
sx={{
|
sx={{
|
||||||
@ -50,7 +56,7 @@ export const DraggableListItem = ({
|
|||||||
<Typography
|
<Typography
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateQuestionsList(quizId, index, {
|
updateQuestionsList(quizId, index, {
|
||||||
...listQuestions[quizId][index],
|
...questionData,
|
||||||
deleted: false,
|
deleted: false,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@ -79,4 +85,4 @@ export const DraggableListItem = ({
|
|||||||
)}
|
)}
|
||||||
</Draggable>
|
</Draggable>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
@ -2,7 +2,7 @@ import { useParams } from "react-router-dom";
|
|||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
||||||
|
|
||||||
import { DraggableListItem } from "./DraggableListItem";
|
import DraggableListItem from "./DraggableListItem";
|
||||||
|
|
||||||
import { questionStore, updateQuestionsListDragAndDrop } from "@root/questions";
|
import { questionStore, updateQuestionsListDragAndDrop } from "@root/questions";
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ export const DraggableList = () => {
|
|||||||
key={index}
|
key={index}
|
||||||
index={index}
|
index={index}
|
||||||
isDragging={snapshot.isDraggingOver}
|
isDragging={snapshot.isDraggingOver}
|
||||||
|
questionData={_}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{provided.placeholder}
|
{provided.placeholder}
|
||||||
|
@ -53,7 +53,6 @@ export default function OptionsPicture({ totalIndex }: Props) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -77,7 +77,6 @@ export default function QuestionsPage() {
|
|||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
createQuestion(quizId);
|
createQuestion(quizId);
|
||||||
console.log(listQuestions);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AddPlus />
|
<AddPlus />
|
||||||
|
@ -101,7 +101,6 @@ export default function TypeQuestions({ totalIndex }: Props) {
|
|||||||
<QuestionsMiniButton
|
<QuestionsMiniButton
|
||||||
key={title}
|
key={title}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
console.log(value);
|
|
||||||
updateQuestionsList(quizId, totalIndex, { type: value });
|
updateQuestionsList(quizId, totalIndex, { type: value });
|
||||||
}}
|
}}
|
||||||
icon={icon}
|
icon={icon}
|
||||||
|
@ -68,7 +68,6 @@ export default function StartPageSettings({ handleNext }: HandleNext) {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const designType = listQuizes[params].startpage;
|
const designType = listQuizes[params].startpage;
|
||||||
const StartPageClone = listQuizes[params];
|
const StartPageClone = listQuizes[params];
|
||||||
console.log(StartPageClone);
|
|
||||||
const [backgroundType, setBackgroundType] = useState(
|
const [backgroundType, setBackgroundType] = useState(
|
||||||
listQuizes[params].config.startpage.background.type
|
listQuizes[params].config.startpage.background.type
|
||||||
);
|
);
|
||||||
@ -616,7 +615,6 @@ export default function StartPageSettings({ handleNext }: HandleNext) {
|
|||||||
label="Кликабельный"
|
label="Кликабельный"
|
||||||
checked={listQuizes[params].config.info.clickable}
|
checked={listQuizes[params].config.info.clickable}
|
||||||
handleChange={(e) => {
|
handleChange={(e) => {
|
||||||
console.log(e.target.checked);
|
|
||||||
let SPageClone = listQuizes[params].config;
|
let SPageClone = listQuizes[params].config;
|
||||||
SPageClone.info.clickable = e.target.checked;
|
SPageClone.info.clickable = e.target.checked;
|
||||||
updateQuizesList(params, { config: SPageClone });
|
updateQuizesList(params, { config: SPageClone });
|
||||||
|
@ -28,22 +28,18 @@ export default ({ text, sx, heightImg, widthImg }: Props) => {
|
|||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
|
|
||||||
const dragenterHC = () => {
|
const dragenterHC = () => {
|
||||||
// console.log("onDragEnter")
|
|
||||||
setReady(true);
|
setReady(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const dragexitHC = () => {
|
const dragexitHC = () => {
|
||||||
// console.log("onDragExit")
|
|
||||||
setReady(false);
|
setReady(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropHC = (event: React.DragEvent<HTMLDivElement>) => {
|
const dropHC = (event: React.DragEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// console.log("onDrop")
|
|
||||||
setReady(false);
|
setReady(false);
|
||||||
|
|
||||||
const file = event.dataTransfer.files[0];
|
const file = event.dataTransfer.files[0];
|
||||||
console.log(event.dataTransfer.files[0]);
|
|
||||||
if (file.size < 5242880) {
|
if (file.size < 5242880) {
|
||||||
setData(URL.createObjectURL(file));
|
setData(URL.createObjectURL(file));
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +49,6 @@ export default ({ text, sx, heightImg, widthImg }: Props) => {
|
|||||||
|
|
||||||
const dragOverHC = (event: React.DragEvent<HTMLDivElement>) => {
|
const dragOverHC = (event: React.DragEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// console.log("onDragOver")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -146,14 +146,11 @@ export default ({ text, sx, heightImg, widthImg }: Props) => {
|
|||||||
const [favList, setFavList] = useState<string[]>([]);
|
const [favList, setFavList] = useState<string[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(favList);
|
|
||||||
if (favList.length === 18) {
|
if (favList.length === 18) {
|
||||||
console.log("сейчас я сработаю");
|
|
||||||
|
|
||||||
const zip = new JSZip(); //создание зип архива
|
const zip = new JSZip(); //создание зип архива
|
||||||
|
|
||||||
favList.forEach((uri, i) => {
|
favList.forEach((uri, i) => {
|
||||||
console.log(i);
|
|
||||||
const idx = uri.indexOf("base64,") + "base64,".length; //обработка строки картинки
|
const idx = uri.indexOf("base64,") + "base64,".length; //обработка строки картинки
|
||||||
const content = uri.substring(idx); //обработка строки картинки
|
const content = uri.substring(idx); //обработка строки картинки
|
||||||
zip.file(`fav${i}.jpg`, content, { base64: true }); //сохранение картинки в архив с именем "fav.jpg"
|
zip.file(`fav${i}.jpg`, content, { base64: true }); //сохранение картинки в архив с именем "fav.jpg"
|
||||||
@ -201,46 +198,26 @@ export default ({ text, sx, heightImg, widthImg }: Props) => {
|
|||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
|
|
||||||
const dragenterHC = () => {
|
const dragenterHC = () => {
|
||||||
// console.log("onDragEnter")
|
|
||||||
setReady(true);
|
setReady(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const dragexitHC = () => {
|
const dragexitHC = () => {
|
||||||
// console.log("onDragExit")
|
|
||||||
setReady(false);
|
setReady(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropHC = (event: React.DragEvent<HTMLDivElement>) => {
|
const dropHC = (event: React.DragEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// console.log("onDrop")
|
|
||||||
setReady(false);
|
setReady(false);
|
||||||
const file = event.dataTransfer.files[0];
|
const file = event.dataTransfer.files[0];
|
||||||
console.log(event.dataTransfer.files[0]);
|
|
||||||
if (file.size < 5242880) {
|
if (file.size < 5242880) {
|
||||||
setData(URL.createObjectURL(file));
|
setData(URL.createObjectURL(file));
|
||||||
} else {
|
} else {
|
||||||
enqueueSnackbar("Размер картинки слишком велик");
|
enqueueSnackbar("Размер картинки слишком велик");
|
||||||
}
|
}
|
||||||
// try {
|
|
||||||
// Resizer.imageFileResizer(
|
|
||||||
// file,
|
|
||||||
// 50,
|
|
||||||
// 50,
|
|
||||||
// "JPEG",
|
|
||||||
// 100,
|
|
||||||
// 0,
|
|
||||||
// callback,
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// } catch (err) {
|
|
||||||
// console.log(err);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const dragOverHC = (event: React.DragEvent<HTMLDivElement>) => {
|
const dragOverHC = (event: React.DragEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// console.log("onDragOver")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -13,10 +13,8 @@ export default function StepOne({ handleNext }: HandleNext) {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const params = Number(useParams().quizId);
|
const params = Number(useParams().quizId);
|
||||||
console.log(params)
|
|
||||||
|
|
||||||
const {listQuizes, updateQuizesList,} = quizStore()
|
const {listQuizes, updateQuizesList,} = quizStore()
|
||||||
console.log(listQuizes)
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box
|
<Box
|
||||||
|
@ -155,9 +155,6 @@ export const CropModal: FC<Iprops> = ({ opened, onClose, picture }) => {
|
|||||||
|
|
||||||
const aspect = imageWidth / imageHeight;
|
const aspect = imageWidth / imageHeight;
|
||||||
|
|
||||||
console.log(aspect);
|
|
||||||
|
|
||||||
console.log(width);
|
|
||||||
|
|
||||||
if (aspect <= 1.333) {
|
if (aspect <= 1.333) {
|
||||||
setWidth(240);
|
setWidth(240);
|
||||||
|
@ -51,7 +51,6 @@ class Resizer {
|
|||||||
Yoffset = Math.round((size - height) / 2)
|
Yoffset = Math.round((size - height) / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(height, width)
|
|
||||||
|
|
||||||
ctx.drawImage(image, Xoffset, Yoffset, width, height);
|
ctx.drawImage(image, Xoffset, Yoffset, width, height);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user