Allow URLs to be passed for the project input

This commit is contained in:
Paul Kaplan 2021-05-13 09:05:23 -04:00
parent 4f6a583277
commit 4fcdf9b99f

View file

@ -60,7 +60,16 @@ const generateProjectListItem = (postBody, infoBody) => ({
avatar: infoBody.author.profile.images 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 state = getState();
const studioId = selectStudioId(state); const studioId = selectStudioId(state);
const token = selectToken(state); const token = selectToken(state);