last changes, possibly

This commit is contained in:
Spynder
2025-05-15 04:32:23 +03:00
parent 042b53e6a4
commit ab1fd6b22a
17 changed files with 1044 additions and 1354 deletions

View File

@ -9,7 +9,6 @@ import "easymde/dist/easymde.min.css";
import { LanguageSelector } from "@ui";
import { observer } from "mobx-react-lite";
import { EVERY_LANGUAGE, Languages, languageStore, META_LANGUAGE } from "@stores";
import { axiosInstance } from "@/providers/data";
const MemoizedSimpleMDE = React.memo(MarkdownEditor);
@ -33,15 +32,14 @@ export const ArticleCreate = observer(() => {
refineCoreProps: {
resource: "article",
...META_LANGUAGE(language)
},
warnWhenUnsavedChanges: false
}
});
// Следим за изменениями в полях body и heading
const bodyContent = watch("body");
const headingContent = watch("heading");
function updateTranslations() {
function updateTranslations(update: boolean = true) {
const newArticleData = {
...articleData,
heading: {
@ -53,13 +51,12 @@ export const ArticleCreate = observer(() => {
[language]: watch("body") ?? "",
}
}
setArticleData(newArticleData);
if(update) setArticleData(newArticleData);
return newArticleData;
}
const handleFormSubmit = handleSubmit((values: FieldValues) => {
const newTranslations = updateTranslations();
console.log(newTranslations);
const handleFormSubmit = handleSubmit((values) => {
const newTranslations = updateTranslations(false);
return onFinish({
translations: newTranslations
});
@ -80,7 +77,6 @@ export const ArticleCreate = observer(() => {
const [preview, setPreview] = useState("");
const [headingPreview, setHeadingPreview] = useState("");
useEffect(() => {
setPreview(bodyContent ?? "");
}, [bodyContent]);
@ -89,17 +85,13 @@ export const ArticleCreate = observer(() => {
setHeadingPreview(headingContent ?? "");
}, [headingContent]);
const simpleMDEOptions = React.useMemo(
() => ({
placeholder: "Введите контент в формате Markdown...",
spellChecker: false,
}),
[]
);
const simpleMDEOptions = React.useMemo(() => ({
placeholder: "Введите контент в формате Markdown...",
spellChecker: false,
}), []);
return (
<Create isLoading={formLoading} saveButtonProps={{
//...saveButtonProps,
onClick: handleFormSubmit
}}>
<Box sx={{ display: "flex", flex: 1, gap: 2 }}>
@ -119,7 +111,7 @@ export const ArticleCreate = observer(() => {
helperText={(errors as any)?.heading?.message}
margin="normal"
fullWidth
InputLabelProps={{ shrink: true }}
slotProps={{inputLabel: {shrink: true}}}
type="text"
label="Заголовок *"
name="heading"
@ -128,7 +120,7 @@ export const ArticleCreate = observer(() => {
<Controller
control={control}
name="body"
rules={{ required: "Это поле является обязательным" }}
//rules={{ required: "Это поле является обязательным" }}
defaultValue=""
render={({ field: { onChange, value } }) => (
<MemoizedSimpleMDE