mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 20:23:39 +00:00
change page works, added change zoom via input too
This commit is contained in:
@@ -88,7 +88,8 @@ const BrewRenderer = (props)=>{
|
|||||||
iframe.contentWindow.document.querySelector('.brewRenderer');
|
iframe.contentWindow.document.querySelector('.brewRenderer');
|
||||||
if (brewRenderer) {
|
if (brewRenderer) {
|
||||||
const pages = brewRenderer.querySelectorAll('.page');
|
const pages = brewRenderer.querySelectorAll('.page');
|
||||||
if (pageNumber > pages.length) {
|
if (pageNumber + 1 > pages.length) {
|
||||||
|
console.log(pageNumber, pages.length);
|
||||||
console.log('page not found');
|
console.log('page not found');
|
||||||
} else {
|
} else {
|
||||||
pages[pageNumber].scrollIntoView({ block: 'start' });
|
pages[pageNumber].scrollIntoView({ block: 'start' });
|
||||||
@@ -234,6 +235,11 @@ const BrewRenderer = (props)=>{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlePageChange = (pageNumber) => {
|
||||||
|
// Scroll to the desired page
|
||||||
|
scrollToPage(pageNumber);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/*render dummy page while iFrame is mounting.*/}
|
{/*render dummy page while iFrame is mounting.*/}
|
||||||
@@ -251,7 +257,7 @@ const BrewRenderer = (props)=>{
|
|||||||
contentDidMount={frameDidMount}
|
contentDidMount={frameDidMount}
|
||||||
onClick={()=>{emitClick();}}
|
onClick={()=>{emitClick();}}
|
||||||
>
|
>
|
||||||
<ToolBar updateZoom={updateZoom} />
|
<ToolBar updateZoom={updateZoom} currentPage={state.viewablePageNumber} onPageChange={handlePageChange} totalPages={rawPages.length}/>
|
||||||
<div className={'brewRenderer'}
|
<div className={'brewRenderer'}
|
||||||
onScroll={handleScroll}
|
onScroll={handleScroll}
|
||||||
onKeyDown={handleControlKeys}
|
onKeyDown={handleControlKeys}
|
||||||
|
|||||||
@@ -3,18 +3,33 @@ const React = require('react');
|
|||||||
const { useState, useRef, useEffect } = React;
|
const { useState, useRef, useEffect } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const ToolBar = ({updateZoom}) => {
|
const ToolBar = ({ updateZoom, currentPage, onPageChange, totalPages }) => {
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
currentPage: 1,
|
currentPage: currentPage,
|
||||||
totalPages: 10,
|
totalPages: totalPages,
|
||||||
zoomLevel: 100,
|
zoomLevel: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [pageNumberInput, setPageNumberInput] = useState(
|
||||||
|
state.currentPage + 1
|
||||||
|
);
|
||||||
|
const [zoomInput, setZoomInput] = useState(state.zoomLevel);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(`Zoom to: ${state.zoomLevel}`);
|
console.log(`Zoom to: ${state.zoomLevel}`);
|
||||||
updateZoom(state.zoomLevel);
|
updateZoom(state.zoomLevel);
|
||||||
}, [state.zoomLevel]);
|
}, [state.zoomLevel]);
|
||||||
|
|
||||||
|
// Update currentPage whenever page prop changes
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(`page number from props ${currentPage}`);
|
||||||
|
setState((prevState) => ({
|
||||||
|
...prevState,
|
||||||
|
currentPage: currentPage,
|
||||||
|
}));
|
||||||
|
setPageNumberInput(currentPage + 1);
|
||||||
|
}, [currentPage]);
|
||||||
|
|
||||||
const setZoomLevel = (direction) => {
|
const setZoomLevel = (direction) => {
|
||||||
let zoomLevel = state.zoomLevel;
|
let zoomLevel = state.zoomLevel;
|
||||||
if (direction === 'in') {
|
if (direction === 'in') {
|
||||||
@@ -29,17 +44,22 @@ const ToolBar = ({updateZoom}) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollToPage = (direction) => {
|
const handleInputChange = (value, type) => {
|
||||||
let currentPage = state.currentPage;
|
// Remove the "%" symbol from the input value
|
||||||
if (direction === 'next') {
|
const newValue = parseInt(value.replace('%', ''), 10);
|
||||||
currentPage += 1;
|
|
||||||
} else {
|
// Check the type of input (zoom or page)
|
||||||
currentPage = currentPage - 1;
|
if (type === 'zoom') {
|
||||||
|
// Check if zoom level is within the allowed range
|
||||||
|
if (newValue >= 10 && newValue <= 300) {
|
||||||
|
setZoomInput(newValue + '%'); // Add "%" back to the value
|
||||||
|
}
|
||||||
|
} else if (type === 'page') {
|
||||||
|
// Check if page number is within the allowed range
|
||||||
|
if (newValue >= 1 && newValue <= totalPages) {
|
||||||
|
setPageNumberInput(newValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setState((prevState) => ({
|
|
||||||
...prevState,
|
|
||||||
currentPage,
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -53,7 +73,27 @@ const ToolBar = ({updateZoom}) => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span className="currentZoom">{state.zoomLevel}%</span>
|
<div className="tool">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="zoom"
|
||||||
|
min={10}
|
||||||
|
max={300}
|
||||||
|
value={zoomInput}
|
||||||
|
onChange={(e) => handleInputChange(e.target.value, 'zoom')}
|
||||||
|
onBlur={(e) => {
|
||||||
|
const newZoomLevel = parseInt(
|
||||||
|
e.target.value.replace('%', ''),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
if (newZoomLevel !== state.zoomLevel) {
|
||||||
|
updateZoom(newZoomLevel);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span>%</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="tool">
|
<div className="tool">
|
||||||
<button
|
<button
|
||||||
onClick={() => setZoomLevel('out')}
|
onClick={() => setZoomLevel('out')}
|
||||||
@@ -66,19 +106,38 @@ const ToolBar = ({updateZoom}) => {
|
|||||||
<div className="tool">
|
<div className="tool">
|
||||||
<button
|
<button
|
||||||
className="previousPage"
|
className="previousPage"
|
||||||
onClick={() => scrollToPage('previous')}
|
onClick={() => {
|
||||||
disabled={state.currentPage <= 1}
|
console.log(`page is ${state.currentPage}`);
|
||||||
|
onPageChange(state.currentPage - 1);
|
||||||
|
}}
|
||||||
|
disabled={state.currentPage === 0}
|
||||||
>
|
>
|
||||||
<i className="fas fa-arrow-left"></i>
|
<i className="fas fa-arrow-left"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span className="currentPage">{state.currentPage}</span>
|
<input
|
||||||
|
type="number"
|
||||||
|
name="page"
|
||||||
|
min={1}
|
||||||
|
max={state.totalPages}
|
||||||
|
id="pageInput"
|
||||||
|
value={pageNumberInput}
|
||||||
|
onChange={(e) => handleInputChange(e.target.value, 'page')}
|
||||||
|
onBlur={(e) => {
|
||||||
|
parseInt(pageNumberInput) === state.currentPage + 1 ||
|
||||||
|
onPageChange(parseInt(pageNumberInput) - 1);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="tool">
|
<div className="tool">
|
||||||
<button
|
<button
|
||||||
className="nextPage"
|
className="nextPage"
|
||||||
onClick={() => scrollToPage('next')}
|
onClick={() => {
|
||||||
disabled={state.currentPage >= 10}
|
console.log(`page is ${state.currentPage}`);
|
||||||
|
onPageChange(state.currentPage + 1);
|
||||||
|
}}
|
||||||
|
disabled={state.currentPage + 1 === state.totalPages}
|
||||||
>
|
>
|
||||||
<i className="fas fa-arrow-right"></i>
|
<i className="fas fa-arrow-right"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -13,12 +13,12 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: baseline;
|
align-items: center;
|
||||||
column-gap: 15px;
|
column-gap: 15px;
|
||||||
row-gap: 5px;
|
row-gap: 5px;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|
||||||
span {
|
input {
|
||||||
background: #eee;
|
background: #eee;
|
||||||
font-family: 'Open Sans', sans-serif;
|
font-family: 'Open Sans', sans-serif;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
color: #000;
|
color: #000;
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
width: 50px;
|
height:1.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tool {
|
.tool {
|
||||||
|
|||||||
Reference in New Issue
Block a user