Skip to content

Commit

Permalink
Chyby rozhraní pro tvůrce #361 (v2) (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
Werxis authored Jul 16, 2024
1 parent c6f8975 commit 64d763b
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 54 deletions.
2 changes: 1 addition & 1 deletion web/src/components/editors/WysiwygEditor/WysiwygEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "react-quill/dist/quill.snow.css";

import "./custom-editor-styles.scss";
import CustomToolbar from "./CustomToolbar";
import { getTextFromHtml } from "./getTextFromHtml";
import { getTextFromHtml } from "./utils";

// Other components
import CharacterCount from "../character-count";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export const getTextFromHtml = (htmlMarkup: string) => {

return plainText;
};

export const wrapTextInParagraph = (text: string) => {
return `<p>${text}</p>`;
};
28 changes: 20 additions & 8 deletions web/src/components/editors/screen-description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ import { Screen } from "models";
import { AppDispatch } from "store/store";

import { getFileById } from "actions/file-actions-typed";
import { updateScreenData } from "actions/expoActions";
import { saveScreen, updateScreenData } from "actions/expoActions";
import { helpIconText } from "enums/text";
import { ScreenCompletedCheckbox } from "./Checkboxes";
import { wrapTextInParagraph } from "./WysiwygEditor/utils";

type ScreenDescriptionProps = {
activeScreen: Screen;
rowNum: string | undefined;
colNum: string | undefined;
sumOfPhotosTimes?: number | null; // in case of slideshow description
totalZoomScreenTime?: number;
};

const ScreenDescription = ({
activeScreen,
rowNum,
colNum,
sumOfPhotosTimes,
totalZoomScreenTime,
}: ScreenDescriptionProps) => {
const { t } = useTranslation("expo-editor");
const dispatch = useDispatch<AppDispatch>();

const text =
"text" in activeScreen && activeScreen.text ? activeScreen.text : "";

const audioFile =
"audio" in activeScreen && activeScreen.audio
? dispatch(getFileById(activeScreen.audio))
Expand All @@ -47,13 +55,17 @@ const ScreenDescription = ({
<TitleTextField titleValue={activeScreen.title ?? ""} />
<WysiwygEditor
controlType="uncontrolled"
defaultValue={
"text" in activeScreen && activeScreen.text
? activeScreen.text
: ""
}
onChange={(newContent: string) => {
dispatch(updateScreenData({ text: newContent }));
defaultValue={text}
onChange={(newText: string) => {
const wrappedOldText = wrapTextInParagraph(text.trimEnd());
dispatch(updateScreenData({ text: newText }));

// NOTE: Additional check
// Means that the new text is just wrapped old text
// We do not want this change to act as a change done from user, so immediately save it
if (newText === wrappedOldText) {
dispatch(saveScreen(activeScreen, rowNum, colNum));
}
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const ScreenExternal = (props: ScreenEditorProps) => {
const externalScreenProps = props as ScreenEditorExternalProps;
const { activeScreen, url } = externalScreenProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

return (
<div>
<TabMenu
Expand All @@ -49,7 +52,13 @@ const ScreenExternal = (props: ScreenEditorProps) => {
/>
<Route
path={`${match.url}/description`}
render={() => <ScreenDescription activeScreen={activeScreen} />}
render={() => (
<ScreenDescription
activeScreen={activeScreen}
rowNum={rowNum}
colNum={colNum}
/>
)}
/>
<Route
path={`${match.url}/externalData`}
Expand All @@ -62,8 +71,8 @@ const ScreenExternal = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
history={history}
url={url}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const ScreenImageChange = (props: ScreenEditorProps) => {
const imageChangeProps = props as ScreenEditorImageChangeProps;
const { activeScreen } = imageChangeProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

return (
<div>
<TabMenu
Expand All @@ -48,7 +51,13 @@ const ScreenImageChange = (props: ScreenEditorProps) => {
/>
<Route
path={`${match.url}/description`}
render={() => <ScreenDescription activeScreen={activeScreen} />}
render={() => (
<ScreenDescription
activeScreen={activeScreen}
rowNum={rowNum}
colNum={colNum}
/>
)}
/>
<Route
path={`${match.url}/images`}
Expand All @@ -61,8 +70,8 @@ const ScreenImageChange = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
history={history}
url={imageChangeProps.url}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const ScreenImage = (props: ScreenEditorProps) => {
const imageScreenProps = props as ScreenEditorImageProps;
const { activeScreen, url } = imageScreenProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

return (
<div>
<TabMenu
Expand All @@ -50,7 +53,13 @@ const ScreenImage = (props: ScreenEditorProps) => {
/>
<Route
path={`${match.url}/description`}
render={() => <ScreenDescription activeScreen={activeScreen} />}
render={() => (
<ScreenDescription
activeScreen={activeScreen}
rowNum={rowNum}
colNum={colNum}
/>
)}
/>
<Route
path={`${match.url}/image`}
Expand All @@ -63,8 +72,8 @@ const ScreenImage = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
noActions={!!find(activeScreen.infopoints, (item) => item.edit)}
history={history}
url={url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const ScreenParallax = (props: ScreenEditorProps) => {
const parallaxScreenProps = props as ScreenEditorParallaxProps;
const { activeScreen, url } = parallaxScreenProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

return (
<div>
<TabMenu
Expand All @@ -49,7 +52,13 @@ const ScreenParallax = (props: ScreenEditorProps) => {
/>
<Route
path={`${match.url}/description`}
render={() => <ScreenDescription activeScreen={activeScreen} />}
render={() => (
<ScreenDescription
activeScreen={activeScreen}
rowNum={rowNum}
colNum={colNum}
/>
)}
/>
<Route
path={`${match.url}/parallax`}
Expand All @@ -62,8 +71,8 @@ const ScreenParallax = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
history={history}
url={url}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,28 @@ import { File as IndihuFile } from "models";

// Utils
import { getFileById } from "actions/file-actions";
import { updateScreenData } from "actions/expoActions/screen-actions";
import {
saveScreen,
updateScreenData,
} from "actions/expoActions/screen-actions";
import { wrapTextInParagraph } from "components/editors/WysiwygEditor/utils";

// - -

const Description = (props: ScreenEditorPhotogalleryProps) => {
type DescriptionProps = ScreenEditorPhotogalleryProps & {
rowNum: string | undefined;
colNum: string | undefined;
};

const Description = (props: DescriptionProps) => {
const { t } = useTranslation("expo-editor");
const dispatch = useDispatch<AppDispatch>();

const { activeScreen } = props;
const { activeScreen, rowNum, colNum } = props;
const audio = dispatch(getFileById(props.activeScreen.audio)) as IndihuFile;

const text = activeScreen.text ?? "";

return (
<div className="container container-tabMenu">
<div className="screen">
Expand All @@ -35,9 +46,17 @@ const Description = (props: ScreenEditorPhotogalleryProps) => {
<TitleTextField titleValue={activeScreen.title ?? ""} />
<WysiwygEditor
controlType="uncontrolled"
defaultValue={activeScreen.text ?? ""}
onChange={(newContent: string) => {
dispatch(updateScreenData({ text: newContent }));
defaultValue={text}
onChange={(newText: string) => {
const wrappedOldText = wrapTextInParagraph(text.trimEnd());
dispatch(updateScreenData({ text: newText }));

// NOTE: Additional check
// Means that the new text is just wrapped old text
// We do not want this change to act as a change done from user, so immediately save it
if (newText === wrappedOldText) {
dispatch(saveScreen(activeScreen, rowNum, colNum));
}
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const ScreenPhotogallery = (props: ScreenEditorProps) => {

const photogalleryProps = props as ScreenEditorPhotogalleryProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

return (
<div>
<TabMenu
Expand All @@ -43,7 +46,9 @@ const ScreenPhotogallery = (props: ScreenEditorProps) => {
/>
<Route
path={`${match.url}/description`}
render={() => <Description {...photogalleryProps} />}
render={() => (
<Description {...photogalleryProps} rowNum={rowNum} colNum={colNum} />
)}
/>
<Route
path={`${match.url}/photogallery`}
Expand All @@ -59,8 +64,8 @@ const ScreenPhotogallery = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={props.activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
history={history}
url={props.url}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const ScreenSignpost = (props: ScreenEditorProps) => {
const signpostProps = props as ScreenEditorSignpostProps;
const { activeScreen, url } = signpostProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

return (
<div>
<TabMenu
Expand All @@ -50,7 +53,13 @@ const ScreenSignpost = (props: ScreenEditorProps) => {
/>
<Route
path={`${match.url}/description`}
render={() => <ScreenDescription activeScreen={activeScreen} />}
render={() => (
<ScreenDescription
activeScreen={activeScreen}
rowNum={rowNum}
colNum={colNum}
/>
)}
/>
<Route
path={`${match.url}/references`}
Expand All @@ -64,8 +73,8 @@ const ScreenSignpost = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
history={history}
url={url}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const ScreenSlideshow = (props: ScreenEditorProps) => {
const slideshowProps = props as ScreenEditorSlideshowProps;
const { activeScreen } = slideshowProps;

const rowNum = match.params.position.match(/^(\d*)/)?.[0];
const colNum = match.params.position.match(/(\d*)$/)?.[0];

const timePhotosManual = useMemo(
() => activeScreen.timePhotosManual,
[activeScreen.timePhotosManual]
Expand Down Expand Up @@ -99,6 +102,8 @@ const ScreenSlideshow = (props: ScreenEditorProps) => {
<ScreenDescription
activeScreen={activeScreen}
sumOfPhotosTimes={sumOfPhotosTimes}
rowNum={rowNum}
colNum={colNum}
/>
)}
/>
Expand All @@ -118,8 +123,8 @@ const ScreenSlideshow = (props: ScreenEditorProps) => {
<Footer
activeExpo={props.activeExpo}
activeScreen={activeScreen}
rowNum={match.params.position.match(/^(\d*)/)?.[0]}
colNum={match.params.position.match(/(\d*)$/)?.[0]}
rowNum={rowNum}
colNum={colNum}
noActions={
!!find(activeScreen.images, (image) =>
find(image?.infopoints, (item) => item.edit)
Expand Down
Loading

0 comments on commit 64d763b

Please sign in to comment.