-
Notifications
You must be signed in to change notification settings - Fork 7
Refactored how templates are handled #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6833870
238285c
9ce0ae4
856745d
10120bc
692de1f
95eb2c8
fd8ca35
b59d034
c49b094
5314243
633b227
080c6c4
4a73327
318dceb
d4f2799
2b13acc
604227f
d16d637
e2ffe83
f993104
10c3b58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,7 +16,7 @@ import idFromUrl from "../util/helpers/id-from-url"; | |||||
import FormInput from "../util/forms/form-input"; | ||||||
import ContentForm from "./content/content-form"; | ||||||
import LoadingComponent from "../util/loading-component/loading-component"; | ||||||
import SlidePreview from "./preview/slide-preview.jsx"; | ||||||
import SlidePreview from "./preview/slide-preview"; | ||||||
import FeedSelector from "./content/feed-selector"; | ||||||
import SelectPlaylistsTable from "../util/multi-and-table/select-playlists-table"; | ||||||
import localStorageKeys from "../util/local-storage-keys"; | ||||||
|
@@ -26,6 +26,7 @@ import "./slide-form.scss"; | |||||
import Preview from "../preview/preview"; | ||||||
import StickyFooter from "../util/sticky-footer"; | ||||||
import Select from "../util/forms/select"; | ||||||
import { getConfig } from "../../../shared/slide-utils/templates"; | ||||||
|
||||||
/** | ||||||
* The slide form component. | ||||||
|
@@ -92,6 +93,7 @@ function SlideForm({ | |||||
const [themesOptions, setThemesOptions] = useState(); | ||||||
const [displayPreview, setDisplayPreview] = useState(null); | ||||||
const [templateError, setTemplateError] = useState(false); | ||||||
const [disableLivePreview, setDisableLivePreview] = useState(false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This state is never changed in the file...... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch :) |
||||||
|
||||||
// Load templates. | ||||||
const { data: templates, isLoading: loadingTemplates } = | ||||||
|
@@ -157,19 +159,12 @@ function SlideForm({ | |||||
const newSelectedTemplates = []; | ||||||
|
||||||
if (selectedTemplate) { | ||||||
// Get content form from template resources. | ||||||
const contentFormUrl = selectedTemplate?.resources?.admin; | ||||||
fetch(contentFormUrl) | ||||||
.then((response) => response.json()) | ||||||
.then((data) => { | ||||||
setContentFormElements(data); | ||||||
}) | ||||||
.catch((er) => { | ||||||
displayError(t("template-error"), er); | ||||||
}); | ||||||
|
||||||
const slideConfig = getConfig(selectedTemplate['id']); | ||||||
setContentFormElements(slideConfig.adminForm ?? []); | ||||||
setDisableLivePreview(slideConfig?.options?.disableLivePreview ?? false); | ||||||
newSelectedTemplates.push(selectedTemplate); | ||||||
} | ||||||
|
||||||
setSelectedTemplates(newSelectedTemplates); | ||||||
}, [selectedTemplate]); | ||||||
|
||||||
|
@@ -401,13 +396,12 @@ function SlideForm({ | |||||
</Button> | ||||||
</div> | ||||||
|
||||||
{selectedTemplate?.resources?.options?.disableLivePreview && ( | ||||||
{disableLivePreview && ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<Alert variant="secondary" className="mt-3"> | ||||||
{t("slide-preview-disabled-preview")} | ||||||
</Alert> | ||||||
)} | ||||||
{!selectedTemplate?.resources?.options?.disableLivePreview && | ||||||
selectedTemplate?.resources?.component && ( | ||||||
{!disableLivePreview && ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<> | ||||||
{previewOrientation === "horizontal" && ( | ||||||
<div style={{ width: "100%" }}> | ||||||
|
@@ -581,10 +575,6 @@ SlideForm.propTypes = { | |||||
selectTemplate: PropTypes.func.isRequired, | ||||||
selectedTemplate: PropTypes.shape({ | ||||||
"@id": PropTypes.string, | ||||||
resources: PropTypes.shape({ | ||||||
admin: PropTypes.string.isRequired, | ||||||
component: PropTypes.string.isRequired, | ||||||
}).isRequired, | ||||||
}), | ||||||
isLoading: PropTypes.bool, | ||||||
loadingMessage: PropTypes.string, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"title": "Test", | ||
"id": "01K2PREY1Q0XCTR9EK1YT5R4XK", | ||
"options": {}, | ||
"adminForm": [ | ||
{ | ||
"key": "test-form-1", | ||
"input": "header", | ||
"text": "Skabelon: Test", | ||
"formGroupClasses": "h4 mb-3" | ||
}, | ||
{ | ||
"key": "test-form-title", | ||
"input": "input", | ||
"name": "title", | ||
"type": "text", | ||
"label": "Overskrift", | ||
"helpText": "Her kan du skrive overskrift.", | ||
"formGroupClasses": "mb-3" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useEffect } from "react"; | ||
tuj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import templateConfig from "./custom-template-example.json"; | ||
import BaseSlideExecution from "../slide-utils/base-slide-execution.js"; | ||
import { ThemeStyles } from "../slide-utils/slide-util.jsx"; | ||
|
||
function id() { | ||
return templateConfig.id; | ||
} | ||
|
||
function config() { | ||
return templateConfig; | ||
} | ||
|
||
function renderSlide(slide, run, slideDone) { | ||
return <CustomTemplateExample | ||
slide={slide} | ||
run={run} | ||
slideDone={slideDone} | ||
content={slide.content} | ||
executionId={slide.executionId} | ||
/>; | ||
} | ||
|
||
/** | ||
* @param {object} props Props. | ||
* @param {object} props.slide The slide. | ||
* @param {object} props.content The slide content. | ||
* @param {boolean} props.run Whether or not the slide should start running. | ||
* @param {Function} props.slideDone Function to invoke when the slide is done playing. | ||
* @param {string} props.executionId Unique id for the instance. | ||
* @returns {JSX.Element} The component. | ||
*/ | ||
function CustomTemplateExample({ slide, content, run, slideDone, executionId }) { | ||
const { duration = 15000 } = content; | ||
const { title = "Default title" } = content; | ||
|
||
const slideExecution = new BaseSlideExecution(slide, slideDone); | ||
|
||
useEffect(() => { | ||
if (run) { | ||
slideExecution.start(duration); | ||
} | ||
|
||
return function cleanup() { | ||
slideExecution.stop(); | ||
}; | ||
}, [run]); | ||
|
||
return (<> | ||
<div className="custom-template-example"> | ||
<h1 className="title">{title}</h1> | ||
</div> | ||
|
||
<ThemeStyles id={executionId} css={slide?.theme?.cssStyles} /> | ||
</>); | ||
} | ||
|
||
export default { id, config, renderSlide }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.