Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit cda183e

Browse files
committed
fix: restore page-add functionality
1 parent 65d5ef3 commit cda183e

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/component/page-list/page-add-button.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ export class PageAddButton extends React.Component {
1010
e.preventDefault();
1111
const store = ViewStore.getInstance();
1212
const page = store.addNewPage();
13-
// store.openPage(page.getId());
14-
page.setNameState(EditState.Editing);
13+
14+
if (page) {
15+
store.setActivePage(page);
16+
page.setNameState(EditState.Editing);
17+
}
1518
}
1619

1720
public render(): JSX.Element {

src/component/page-list/page-tile-container.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ export class PageTileContainer extends React.Component<PageTileContainerProps> {
4141
}
4242

4343
protected handleClick(e: React.MouseEvent<HTMLElement>): void {
44-
// const store = Store.getInstance();
44+
const store = ViewStore.getInstance();
4545

4646
const target = e.target as HTMLElement;
4747

4848
if (!this.props.focused) {
49-
// store.openPage(this.props.page.getId());
49+
store.setActivePage(this.props.page);
5050
}
5151

5252
if (this.props.focused && target.matches('[data-title]')) {
@@ -65,7 +65,7 @@ export class PageTileContainer extends React.Component<PageTileContainerProps> {
6565
? Types.AlvaView.PageDetail
6666
: Types.AlvaView.Pages;
6767

68-
// store.openPage(this.props.page.getId());
68+
store.setActivePage(this.props.page);
6969
store.setActiveView(next);
7070
}
7171

src/electron/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async function createWindow(): Promise<void> {
9494
case ServerMessageType.CreateNewFileRequest: {
9595
const path = await showSaveDialog({
9696
title: 'Create New Alva File',
97-
defaultPath: 'Untitled.alva',
97+
defaultPath: 'Untitled Project.alva',
9898
filters: [
9999
{
100100
name: 'Alva File',
@@ -105,7 +105,7 @@ async function createWindow(): Promise<void> {
105105

106106
if (path) {
107107
const project = Project.create({
108-
name: 'Untitled',
108+
name: 'Untitled Page',
109109
path
110110
});
111111

src/store/view-store.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,25 @@ export class ViewStore {
137137
return ViewStore.INSTANCE;
138138
}
139139

140-
public addNewPage(): Page {
141-
const project = this.currentProject as Project;
140+
public addNewPage(): Page | undefined {
141+
const project = this.currentProject;
142142

143-
// Page refs register with their project automatically
144-
// via side effects
145-
const pageRef = Page.create({
146-
name: 'New Page',
143+
if (!project) {
144+
return;
145+
}
146+
147+
const name = 'Untitled Page';
148+
149+
const count = project.getPages().filter(p => p.getName().startsWith(name)).length;
150+
151+
const page = Page.create({
152+
name: `${name} ${count + 1}`,
147153
styleguide: project.getStyleguide()
148154
});
149155

150-
// pageRef.createFile();
156+
project.addPage(page);
151157

152-
return pageRef;
158+
return page;
153159
}
154160

155161
/**

0 commit comments

Comments
 (0)