From 4fcdf9b99f67c58f3205e2decc6a489aa766ed32 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 13 May 2021 09:05:23 -0400 Subject: [PATCH] Allow URLs to be passed for the project input --- src/views/studio/lib/studio-project-actions.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/views/studio/lib/studio-project-actions.js b/src/views/studio/lib/studio-project-actions.js index a1b1c9c27..14b23528b 100644 --- a/src/views/studio/lib/studio-project-actions.js +++ b/src/views/studio/lib/studio-project-actions.js @@ -59,8 +59,17 @@ const generateProjectListItem = (postBody, infoBody) => ({ username: infoBody.author.username, avatar: infoBody.author.profile.images }); - -const addProject = projectId => ((dispatch, getState) => new Promise((resolve, reject) => { + +const addProject = projectIdOrUrl => ((dispatch, getState) => new Promise((resolve, reject) => { + // Strings are passed by the open input, numbers by the project browser + let projectId = projectIdOrUrl; + if (typeof projectIdOrUrl === 'string') { + const matches = projectIdOrUrl.match(/(\d+)/g); + if (!matches) return reject(Errors.UNKNOWN_PROJECT); + // Take the last match, in case we are on localhost and there are port numbers, e.g. + projectId = parseInt(matches[matches.length - 1], 10); + } + const state = getState(); const studioId = selectStudioId(state); const token = selectToken(state);