Skip to content

Commit

Permalink
Prompt the user to delete the profile when deleting its last site
Browse files Browse the repository at this point in the history
  • Loading branch information
iTrooz committed Nov 16, 2023
1 parent 1fb74e6 commit 1141f5d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
12 changes: 10 additions & 2 deletions extension/src/sites/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,16 @@ <h5 class="modal-title" id="site-remove-label">Remove web app</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to remove this web app? App data will <strong>not</strong> be
removed, but you can remove them through the app browser or by deleting app's profile.
Are you sure you want to remove this web app?
<div id="site-remove-not-last">
Other apps are present in this profile, so app data will <strong>not</strong> be
removed, but you can remove it by deleting the profile.
</div>
<div id="site-remove-last">
This is the last app in this profile, so you can choose to delete it, and the associated app data
<br>
<input id="site-remove-last-checkbox" type="checkbox" checked> Delete profile & app data</input>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
Expand Down
38 changes: 30 additions & 8 deletions extension/src/sites/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,31 @@ async function createSiteList () {

const removeElement = siteElement.querySelector('#sites-list-template-remove')
removeElement.addEventListener('click', () => {

Check failure on line 369 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Block must not be padded by blank lines

const lastSiteInProfile = profiles[site.profile].sites.length <= 1;

Check failure on line 371 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon

document.getElementById('site-remove-button').onclick = async function () {
this.disabled = true
this.innerText = 'Removing...'

const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'UninstallSite',
params: { id: site.ulid }
})

if (response.type === 'Error') throw new Error(response.data)
if (response.type !== 'SiteUninstalled') throw new Error(`Received invalid response type: ${response.type}`)

Check failure on line 376 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
let deleteProfileCheckbox = document.getElementById("site-remove-last-checkbox");

Check failure on line 377 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

'deleteProfileCheckbox' is never reassigned. Use 'const' instead

Check failure on line 377 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

Check failure on line 377 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon
if (lastSiteInProfile && deleteProfileCheckbox.checked) {
const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'RemoveProfile',
params: { id: site.profile }
})

Check failure on line 383 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
if (response.type === 'Error') throw new Error(response.data)
if (response.type !== 'ProfileRemoved') throw new Error(`Received invalid response type: ${response.type}`)
} else {
const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'UninstallSite',
params: { id: site.ulid }
})

Check failure on line 391 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
if (response.type === 'Error') throw new Error(response.data)
if (response.type !== 'SiteUninstalled') throw new Error(`Received invalid response type: ${response.type}`)
}

this.disabled = true
this.innerText = 'Removed!'
Expand All @@ -388,6 +402,14 @@ async function createSiteList () {
}, 5000)
}

if (lastSiteInProfile) {
document.getElementById('site-remove-last').hidden = false;

Check failure on line 406 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon
document.getElementById('site-remove-not-last').hidden = true;

Check failure on line 407 in extension/src/sites/manage.js

View workflow job for this annotation

GitHub Actions / Lint

Extra semicolon
} else {
document.getElementById('site-remove-last').hidden = true;
document.getElementById('site-remove-not-last').hidden = false;
}

Modal.getOrCreateInstance(document.getElementById('site-remove-modal')).show()
})
removeElement.removeAttribute('id')
Expand Down

0 comments on commit 1141f5d

Please sign in to comment.