Skip to content

Commit

Permalink
switch view modes, update theme on background color
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanjurman committed Sep 4, 2024
1 parent 740a8f6 commit f7794a4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions images/grids_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/rows_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,33 @@
type="text"
id="search"
placeholder="Food Search"
oninput="adjustSearchFontSize()"
onchange="searchFoods()"
/>
<button
id="search-view-grid"
class="page-button"
onclick="updateFoodItemListingStyle('1fr 1fr 1fr')"
style="display: none"
>
<img
src="images/grids_icon.svg"
alt="pencil icon"
style="filter: brightness(0)"
/>
</button>
<button
id="search-view-list"
class="page-button"
onclick="updateFoodItemListingStyle('1fr')"
style="display: none"
>
<img
src="images/rows_icon.svg"
alt="pencil icon"
style="filter: brightness(0)"
/>
</button>
<button class="page-button" onclick="showPage('food-create')">
<img
src="images/edit_icon.svg"
Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function searchFoods() {
spinner.style.display = 'none';

const json = await response.json();
updateFoodItemListingStyle('1fr 1fr 1fr');
updateSelectableFoodItems(json.foods, 0);
} catch (err) {
await new Promise(resolve => setTimeout(resolve, 1000));
Expand All @@ -48,6 +49,27 @@ async function searchFoods() {
}
}

function adjustSearchFontSize() {
const searchElement = document.getElementById("search")
searchElement.style.fontSize = Math.max(Math.min(searchElement.clientWidth / searchElement.value.length, '24'), '12');
}

function updateFoodItemListingStyle(style) {
if (style) {
document.getElementById("grid-food-items-wrapper").style.gridTemplateColumns = style;
}
document.getElementById("search-view-grid").style.display = 'none';
document.getElementById("search-view-list").style.display = 'none';
if (style === '1fr 1fr 1fr') {
document.querySelector(".grid-search-wrapper").style.gridTemplateColumns = 'auto 1fr auto auto auto';
document.getElementById("search-view-list").style.display = '';
}
if (style === '1fr') {
document.querySelector(".grid-search-wrapper").style.gridTemplateColumns = 'auto 1fr auto auto auto';
document.getElementById("search-view-grid").style.display = '';
}
}

function showPage(page) {
history.pushState({}, "", `#${page}`);
pageTransition(page);
Expand Down
4 changes: 4 additions & 0 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ get('background-color').then(color => {
const value = color || '#40798c';
document.documentElement.style.setProperty('--color-background', value)
document.getElementById('background-color').value = value;
document.querySelector('meta[name="theme-color"]').setAttribute('content', value);
});
get('button-color').then(color => {
const value = color || '#ffffff';
Expand Down Expand Up @@ -94,4 +95,7 @@ function updateColor(key) {
const newValue = document.getElementById(`${key}-color`).value;
set(`${key}-color`, document.getElementById(`${key}-color`).value)
document.documentElement.style.setProperty(`--color-${key}`, newValue);
if (key === 'background') {
document.querySelector('meta[name="theme-color"]').setAttribute('content', newValue);
}
}
3 changes: 2 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ html > * {
background-position: 15px 50%;
background-size: 30px;
padding-left: 50px;
padding-right: 50px;
padding-right: 12px;
}

#food-edit-name {
Expand Down Expand Up @@ -136,6 +136,7 @@ html > * {
cursor: pointer;
transition: all 0.1s;
padding: 10px;
container-name: foodButton;
}
.food-button > div {
text-overflow: ellipsis;
Expand Down

0 comments on commit f7794a4

Please sign in to comment.