Skip to content

Commit 1ab6880

Browse files
committed
feat(PageTabs): add functionality to create new pages with an "Add Page" button
1 parent e46bd0c commit 1ab6880

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/components/ContentWrap.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ export default class ContentWrap extends Component {
10891089
pages={this.props.currentItem.pages}
10901090
currentPageId={this.props.currentItem.currentPageId}
10911091
onTabClick={this.props.onPageSwitch}
1092+
onAddPage={this.props.onAddPage}
10921093
/>
10931094
)}
10941095
<div

src/components/PageTabs.jsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,34 @@ import React from 'preact';
22

33
/**
44
* PageTabs component displays tabs for each page and handles tab switching
5-
*
5+
*
66
* @param {Object} props - Component props
77
* @param {Array} props.pages - Array of page objects
88
* @param {String} props.currentPageId - ID of the currently active page
99
* @param {Function} props.onTabClick - Callback function when a tab is clicked
10+
* @param {Function} props.onAddPage - Callback function when the add page button is clicked
1011
*/
11-
export function PageTabs({ pages, currentPageId, onTabClick }) {
12+
export function PageTabs({ pages, currentPageId, onTabClick, onAddPage }) {
1213
if (!pages || pages.length === 0) {
1314
return null;
1415
}
1516

17+
/**
18+
* Wrapper for the onAddPage callback to properly handle the event object.
19+
* This prevents the synthetic event from being passed to the App's addNewPage method,
20+
* which expects either no parameters or a title string, not an event object.
21+
* Without this wrapper, the event object would cause errors when passed to addNewPage.
22+
*/
23+
const handleAddPage = (e) => {
24+
e.preventDefault();
25+
e.stopPropagation();
26+
if (typeof onAddPage === 'function') {
27+
onAddPage();
28+
}
29+
};
30+
1631
return (
17-
<div className="page-tabs bg-black-500 border-b border-black-700 px-2 py-1 flex overflow-x-auto">
32+
<div className="page-tabs bg-black-500 border-b border-black-700 px-2 py-1 flex overflow-x-auto items-center">
1833
{pages.map(page => (
1934
<button
2035
key={page.id}
@@ -28,6 +43,14 @@ export function PageTabs({ pages, currentPageId, onTabClick }) {
2843
{page.title || 'Untitled'}
2944
</button>
3045
))}
46+
<button
47+
className="ml-2 px-3 py-2 bg-black-600 text-gray-400 hover:bg-black-700 hover:text-gray-300 rounded-lg text-sm font-medium transition-colors duration-200 flex items-center"
48+
onClick={handleAddPage}
49+
title="Add new page"
50+
>
51+
<span className="mr-1 font-bold text-lg leading-none">+</span>
52+
Add Page
53+
</button>
3154
</div>
3255
);
3356
}

src/components/app.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,7 @@ BookLibService.Borrow(id) {
16801680
onSplitUpdate={this.splitUpdateHandler.bind(this)}
16811681
onProFeature={this.proBtnClickHandler.bind(this)}
16821682
onPageSwitch={this.switchToPage.bind(this)}
1683+
onAddPage={this.addNewPage.bind(this)}
16831684
keyboardShortcutsBtnClickHandler={this.handleShortcutsModalOpen.bind(
16841685
this,
16851686
)}

0 commit comments

Comments
 (0)