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

Commit

Permalink
fix: restore page-add functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed May 24, 2018
1 parent 65d5ef3 commit cda183e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
7 changes: 5 additions & 2 deletions src/component/page-list/page-add-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ export class PageAddButton extends React.Component {
e.preventDefault();
const store = ViewStore.getInstance();
const page = store.addNewPage();
// store.openPage(page.getId());
page.setNameState(EditState.Editing);

if (page) {
store.setActivePage(page);
page.setNameState(EditState.Editing);
}
}

public render(): JSX.Element {
Expand Down
6 changes: 3 additions & 3 deletions src/component/page-list/page-tile-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class PageTileContainer extends React.Component<PageTileContainerProps> {
}

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

const target = e.target as HTMLElement;

if (!this.props.focused) {
// store.openPage(this.props.page.getId());
store.setActivePage(this.props.page);
}

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

// store.openPage(this.props.page.getId());
store.setActivePage(this.props.page);
store.setActiveView(next);
}

Expand Down
4 changes: 2 additions & 2 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function createWindow(): Promise<void> {
case ServerMessageType.CreateNewFileRequest: {
const path = await showSaveDialog({
title: 'Create New Alva File',
defaultPath: 'Untitled.alva',
defaultPath: 'Untitled Project.alva',
filters: [
{
name: 'Alva File',
Expand All @@ -105,7 +105,7 @@ async function createWindow(): Promise<void> {

if (path) {
const project = Project.create({
name: 'Untitled',
name: 'Untitled Page',
path
});

Expand Down
22 changes: 14 additions & 8 deletions src/store/view-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,25 @@ export class ViewStore {
return ViewStore.INSTANCE;
}

public addNewPage(): Page {
const project = this.currentProject as Project;
public addNewPage(): Page | undefined {
const project = this.currentProject;

// Page refs register with their project automatically
// via side effects
const pageRef = Page.create({
name: 'New Page',
if (!project) {
return;
}

const name = 'Untitled Page';

const count = project.getPages().filter(p => p.getName().startsWith(name)).length;

const page = Page.create({
name: `${name} ${count + 1}`,
styleguide: project.getStyleguide()
});

// pageRef.createFile();
project.addPage(page);

return pageRef;
return page;
}

/**
Expand Down

0 comments on commit cda183e

Please sign in to comment.