Skip to content

Commit

Permalink
feat: add layout selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed Jan 21, 2024
1 parent 4622b2b commit 7ddd2a3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
38 changes: 20 additions & 18 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<template>
<div class="container">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<router-link to="/" class="navbar-item">
<img src="/atlas-logo.svg" width="112" height="28">
</router-link>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<button class="button is-light" @click="updateCache" title="Refresh">
<span class="icon is-small">
<i class="mdi material-icons">refresh</i>
</span>
</button>
<div class="topbar">
<div class="container">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<router-link to="/" class="navbar-item">
<img src="/atlas-logo.svg" width="112" height="28">
</router-link>
</div>
<div class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<button class="button is-light" @click="updateCache" title="Refresh">
<span class="icon is-small">
<i class="mdi material-icons">refresh</i>
</span>
</button>
</div>
</div>
</div>
</div>
</div>
</nav>
</nav>
</div>
</div>

<div class="container">
Expand Down
17 changes: 16 additions & 1 deletion src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ p span.badge {
.flex-list {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 5px;
align-items: stretch;
}

.flex-list-item.recipe-card .card {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.badges {
Expand Down Expand Up @@ -144,4 +150,13 @@ p span.badge {

.bar-segment.bar-segment--very-low {
background-color: #768ffb;
}

.topbar {
background-color: #fff;
border-bottom: 1px solid #dddddd;
margin: 0 0 18px;
position: sticky;
top: 0;
z-index: 99
}
1 change: 1 addition & 0 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const useAtlasStore = defineStore('atlas', {
state: () => ({
vibRecipes: [] as VibRecipe[],
lastFetchDate: Date.now(),
layout: 'grid',
}),
persist: {
storage: window.localStorage,
Expand Down
34 changes: 29 additions & 5 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<template>
<div v-if="atlasStore.vibRecipes">
<nav class="navbar">
<div class="navbar-brand">
<button class="button navbar-item" @click="toggleView">
<span class="icon is-small">
<i class="mdi material-icons" v-if="isGridView">view_list</i>
<i class="mdi material-icons" v-else>view_module</i>
</span>
</button>
</div>
</nav>

<section class="hero">
<div class="hero-body">
<p class="title">Vib Images</p>
Expand All @@ -13,16 +24,17 @@
<button class="delete" aria-label="delete" @click="hideWarning"></button>
</div>
<div class="message-body">
Your local data is old than <u>12 hours</u>, which means that you may not see
Your local data is older than <u>12 hours</u>, which means that you may not see
the latest recipes. Do you want to update it now?
<br />
<br />
<button class="button is-warning" @click="updateCache">Update cache</button>
</div>
</article>

<div class="flex-grid">
<div class="flex-grid-item" v-for="(recipe, index) in atlasStore.vibRecipes" :key="index">
<div :class="{ 'flex-list': !isGridView, 'flex-grid': isGridView }">
<div v-for="(recipe, index) in atlasStore.vibRecipes" :key="index"
:class="{ 'flex-list-item': !isGridView, 'flex-grid-item': isGridView }" class="recipe-card">
<router-link :to="{ name: 'recipe', params: { id: recipe.id } }">
<div class="card">
<header class="card-header">
Expand Down Expand Up @@ -69,17 +81,23 @@ export default defineComponent({
cacheIsOld: false,
refreshCacheTimer: 0,
messageHidden: false,
isGridView: true,
};
},
setup() {
const atlasStore = useAtlasStore();
return { atlasStore };
},
async beforeMount() {
this.setLayout();
this.fetchRecipes();
this.setCacheRefreshTimer();
},
methods: {
setLayout() {
const layout = this.atlasStore.layout;
this.isGridView = layout === "grid";
},
async fetchRecipes() {
try {
// @ts-ignore
Expand All @@ -92,7 +110,7 @@ export default defineComponent({
console.log("Checking cache status..");
const lastFetchTimestamp = this.atlasStore.lastFetchDate;
if (lastFetchTimestamp) {
const lastFetchDate = new Date(lastFetchTimestamp); // Convert timestamp to Date object
const lastFetchDate = new Date(lastFetchTimestamp);
const now = new Date();
const diff = now.getTime() - lastFetchDate.getTime();
this.cacheIsOld = diff > 1000 * 60 * 60 * 12;
Expand Down Expand Up @@ -127,6 +145,12 @@ export default defineComponent({
hideWarning() {
this.messageHidden = true;
},
toggleView() {
this.isGridView = !this.isGridView;
this.atlasStore.$patch((state) => {
state.layout = this.isGridView ? "grid" : "list";
});
},
},
});
</script>
</script>

0 comments on commit 7ddd2a3

Please sign in to comment.