This repository was archived by the owner on Oct 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +24
-15
lines changed Expand file tree Collapse file tree 4 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,11 @@ export class PageAddButton extends React.Component {
10
10
e . preventDefault ( ) ;
11
11
const store = ViewStore . getInstance ( ) ;
12
12
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
+ }
15
18
}
16
19
17
20
public render ( ) : JSX . Element {
Original file line number Diff line number Diff line change @@ -41,12 +41,12 @@ export class PageTileContainer extends React.Component<PageTileContainerProps> {
41
41
}
42
42
43
43
protected handleClick ( e : React . MouseEvent < HTMLElement > ) : void {
44
- // const store = Store .getInstance();
44
+ const store = ViewStore . getInstance ( ) ;
45
45
46
46
const target = e . target as HTMLElement ;
47
47
48
48
if ( ! this . props . focused ) {
49
- // store.openPage (this.props.page.getId() );
49
+ store . setActivePage ( this . props . page ) ;
50
50
}
51
51
52
52
if ( this . props . focused && target . matches ( '[data-title]' ) ) {
@@ -65,7 +65,7 @@ export class PageTileContainer extends React.Component<PageTileContainerProps> {
65
65
? Types . AlvaView . PageDetail
66
66
: Types . AlvaView . Pages ;
67
67
68
- // store.openPage (this.props.page.getId() );
68
+ store . setActivePage ( this . props . page ) ;
69
69
store . setActiveView ( next ) ;
70
70
}
71
71
Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ async function createWindow(): Promise<void> {
94
94
case ServerMessageType . CreateNewFileRequest : {
95
95
const path = await showSaveDialog ( {
96
96
title : 'Create New Alva File' ,
97
- defaultPath : 'Untitled.alva' ,
97
+ defaultPath : 'Untitled Project .alva' ,
98
98
filters : [
99
99
{
100
100
name : 'Alva File' ,
@@ -105,7 +105,7 @@ async function createWindow(): Promise<void> {
105
105
106
106
if ( path ) {
107
107
const project = Project . create ( {
108
- name : 'Untitled' ,
108
+ name : 'Untitled Page ' ,
109
109
path
110
110
} ) ;
111
111
Original file line number Diff line number Diff line change @@ -137,19 +137,25 @@ export class ViewStore {
137
137
return ViewStore . INSTANCE ;
138
138
}
139
139
140
- public addNewPage ( ) : Page {
141
- const project = this . currentProject as Project ;
140
+ public addNewPage ( ) : Page | undefined {
141
+ const project = this . currentProject ;
142
142
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 } ` ,
147
153
styleguide : project . getStyleguide ( )
148
154
} ) ;
149
155
150
- // pageRef.createFile( );
156
+ project . addPage ( page ) ;
151
157
152
- return pageRef ;
158
+ return page ;
153
159
}
154
160
155
161
/**
You can’t perform that action at this time.
0 commit comments