mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-23 18:47:11 +00:00
Move remaining state to common hook
This commit is contained in:
1 parent
c282d5e5bc
commit
9fb7a79047
4 files changed
+45
-103
No files matched your search
@@ -1,20 +1,11 @@
|
||||
import './newPage.less';
|
||||
|
||||
// Common imports
|
||||
import React, { useState } from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||
|
||||
import React from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import _ from 'lodash';
|
||||
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.jsx';
|
||||
|
||||
// Page specific imports
|
||||
const useLocalStorage = true;
|
||||
const sandbox = true;
|
||||
const showFloatingButtons = false;
|
||||
const showEditorButtons = true;
|
||||
const pageName = 'newPage';
|
||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||
|
||||
const NewPage = (props)=>{
|
||||
props = {
|
||||
@@ -22,18 +13,10 @@ const NewPage = (props)=>{
|
||||
...props
|
||||
};
|
||||
|
||||
const [currentBrew, setCurrentBrew] = useState(props.brew);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const save = async (brew, saveToGoogle)=>{
|
||||
const res = await request
|
||||
.post(`/api${saveToGoogle ? '?saveToGoogle=true' : ''}`)
|
||||
.send(brew)
|
||||
.catch((err)=>{
|
||||
console.error('Error Updating Local Brew');
|
||||
setError(err);
|
||||
});
|
||||
if(!res) return;
|
||||
.send(brew);
|
||||
|
||||
return res.body;
|
||||
};
|
||||
@@ -46,18 +29,15 @@ const NewPage = (props)=>{
|
||||
const {
|
||||
renderPanels
|
||||
} = useCommonEditPageFunctions({
|
||||
error,
|
||||
setError,
|
||||
currentBrew,
|
||||
setCurrentBrew,
|
||||
useLocalStorage,
|
||||
sandbox,
|
||||
showFloatingButtons,
|
||||
useLocalStorage : true,
|
||||
sandbox : true,
|
||||
showFloatingButtons : false,
|
||||
showEditorButtons : true,
|
||||
pageName : 'newPage',
|
||||
brew : props.brew,
|
||||
userThemes : props.userThemes,
|
||||
save,
|
||||
onSaveSuccess,
|
||||
pageName,
|
||||
showEditorButtons,
|
||||
userThemes : props.userThemes
|
||||
});
|
||||
|
||||
return renderPanels();
|
||||
|
||||
Reference in new issue
Block a user