diff --git a/bin/configure-fastly.js b/bin/configure-fastly.js index a935b906e..74399a0d3 100644 --- a/bin/configure-fastly.js +++ b/bin/configure-fastly.js @@ -176,7 +176,7 @@ async.auto({ if (err) throw new Error(err); if (process.env.FASTLY_ACTIVATE_CHANGES) { fastly.activateVersion(results.version, function (e, resp) { - if (err) throw new Error(e); + if (e) throw new Error(e); process.stdout.write('Successfully configured and activated version ' + resp.number + '\n'); if (process.env.FASTLY_PURGE_ALL) { fastly.purgeAll(FASTLY_SERVICE_ID, function (error) { diff --git a/src/routes.json b/src/routes.json index 5a6e7fedb..d4a6e8bb6 100644 --- a/src/routes.json +++ b/src/routes.json @@ -193,7 +193,7 @@ }, { "name": "preview", - "pattern": "^/preview/(*)/?$", + "pattern": "^/preview(/editor|(/\\d+(/editor|/fullscreen)?)?)?/?$", "routeAlias": "/preview/?$", "view": "preview/preview", "title": "Scratch 3.0 Preview" diff --git a/src/views/preview/preview.jsx b/src/views/preview/preview.jsx index 426527846..fb40c2cff 100644 --- a/src/views/preview/preview.jsx +++ b/src/views/preview/preview.jsx @@ -54,31 +54,19 @@ class Preview extends React.Component { } } initState () { - let pathname = window.location.pathname.toLowerCase(); - const params = { + const pathname = window.location.pathname.toLowerCase(); + const parts = pathname.split('/').filter(Boolean); + // parts[0]: 'preview' + // parts[1]: either :id or 'editor' + // parts[2]: undefined if no :id, otherwise either 'editor' or 'fullscreen' + return { editable: false, favoriteCount: 0, - inEditor: false, - isFullScreen: false, + inEditor: parts.indexOf('editor') !== -1, + isFullScreen: parts.indexOf('fullscreen') !== -1, loveCount: 0, - projectId: null + projectId: parts[1] === 'editor' ? null : parts[1] }; - if (pathname[pathname.length - 1] === '/') { - pathname = pathname.substring(0, pathname.length - 1); - } - const path = pathname.split('/'); - if (path[path.length - 1] === 'editor' || path[path.length - 1] === 'preview') { - params.inEditor = true; - path.pop(); - } - if (path[path.length - 1] === 'fullscreen') { - params.isFullScreen = true; - path.pop(); - } - if (/^\d+$/.test(path[path.length - 1])) { - params.projectId = path.pop(); - } - return params; } handleFavoriteToggle () { this.props.setFavedStatus(