Skip to content

Commit

Permalink
Fix New Sandbox Modal (#1194)
Browse files Browse the repository at this point in the history
* fix modal

*  lint :(

* Update sapper.js
  • Loading branch information
SaraVieira authored and CompuIves committed Oct 23, 2018
1 parent 6951e8f commit 0429f52
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const usedTemplates = sortBy(

const TEMPLATE_BASE_WIDTH = 150;
const MAIN_TEMPLATE_BASE_WIDTH = 190;
const SERVER_TEMPLATE_BASE_WIDTH = 150; // 150

export default class Modal extends React.PureComponent {
selectTemplate = template => {
Expand All @@ -39,21 +38,21 @@ export default class Modal extends React.PureComponent {
const paddedWidth = width;
const mainTemplates = usedTemplates.filter(t => t.main && !t.isServer);
const otherTemplates = usedTemplates.filter(t => !t.main && !t.isServer);
const serverTemplates = usedTemplates.filter(t => t.isServer);
const mainServerTemplates = usedTemplates.filter(t => t.main && t.isServer);
const otherServerTemplates = usedTemplates.filter(
t => !t.main && t.isServer
);

const mainTemplatesPerRow = Math.max(
1,
paddedWidth / MAIN_TEMPLATE_BASE_WIDTH
);
const templatesPerRow = Math.max(1, paddedWidth / TEMPLATE_BASE_WIDTH);
const serverTemplatesPerRow = Math.max(
1,
paddedWidth / SERVER_TEMPLATE_BASE_WIDTH
);

const mainRows = chunk(mainTemplates, mainTemplatesPerRow);
const rows = chunk(otherTemplates, templatesPerRow);
const serverRows = chunk(serverTemplates, serverTemplatesPerRow);
const mainServerRows = chunk(mainServerTemplates, mainTemplatesPerRow);
const serverRows = chunk(otherServerTemplates, templatesPerRow);

return (
<Container
Expand All @@ -64,7 +63,7 @@ export default class Modal extends React.PureComponent {
<InnerContainer forking={forking} closing={closing}>
<Title>Client Templates</Title>
{mainRows.map((ts, i) => (
// eslint-disable-next-line
// eslint-disable-next-line react/no-array-index-key
<Templates key={i}>
{ts.map(t => (
<Template
Expand All @@ -78,7 +77,7 @@ export default class Modal extends React.PureComponent {
))}

{rows.map((ts, i) => (
// eslint-disable-next-line
// eslint-disable-next-line react/no-array-index-key
<Templates style={{ fontSize: '.8rem' }} key={i}>
{ts.map(t => (
<Template
Expand All @@ -93,12 +92,27 @@ export default class Modal extends React.PureComponent {
))}

<Title>Server Templates</Title>
{mainServerRows.map((ts, i) => (
// eslint-disable-next-line react/no-array-index-key
<Templates key={i}>
{ts.map(t => (
<Template
width={Math.floor(paddedWidth / mainTemplatesPerRow - 16)}
key={t.name}
template={t}
selectTemplate={this.selectTemplate}
/>
))}
</Templates>
))}

{serverRows.map((ts, i) => (
// eslint-disable-next-line
<Templates style={{ fontSize: '.9rem' }} key={i}>
// eslint-disable-next-line react/no-array-index-key
<Templates style={{ fontSize: '.8rem' }} key={i}>
{ts.map(t => (
<Template
width={Math.floor(paddedWidth / serverTemplatesPerRow - 16)}
small
width={Math.floor(paddedWidth / templatesPerRow - 16)}
key={t.name}
template={t}
selectTemplate={this.selectTemplate}
Expand Down
1 change: 1 addition & 0 deletions packages/common/templates/gatsby.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export default new Template(
isServer: true,
mainFile: ['/src/pages/index.js'],
showOnHomePage: true,
main: true,
}
);
1 change: 1 addition & 0 deletions packages/common/templates/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export default new Template(
mainFile: ['/pages/index.js'],
backgroundColor: decorateSelector(() => '#000000'),
showOnHomePage: true,
main: true,
}
);
1 change: 1 addition & 0 deletions packages/common/templates/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default new Template(
{
isServer: true,
showOnHomePage: true,
main: true,
mainFile: ['/pages/index.vue', '/pages/index.js', '/src/pages/index.js'],
}
);
1 change: 1 addition & 0 deletions packages/common/templates/nuxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export default new Template(
isServer: true,
mainFile: ['/pages/index.vue'],
showOnHomePage: true,
main: true,
}
);
2 changes: 1 addition & 1 deletion packages/common/templates/sapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export default new Template(
{
isServer: true,
mainFile: ['/src/routes/index.html'],
showOnHomePage: false,
showOnHomePage: true,
}
);
1 change: 0 additions & 1 deletion packages/homepage/content/docs/2-importing.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ We infer sandbox settings based on several files in a repository.
| Template - React | If `package.json` dependencies contains `react-scripts`. |
| Template - React-Typescript | If `package.json` dependencies contains `react-scripts-ts`. |
| Template - Svelte | If `package.json` dependencies contains `svelte`. |
| Template - Node | If `package.json` dependencies contains `ember-cli`. |

Additionally, you may specify a `template` property in your `./sandbox.config.json` file.

Expand Down

0 comments on commit 0429f52

Please sign in to comment.