mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-20 14:32:57 +00:00
Pass in the remaining missing dependencies
This commit is contained in:
@@ -8,7 +8,6 @@ import { hbfm } from 'hbmarkedwrapper';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
||||||
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
|
||||||
|
|
||||||
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.js'
|
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.js'
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ const SAVE_TIMEOUT = 10000;
|
|||||||
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
||||||
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
||||||
|
|
||||||
const AUTOSAVE_KEY = 'HB_editor_autoSaveOn';
|
|
||||||
const BREWKEY = 'HB_newPage_content';
|
const BREWKEY = 'HB_newPage_content';
|
||||||
const STYLEKEY = 'HB_newPage_style';
|
const STYLEKEY = 'HB_newPage_style';
|
||||||
const SNIPKEY = 'HB_newPage_snippets';
|
const SNIPKEY = 'HB_newPage_snippets';
|
||||||
@@ -90,14 +88,21 @@ const EditPage = (props)=>{
|
|||||||
setThemeBundle,
|
setThemeBundle,
|
||||||
HTMLErrors,
|
HTMLErrors,
|
||||||
setHTMLErrors,
|
setHTMLErrors,
|
||||||
|
currentBrew,
|
||||||
setCurrentBrew,
|
setCurrentBrew,
|
||||||
useLocalStorage,
|
useLocalStorage,
|
||||||
BREWKEY,
|
BREWKEY,
|
||||||
STYLEKEY,
|
STYLEKEY,
|
||||||
SNIPKEY,
|
SNIPKEY,
|
||||||
METAKEY,
|
METAKEY,
|
||||||
fetchThemeBundle,
|
hbfm,
|
||||||
hbfm
|
autoSaveEnabled,
|
||||||
|
setAutoSaveEnabled,
|
||||||
|
setWarnUnsavedChanges,
|
||||||
|
trySaveRef,
|
||||||
|
unsavedChangesRef,
|
||||||
|
sandbox,
|
||||||
|
saveGoogle
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { hbfm } from 'hbmarkedwrapper';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||||
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
|
||||||
|
|
||||||
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.js'
|
import useCommonEditPageFunctions from '../../utils/commonEditPageFunctions.js'
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ const SAVE_TIMEOUT = 10000;
|
|||||||
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
||||||
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
||||||
|
|
||||||
const AUTOSAVE_KEY = 'HB_editor_autoSaveOn';
|
|
||||||
const BREWKEY = 'HB_newPage_content';
|
const BREWKEY = 'HB_newPage_content';
|
||||||
const STYLEKEY = 'HB_newPage_style';
|
const STYLEKEY = 'HB_newPage_style';
|
||||||
const SNIPKEY = 'HB_newPage_snippets';
|
const SNIPKEY = 'HB_newPage_snippets';
|
||||||
@@ -67,6 +65,7 @@ const HomePage =(props)=>{
|
|||||||
const editorRef = useRef(null);
|
const editorRef = useRef(null);
|
||||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
||||||
const warnUnsavedTimeout = useRef(null);
|
const warnUnsavedTimeout = useRef(null);
|
||||||
|
const trySaveRef = useRef(null); // CTRL+S listener lives outside React and needs ref to use trySave with latest copy of brew
|
||||||
const unsavedChangesRef = useRef(unsavedChanges);
|
const unsavedChangesRef = useRef(unsavedChanges);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -76,14 +75,20 @@ const HomePage =(props)=>{
|
|||||||
setThemeBundle,
|
setThemeBundle,
|
||||||
HTMLErrors,
|
HTMLErrors,
|
||||||
setHTMLErrors,
|
setHTMLErrors,
|
||||||
|
currentBrew,
|
||||||
setCurrentBrew,
|
setCurrentBrew,
|
||||||
useLocalStorage,
|
useLocalStorage,
|
||||||
BREWKEY,
|
BREWKEY,
|
||||||
STYLEKEY,
|
STYLEKEY,
|
||||||
SNIPKEY,
|
SNIPKEY,
|
||||||
METAKEY,
|
METAKEY,
|
||||||
fetchThemeBundle,
|
hbfm,
|
||||||
hbfm
|
autoSaveEnabled,
|
||||||
|
setAutoSaveEnabled,
|
||||||
|
setWarnUnsavedChanges,
|
||||||
|
trySaveRef,
|
||||||
|
unsavedChangesRef,
|
||||||
|
sandbox
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ const SAVE_TIMEOUT = 10000;
|
|||||||
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
||||||
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
||||||
|
|
||||||
const AUTOSAVE_KEY = 'HB_editor_autoSaveOn';
|
|
||||||
const BREWKEY = 'HB_newPage_content';
|
const BREWKEY = 'HB_newPage_content';
|
||||||
const STYLEKEY = 'HB_newPage_style';
|
const STYLEKEY = 'HB_newPage_style';
|
||||||
const SNIPKEY = 'HB_newPage_snippets';
|
const SNIPKEY = 'HB_newPage_snippets';
|
||||||
@@ -81,14 +80,20 @@ const NewPage = (props)=>{
|
|||||||
setThemeBundle,
|
setThemeBundle,
|
||||||
HTMLErrors,
|
HTMLErrors,
|
||||||
setHTMLErrors,
|
setHTMLErrors,
|
||||||
|
currentBrew,
|
||||||
setCurrentBrew,
|
setCurrentBrew,
|
||||||
useLocalStorage,
|
useLocalStorage,
|
||||||
BREWKEY,
|
BREWKEY,
|
||||||
STYLEKEY,
|
STYLEKEY,
|
||||||
SNIPKEY,
|
SNIPKEY,
|
||||||
METAKEY,
|
METAKEY,
|
||||||
fetchThemeBundle,
|
hbfm,
|
||||||
hbfm
|
autoSaveEnabled,
|
||||||
|
setAutoSaveEnabled,
|
||||||
|
setWarnUnsavedChanges,
|
||||||
|
trySaveRef,
|
||||||
|
unsavedChangesRef,
|
||||||
|
sandbox
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadBrew = ()=>{
|
const loadBrew = ()=>{
|
||||||
|
|||||||
@@ -1,23 +1,36 @@
|
|||||||
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
|
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
||||||
|
|
||||||
|
const AUTOSAVE_KEY = 'HB_editor_autoSaveOn';
|
||||||
|
|
||||||
export default function useCommonEditPageFunctions(dependencies) {
|
export default function useCommonEditPageFunctions(dependencies) {
|
||||||
const {
|
const {
|
||||||
setError,
|
setError,
|
||||||
setThemeBundle,
|
setThemeBundle,
|
||||||
HTMLErrors,
|
HTMLErrors,
|
||||||
setHTMLErrors,
|
setHTMLErrors,
|
||||||
|
currentBrew,
|
||||||
setCurrentBrew,
|
setCurrentBrew,
|
||||||
useLocalStorage,
|
useLocalStorage,
|
||||||
BREWKEY,
|
BREWKEY,
|
||||||
STYLEKEY,
|
STYLEKEY,
|
||||||
SNIPKEY,
|
SNIPKEY,
|
||||||
METAKEY,
|
METAKEY,
|
||||||
fetchThemeBundle,
|
hbfm,
|
||||||
hbfm
|
autoSaveEnabled,
|
||||||
|
setAutoSaveEnabled,
|
||||||
|
setWarnUnsavedChanges,
|
||||||
|
trySaveRef,
|
||||||
|
sandbox,
|
||||||
|
saveGoogle = false,
|
||||||
|
unsavedChangesRef
|
||||||
} = dependencies;
|
} = dependencies;
|
||||||
|
|
||||||
//==--------- Page setup ----------==//
|
//==--------- Page setup ----------==//
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
const autoSavePref = JSON.parse(localStorage.getItem(AUTOSAVE_KEY) ?? true);
|
const autoSavePref = !sandbox && JSON.parse(localStorage.getItem(AUTOSAVE_KEY) ?? true);
|
||||||
setAutoSaveEnabled(autoSavePref);
|
setAutoSaveEnabled(autoSavePref);
|
||||||
|
console.log(autoSavePref)
|
||||||
setWarnUnsavedChanges(!autoSavePref);
|
setWarnUnsavedChanges(!autoSavePref);
|
||||||
setHTMLErrors(hbfm.validate(currentBrew.text));
|
setHTMLErrors(hbfm.validate(currentBrew.text));
|
||||||
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
||||||
|
|||||||
Reference in New Issue
Block a user