Finalize homepage editing functionality
This commit is contained in:
parent
1be3ee54b0
commit
7781c5c3e4
@ -60,7 +60,6 @@ function AppEditable() {
|
|||||||
"darkTheme": JSON.parse(responseData["dark_theme"]),
|
"darkTheme": JSON.parse(responseData["dark_theme"]),
|
||||||
"lightTheme": JSON.parse(responseData["light_theme"])
|
"lightTheme": JSON.parse(responseData["light_theme"])
|
||||||
})
|
})
|
||||||
setGlobalTheme(responseData["default_theme"])
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Container, Spinner, Input, InputGroup, InputGroupText, Button, ButtonGroup } from 'reactstrap';
|
import { Container, Spinner, Input, InputGroup, InputGroupText, Button, ButtonGroup, FormFeedback } from 'reactstrap';
|
||||||
import {useEffect, useState, useRef} from 'react';
|
import {useEffect, useState, useRef} from 'react';
|
||||||
import EditorComponent from './shared/tiptap';
|
import EditorComponent from './shared/tiptap';
|
||||||
import MediaService from '../../services/media-service'
|
import MediaService from '../../services/media-service'
|
||||||
@ -6,6 +6,7 @@ import MediaService from '../../services/media-service'
|
|||||||
function HomePage(props) {
|
function HomePage(props) {
|
||||||
const [introContent, setIntroContent] = useState("")
|
const [introContent, setIntroContent] = useState("")
|
||||||
const [saveKeyReady, setSaveKeyReady] = useState(true)
|
const [saveKeyReady, setSaveKeyReady] = useState(true)
|
||||||
|
const [nameFieldInvalid, setNameFieldInvalid] = useState(false)
|
||||||
const nameField = useRef(null)
|
const nameField = useRef(null)
|
||||||
const UserData = props.UserData ? props.UserData : <Spinner> Loading... </Spinner>
|
const UserData = props.UserData ? props.UserData : <Spinner> Loading... </Spinner>
|
||||||
const GlobalTheme = props.GlobalTheme;
|
const GlobalTheme = props.GlobalTheme;
|
||||||
@ -20,10 +21,20 @@ function HomePage(props) {
|
|||||||
console.log(response)
|
console.log(response)
|
||||||
if (response === 200)
|
if (response === 200)
|
||||||
props.notificationToggler("Data saved successfully!")
|
props.notificationToggler("Data saved successfully!")
|
||||||
if ([500, 404, 403].includes(response))
|
if ([500, 404, 403, 400].includes(response))
|
||||||
props.notificationToggler("Something failed!", "danger")
|
props.notificationToggler("Something failed!", "danger")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showError = (elementValue, fieldType) => {
|
||||||
|
console.log(elementValue)
|
||||||
|
if (fieldType === 'nameField'){
|
||||||
|
if (elementValue === '')
|
||||||
|
setNameFieldInvalid(true)
|
||||||
|
else
|
||||||
|
setNameFieldInvalid(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIntroContent(UserData.introContent)
|
setIntroContent(UserData.introContent)
|
||||||
}, [UserData])
|
}, [UserData])
|
||||||
@ -39,7 +50,10 @@ function HomePage(props) {
|
|||||||
<InputGroupText>
|
<InputGroupText>
|
||||||
Name
|
Name
|
||||||
</InputGroupText>
|
</InputGroupText>
|
||||||
<Input innerRef={nameField} defaultValue={UserData.name} />
|
<Input invalid={nameFieldInvalid} innerRef={nameField} defaultValue={UserData.name} onChange={() => showError(nameField.current.value, 'nameField')}/>
|
||||||
|
{nameFieldInvalid ? <FormFeedback tooltip className="mt-1">
|
||||||
|
This field cannot be empty
|
||||||
|
</FormFeedback>:''}
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
<EditorComponent GlobalTheme={GlobalTheme} ThemeConfig={ThemeConfig} content={UserData.introContent} setContent={setIntroContent}/>
|
<EditorComponent GlobalTheme={GlobalTheme} ThemeConfig={ThemeConfig} content={UserData.introContent} setContent={setIntroContent}/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -18,7 +18,7 @@ const Footer = (props) => {
|
|||||||
const ThemeConfig = props.ThemeConfig;
|
const ThemeConfig = props.ThemeConfig;
|
||||||
const UserData = props.UserData;
|
const UserData = props.UserData;
|
||||||
|
|
||||||
const setInfo = async (color, colorArea) => {
|
const setInfo = async (colorArea, color) => {
|
||||||
let localThemeConfig = {...ThemeConfig}
|
let localThemeConfig = {...ThemeConfig}
|
||||||
localThemeConfig[GlobalTheme].footer[colorArea] = `${color}`
|
localThemeConfig[GlobalTheme].footer[colorArea] = `${color}`
|
||||||
let response = await props.setInfo('/data/shared/update/theme-config/', GlobalTheme === "darkTheme" ? {
|
let response = await props.setInfo('/data/shared/update/theme-config/', GlobalTheme === "darkTheme" ? {
|
||||||
@ -42,39 +42,39 @@ const Footer = (props) => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color='primary'
|
color='primary'
|
||||||
onClick={() => setInfo('bg-primary', 'background')}/>
|
onClick={() => setInfo('background', 'bg-primary')}/>
|
||||||
<Button
|
<Button
|
||||||
color='secondary'
|
color='secondary'
|
||||||
onClick={() => setInfo('bg-secondary', 'background')}/>
|
onClick={() => setInfo('background', 'bg-secondary')}/>
|
||||||
<Button
|
<Button
|
||||||
color='success'
|
color='success'
|
||||||
onClick={() => setInfo('bg-success', 'background')}/>
|
onClick={() => setInfo('background', 'bg-success')}/>
|
||||||
<Button
|
<Button
|
||||||
color='danger'
|
color='danger'
|
||||||
onClick={() => setInfo('bg-danger', 'background')}/>
|
onClick={() => setInfo('background', 'bg-danger')}/>
|
||||||
<Button
|
<Button
|
||||||
color='warning'
|
color='warning'
|
||||||
onClick={() => setInfo('bg-warning', 'background')}/>
|
onClick={() => setInfo('background', 'bg-warning')}/>
|
||||||
<Button
|
<Button
|
||||||
color='info'
|
color='info'
|
||||||
onClick={() => setInfo('bg-info', 'background')}/>
|
onClick={() => setInfo('background', 'bg-info')}/>
|
||||||
<Button
|
<Button
|
||||||
color='light'
|
color='light'
|
||||||
onClick={() => setInfo('bg-light', 'background')}/>
|
onClick={() => setInfo('background', 'bg-light')}/>
|
||||||
<Button
|
<Button
|
||||||
color='dark'
|
color='dark'
|
||||||
onClick={() => setInfo('bg-dark', 'background')}/>
|
onClick={() => setInfo('background', 'bg-dark')}/>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
<ButtonGroup style={{marginTop: '15px', marginBottom: '15px'}}>
|
<ButtonGroup style={{marginTop: '15px', marginBottom: '15px'}}>
|
||||||
<Button disabled color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}>
|
<Button disabled color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}>
|
||||||
<FontAwesomeIcon icon={faBrush} /> Set footer text color
|
<FontAwesomeIcon icon={faBrush} /> Set footer text color
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
|
||||||
color='dark'
|
|
||||||
onClick={() => setInfo('text-light', 'text')}>White on black</Button>
|
|
||||||
<Button
|
<Button
|
||||||
color='light'
|
color='light'
|
||||||
onClick={() => setInfo('text-black', 'text')}>Black on white</Button>
|
onClick={() => setInfo('text', 'text-white')}>White</Button>
|
||||||
|
<Button
|
||||||
|
color='dark'
|
||||||
|
onClick={() => setInfo('text', 'text-black')}>Black</Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
<Col md="12">
|
<Col md="12">
|
||||||
<div className="blogContent text-center text-md-left mt-3">
|
<div className="blogContent text-center text-md-left mt-3">
|
||||||
|
|||||||
@ -26,13 +26,19 @@ function Header(props) {
|
|||||||
|
|
||||||
const [collapseClasses, setCollapseClasses] = useState('');
|
const [collapseClasses, setCollapseClasses] = useState('');
|
||||||
const [themeSelected, setThemeSelected] = useState('lightTheme');
|
const [themeSelected, setThemeSelected] = useState('lightTheme');
|
||||||
|
const [defaultThemeConfig, setDefaultThemeConfig] = useState('lightTheme');
|
||||||
|
|
||||||
const setInfo = async (color, colorArea) => {
|
const setInfo = async (colorArea, color, defaultThemeConfig) => {
|
||||||
let localThemeConfig = {...ThemeConfig}
|
let localThemeConfig = {...ThemeConfig}
|
||||||
localThemeConfig[GlobalTheme].navBar[colorArea] = `${color}`
|
|
||||||
|
if (colorArea && color)
|
||||||
|
localThemeConfig[GlobalTheme].navBar[colorArea] = `${color}`
|
||||||
|
|
||||||
let response = await props.setInfo('/data/shared/update/theme-config/', GlobalTheme === "darkTheme" ? {
|
let response = await props.setInfo('/data/shared/update/theme-config/', GlobalTheme === "darkTheme" ? {
|
||||||
|
"default_theme": defaultThemeConfig,
|
||||||
"dark_theme": JSON.stringify(localThemeConfig[GlobalTheme]),
|
"dark_theme": JSON.stringify(localThemeConfig[GlobalTheme]),
|
||||||
}:{
|
}:{
|
||||||
|
"default_theme": defaultThemeConfig,
|
||||||
"light_theme": JSON.stringify(localThemeConfig[GlobalTheme]),
|
"light_theme": JSON.stringify(localThemeConfig[GlobalTheme]),
|
||||||
})
|
})
|
||||||
if (response === 200)
|
if (response === 200)
|
||||||
@ -47,6 +53,7 @@ function Header(props) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setThemeSelected(props.ThemeConfig.defaultTheme)
|
setThemeSelected(props.ThemeConfig.defaultTheme)
|
||||||
|
setDefaultThemeConfig(props.ThemeConfig.defaultTheme)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (GlobalTheme && ThemeConfig && UserData)
|
if (GlobalTheme && ThemeConfig && UserData)
|
||||||
@ -102,41 +109,52 @@ function Header(props) {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color='primary'
|
color='primary'
|
||||||
onClick={() => setInfo('bg-primary', 'background')}/>
|
onClick={() => setInfo('background', 'bg-primary', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='secondary'
|
color='secondary'
|
||||||
onClick={() => setInfo('bg-secondary', 'background')}/>
|
onClick={() => setInfo('background', 'bg-secondary', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='success'
|
color='success'
|
||||||
onClick={() => setInfo('bg-success', 'background')}/>
|
onClick={() => setInfo('background', 'bg-success', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='danger'
|
color='danger'
|
||||||
onClick={() => setInfo('bg-danger', 'background')}/>
|
onClick={() => setInfo('background', 'bg-danger', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='warning'
|
color='warning'
|
||||||
onClick={() => setInfo('bg-warning', 'background')}/>
|
onClick={() => setInfo('background', 'bg-warning', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='info'
|
color='info'
|
||||||
onClick={() => setInfo('bg-info', 'background')}/>
|
onClick={() => setInfo('background', 'bg-info', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='light'
|
color='light'
|
||||||
onClick={() => setInfo('bg-light', 'background')}/>
|
onClick={() => setInfo('background', 'bg-light', ThemeConfig['defaultTheme'])}/>
|
||||||
<Button
|
<Button
|
||||||
color='dark'
|
color='dark'
|
||||||
onClick={() => setInfo('bg-dark', 'background')}/>
|
onClick={() => setInfo('background', 'bg-dark', ThemeConfig['defaultTheme'])}/>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
<ButtonGroup style={{marginTop: '15px', marginBottom: '15px'}}>
|
<ButtonGroup style={{marginTop: '15px', marginBottom: '15px'}}>
|
||||||
<Button disabled color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}>
|
<Button disabled color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}>
|
||||||
<FontAwesomeIcon icon={faBrush} /> Set button color
|
<FontAwesomeIcon icon={faBrush} /> Set button color
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}
|
color='light'
|
||||||
outline
|
onClick={() => setInfo('buttonColor', 'light', ThemeConfig['defaultTheme'])}>White</Button>
|
||||||
onClick={() => setInfo('light', 'buttonColor')}>White</Button>
|
<Button
|
||||||
|
color='dark'
|
||||||
|
onClick={() => setInfo('buttonColor', 'black', ThemeConfig['defaultTheme'])}>Black</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
<ButtonGroup style={{marginTop: '15px', marginBottom: '15px'}}>
|
||||||
|
<Button disabled color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}>
|
||||||
|
<FontAwesomeIcon icon={faBrush} /> Default Theme
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}
|
color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}
|
||||||
outline
|
outline
|
||||||
onClick={() => setInfo('black', 'buttonColor')}>Black</Button>
|
onClick={() => setInfo(null, null, 'lightTheme')}>Light Theme</Button>
|
||||||
|
<Button
|
||||||
|
color={`${ThemeConfig ? ThemeConfig[GlobalTheme].navBar['buttonColor'] : ""}`}
|
||||||
|
outline
|
||||||
|
onClick={() => setInfo(null, null, 'darkTheme')}>Dark Theme</Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</NavItem>
|
</NavItem>
|
||||||
</Nav>
|
</Nav>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user