Skip to content

Commit

Permalink
fix the order not updated
Browse files Browse the repository at this point in the history
Signed-off-by: huongg <[email protected]>
  • Loading branch information
Huongg committed Jun 6, 2024
1 parent 381c261 commit 54cf5ee
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/components/shareable-url-modal/shareable-url-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,28 @@ const ShareableUrlModal = ({ onToggleModal, visible }) => {
}
};

const updateLocalStorageState = () => {
const selectedHostingPlatformVal = {};
if (hostingPlatforms.hasOwnProperty(inputValues.platform)) {
selectedHostingPlatformVal[inputValues.platform] = { ...inputValues };
}
saveLocalStorage(localStorageShareableUrl, selectedHostingPlatformVal);

// filtering out the pairs where the key is in selectedHostingPlatformVal
const localStorageExcludingSelectedPlatform = Object.fromEntries(
Object.entries(hostingPlatformLocalStorageVal).filter(
([key]) => !(key in selectedHostingPlatformVal)
)
);

// set the new state with selectedHostingPlatformVal as the first value and localStorageExcludingSelectedPlatform
const newState = {
...selectedHostingPlatformVal,
...localStorageExcludingSelectedPlatform,
};
setHostingPlatformLocalStorageVal(newState);
};

const handleSubmit = async () => {
setDeploymentState('loading');
setIsLoading(true);
Expand All @@ -155,17 +177,7 @@ const ShareableUrlModal = ({ onToggleModal, visible }) => {
if (request.ok) {
setResponseUrl(response.url);
setDeploymentState('success');

const hostingPlatformVal = {};
if (hostingPlatforms.hasOwnProperty(inputValues.platform)) {
hostingPlatformVal[inputValues.platform] = { ...inputValues };
}
saveLocalStorage(localStorageShareableUrl, hostingPlatformVal);
const newState = {
...hostingPlatformVal,
...hostingPlatformLocalStorageVal,
};
setHostingPlatformLocalStorageVal(newState);
updateLocalStorageState();
} else {
setResponseUrl(null);
setResponseError(response.message || 'Error occurred!');
Expand Down

0 comments on commit 54cf5ee

Please sign in to comment.