Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions static/gui/app-store/002.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
</article>
</a>

<a class="app-card-link app-card-link--inactive" href="#" aria-disabled="true">
<article class="app-card app-card--disabled" data-app-id="999-999">
<a class="app-card-link" href="#">
<article class="app-card" data-app-id="999-999">
<div class="app-card__icon-wrapper">
<img class="app-card__icon" src="apps/999-999/logo.png" alt="Add new app" style="opacity: 0.4; filter: drop-shadow(2px 4px 1px black) invert(0.5);">
</div>
Expand Down
64 changes: 46 additions & 18 deletions static/gui/app-store/002b.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,34 @@
<div id="apps-container" class="apps-container app-store-grid"></div>

<script>
function toggleAppInstallation(appId) {
if (appId === '999-999') return;
const appInstalled = localStorage.getItem(appId) === 'added';
localStorage.setItem(appId, appInstalled ? '' : 'added' );
// Removed updateHomeScreen() call here, as window.addEventListener('storage') will handle it
const ADD_APP_ID = '999-999';

function isAddAppAlwaysVisible() {
return window.location.pathname.includes('/app-store/006');
}

function isAddAppEnabled() {
return localStorage.getItem(ADD_APP_ID) !== 'removed';
}

function toggleAppInstallation(appId, shouldEnable) {
if (appId === ADD_APP_ID) {
if (isAddAppAlwaysVisible()) {
localStorage.setItem(ADD_APP_ID, 'added');
} else {
localStorage.setItem(ADD_APP_ID, shouldEnable ? 'added' : 'removed');
}
updateHomeScreen();
return;
}

if (shouldEnable) {
localStorage.setItem(appId, 'added');
} else {
localStorage.removeItem(appId);
}

updateHomeScreen();
}

function getAppLink(appId) {
Expand All @@ -54,7 +77,7 @@
return '../app-store/apps/002-001/fetch.html';
case '002-002':
return 'http://hbnb.local:81';
case '999-999':
case ADD_APP_ID:
return '../app-store/002b.html';
default:
return '#';
Expand All @@ -73,28 +96,34 @@
const appsContainer = document.getElementById('apps-container');
appsContainer.innerHTML = ''; // Clear existing apps

const appIds = ['002-001', '002-002', '999-999']; // Using class-based IDs
const appIds = ['002-001', '002-002', ADD_APP_ID];
appIds.forEach(appId => {
const isPlaceholder = appId === ADD_APP_ID;
const appInstalled = localStorage.getItem(appId) === 'added';
const addAppAlwaysVisible = isAddAppAlwaysVisible();
const addAppEnabled = addAppAlwaysVisible || isAddAppEnabled();
const checkboxShouldBeChecked = isPlaceholder ? addAppEnabled : appInstalled;
const appElement = document.createElement('a');
const isPlaceholder = appId === '999-999';
appElement.href = getAppLink(appId); // Set the hyperlink
appElement.className = `app-card-link${isPlaceholder ? ' app-card-link--inactive' : ''}`;
appElement.href = getAppLink(appId);
appElement.className = 'app-card-link';
appElement.dataset.appId = appId;
appElement.draggable = true;
appElement.style.cursor = isPlaceholder ? 'default' : 'pointer';
if (isPlaceholder) {
appElement.style.cursor = 'pointer';

if (isPlaceholder && !addAppEnabled) {
appElement.setAttribute('aria-disabled', 'true');
} else {
appElement.removeAttribute('aria-disabled');
}

const toggleAttributes = [];
if (appInstalled || isPlaceholder) {
if (checkboxShouldBeChecked) {
toggleAttributes.push('checked');
}
if (isPlaceholder) {
if (isPlaceholder && addAppAlwaysVisible) {
toggleAttributes.push('disabled');
}
const cardClasses = `app-card${isPlaceholder ? ' app-card--disabled' : ''}`;
const cardClasses = 'app-card';
const altText = isPlaceholder ? 'Add new app' : `Hβnβ entertainment app icon ${appId}`;

appElement.innerHTML = `
Expand All @@ -112,11 +141,10 @@
appsContainer.appendChild(appElement);
});

// Re-attach click listeners to newly created checkboxes
const checkboxes = document.querySelectorAll('.app-checkbox');
checkboxes.forEach(checkbox => {
checkbox.addEventListener('click', function() {
toggleAppInstallation(this.id);
checkbox.addEventListener('change', function() {
toggleAppInstallation(this.id, this.checked);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions static/gui/app-store/003.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
</article>
</a>

<a class="app-card-link app-card-link--inactive" href="#" aria-disabled="true">
<article class="app-card app-card--disabled" data-app-id="999-999">
<a class="app-card-link" href="#">
<article class="app-card" data-app-id="999-999">
<div class="app-card__icon-wrapper">
<img class="app-card__icon" src="apps/999-999/logo.png" alt="Add new app" style="opacity: 0.4; filter: drop-shadow(2px 4px 1px black) invert(0.5);">
</div>
Expand Down
4 changes: 2 additions & 2 deletions static/gui/app-store/004.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
</article>
</a>

<a class="app-card-link app-card-link--inactive" href="#" aria-disabled="true">
<article class="app-card app-card--disabled" data-app-id="999-999">
<a class="app-card-link" href="#">
<article class="app-card" data-app-id="999-999">
<div class="app-card__icon-wrapper">
<img class="app-card__icon" src="apps/999-999/logo.png" alt="Add new app" style="opacity: 0.4; filter: drop-shadow(2px 4px 1px black) invert(0.5);">
</div>
Expand Down
4 changes: 2 additions & 2 deletions static/gui/app-store/005.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
</article>
</a>

<a class="app-card-link app-card-link--inactive" href="#" aria-disabled="true">
<article class="app-card app-card--disabled" data-app-id="999-999">
<a class="app-card-link" href="#">
<article class="app-card" data-app-id="999-999">
<div class="app-card__icon-wrapper">
<img class="app-card__icon" src="apps/999-999/logo.png" alt="Add new app" style="opacity: 0.4; filter: drop-shadow(2px 4px 1px black) invert(0.5);">
</div>
Expand Down
4 changes: 2 additions & 2 deletions static/gui/app-store/006.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
</article>
</a>

<a class="app-card-link app-card-link--inactive" href="#" aria-disabled="true">
<article class="app-card app-card--disabled" data-app-id="999-999">
<a class="app-card-link" href="#">
<article class="app-card" data-app-id="999-999">
<div class="app-card__icon-wrapper">
<img class="app-card__icon" src="apps/999-999/logo.png" alt="Add new app" style="opacity: 0.4; filter: drop-shadow(2px 4px 1px black) invert(0.5);">
</div>
Expand Down
84 changes: 72 additions & 12 deletions static/gui/app-store/js/app-toggle.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,89 @@
(function () {
const ADD_APP_ID = '999-999';
const ADD_APP_REMOVED = 'removed';
const ADD_APP_ADDED = 'added';
const path = window.location.pathname;
const isProtectedContext =
path.includes('/app-store/006') || path.includes('/dashboard/006');

function isAddAppEnabled() {
if (isProtectedContext) {
return true;
}

return localStorage.getItem(ADD_APP_ID) !== ADD_APP_REMOVED;
}

function applyAddAppState(card) {
const checkbox = card.querySelector('.app-checkbox');
if (!checkbox) {
return;
}

const link = card.closest('.app-card-link');
const enabled = isAddAppEnabled();
const effectiveEnabled = isProtectedContext ? true : enabled;

checkbox.checked = effectiveEnabled;
checkbox.disabled = isProtectedContext;

card.classList.remove('app-card--disabled');

if (link) {
link.classList.remove('app-card-link--inactive');
if (effectiveEnabled) {
link.removeAttribute('aria-disabled');
} else {
link.setAttribute('aria-disabled', 'true');
}
}
}

function syncCheckboxState(card) {
const appId = card.dataset.appId;
const checkbox = card.querySelector('.app-checkbox');
if (!appId || !checkbox) {
return;
}

const storedValue = localStorage.getItem(appId);
const isInstalled = storedValue === 'added' || (appId === '999-999' && storedValue !== 'removed');
if (appId === ADD_APP_ID) {
applyAddAppState(card);
return;
}

checkbox.checked = appId === '999-999' ? true : isInstalled;
const storedValue = localStorage.getItem(appId);
const isInstalled = storedValue === ADD_APP_ADDED;

if (appId === '999-999') {
checkbox.setAttribute('disabled', 'disabled');
card.classList.add('app-card--disabled');
}
checkbox.checked = isInstalled;
}

function toggleAppInstallation(appId, checkbox) {
if (appId === '999-999') {
checkbox.checked = true;
function toggleAppInstallation(appId, checkbox, card) {
if (appId === ADD_APP_ID) {
if (isProtectedContext) {
checkbox.checked = true;
return;
}

const enabled = checkbox.checked;
localStorage.setItem(appId, enabled ? ADD_APP_ADDED : ADD_APP_REMOVED);
applyAddAppState(card);
refreshAddAppCards();
return;
}

if (checkbox.checked) {
localStorage.setItem(appId, 'added');
localStorage.setItem(appId, ADD_APP_ADDED);
} else {
localStorage.removeItem(appId);
}
}

function refreshAddAppCards() {
document
.querySelectorAll('.app-card[data-app-id="' + ADD_APP_ID + '"]')
.forEach(applyAddAppState);
}

document.addEventListener('DOMContentLoaded', function () {
const cards = document.querySelectorAll('.app-card[data-app-id]');

Expand All @@ -43,8 +97,14 @@
syncCheckboxState(card);

checkbox.addEventListener('change', function () {
toggleAppInstallation(appId, checkbox);
toggleAppInstallation(appId, checkbox, card);
});
});
});

window.addEventListener('storage', function (event) {
if (event.key === ADD_APP_ID) {
refreshAddAppCards();
}
});
})();
31 changes: 22 additions & 9 deletions static/gui/dashboard/002.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,28 @@

<script>

const ADD_APP_ID = '999-999';

function isAddAppAlwaysVisible() {
return window.location.pathname.includes('/dashboard/006');
}

function shouldDisplayAddAppIcon() {
return isAddAppAlwaysVisible() || localStorage.getItem(ADD_APP_ID) !== 'removed';
}

function updateHomeScreen() {
const appsContainer = document.getElementById('apps-container');
appsContainer.innerHTML = ''; // Clear existing apps
const appIds = ['002-001', '002-002', '999-999']; // Using class-based IDs
appsContainer.innerHTML = '';
const appIds = ['002-001', '002-002', ADD_APP_ID];
appIds.forEach(appId => {
const appInstalled = localStorage.getItem(appId) === 'added';
if (appInstalled || appId === '999-999') {
const isAddApp = appId === ADD_APP_ID;
const canShowAddApp = isAddApp ? shouldDisplayAddAppIcon() : false;

if (appInstalled || (isAddApp && canShowAddApp)) {
const appElement = document.createElement('a');
appElement.href = getAppLink(appId); // Set the hyperlink
appElement.href = getAppLink(appId);
appElement.style.cursor = 'pointer';
appElement.innerHTML = `
<div class="square-${appId}">
Expand All @@ -187,7 +200,7 @@
<div class="table-cell-${appId}">
<img class="rs-${appId}" src="../app-store/apps/${appId}/logo.png">
<br>
<img src="../app-store/apps/${appId}/title.svg" style="width:75%; height:5vw; margin-top:-1.95pc;">
<img src="../app-store/apps/${appId}/title.svg" style="width:75%; height:5vw; margin-top:-1.95pc;">
<br>
</div>
</div>
Expand Down Expand Up @@ -226,7 +239,7 @@
return '../app-store/apps/002-001/fetch.html';
case '002-002':
return 'http://hbnb.local:81';
case '999-999':
case ADD_APP_ID:
return '../app-store/002.html';
}
}
Expand All @@ -245,14 +258,14 @@
const appElement = document.getElementById(appId);
if (appElement) {
// Check if the dropped app is the one you want to prevent from being deleted
if (appId !== '999-999') {
if (appId !== ADD_APP_ID) {
appElement.remove();
localStorage.removeItem(appId);
updateAppStore(); // Update app store after removal

// Reload only the apps-container to update the remaining app icons
const appsContainer = document.getElementById('apps-container');
psContainer.innerHTML = ''; // Clear existing apps
appsContainer.innerHTML = ''; // Clear existing apps
updateHomeScreen(); // Repopulate the apps-container with updated app icons
} else {
// Do something (like displaying a message) to indicate that dropping this app is not allowed
Expand All @@ -262,7 +275,7 @@
}

function updateAppStore() {
const appIds = ['002-001', '002-002', '999-999'];
const appIds = ['002-001', '002-002', ADD_APP_ID];
appIds.forEach(appId => {
const installState = localStorage.getItem(appId);
const installAppCheckbox = document.getElementById(appId);
Expand Down
23 changes: 18 additions & 5 deletions static/gui/dashboard/003.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,28 @@


<script>
const ADD_APP_ID = '999-999';

function isAddAppAlwaysVisible() {
return window.location.pathname.includes('/dashboard/006');
}

function shouldDisplayAddAppIcon() {
return isAddAppAlwaysVisible() || localStorage.getItem(ADD_APP_ID) !== 'removed';
}

function updateHomeScreen() {
const appsContainer = document.getElementById('apps-container');
appsContainer.innerHTML = ''; // Clear existing apps
const appIds = ['003-001', '999-999']; // Using class-based IDs
appsContainer.innerHTML = '';
const appIds = ['003-001', ADD_APP_ID];
appIds.forEach(appId => {
const appInstalled = localStorage.getItem(appId) === 'added';
if (appInstalled || appId === '999-999') {
const isAddApp = appId === ADD_APP_ID;
const canShowAddApp = isAddApp ? shouldDisplayAddAppIcon() : false;

if (appInstalled || (isAddApp && canShowAddApp)) {
const appElement = document.createElement('a');
appElement.href = getAppLink(appId); // Set the hyperlink
appElement.href = getAppLink(appId);
appElement.style.cursor = 'pointer';
appElement.innerHTML = `
<div class="square-${appId}">
Expand All @@ -210,7 +223,7 @@
switch (appId) {
case '003-001':
return '../app-store/apps/003-001/fetch.html';
case '999-999':
case ADD_APP_ID:
return '../app-store/003.html';
}
}
Expand Down
Loading