Pass Grid's data source as props + Add GridEmpty for error messages.
This commit is contained in:
@@ -75,39 +75,58 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</transition-group>
|
</transition-group>
|
||||||
|
|
||||||
|
<!-- Error Message -->
|
||||||
|
<GridEmpty
|
||||||
|
v-if="dataSource && !dataSource.length"
|
||||||
|
message="0 projects listed."
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import projects from "../content/projects.json";
|
|
||||||
import { shuffle } from "lodash";
|
import { shuffle } from "lodash";
|
||||||
|
import GridEmpty from "./GridEmpty";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: { GridEmpty },
|
||||||
computed: {
|
computed: {
|
||||||
filteredData() {
|
filteredData() {
|
||||||
if (this.filter === "all") return this.data;
|
if (this.filter === "all") return shuffle(this.dataSource);
|
||||||
|
|
||||||
return shuffle(this.data.filter(o => o.type === this.filter));
|
return this.shuffle(this.dataSource.filter(o => o.type === this.filter));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
props: {
|
||||||
|
dataSource: [Array, Object],
|
||||||
|
default: () => {}
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
data: projects,
|
|
||||||
filter: "all"
|
filter: "all"
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.data = shuffle(this.data);
|
// FIXME: Commented for testing purposes
|
||||||
|
// 1. Get nav element and observe it.
|
||||||
// get the sticky element
|
// 2. Toggle class for sticky behavior.
|
||||||
const stickyElm = document.getElementById("grid-nav");
|
// const stickyElm = document.getElementById("grid-nav");
|
||||||
|
// this.observeElmt(stickyElm);
|
||||||
const observer = new IntersectionObserver(
|
},
|
||||||
([e]) => e.target.classList.toggle("shadow-md", e.intersectionRatio < 1),
|
methods: {
|
||||||
{ threshold: [1] }
|
// FIXME: Commented for testing purposes
|
||||||
);
|
// observeElmt(elmt) {
|
||||||
|
// const options = {
|
||||||
observer.observe(stickyElm);
|
// root: elmt,
|
||||||
|
// threshold: 1
|
||||||
|
// };
|
||||||
|
// const observer = new IntersectionObserver(
|
||||||
|
// ([e]) =>
|
||||||
|
// e.target.classList.toggle("shadow-md", e.intersectionRatio < 1),
|
||||||
|
// options
|
||||||
|
// );
|
||||||
|
// observer.observe(elmt);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
22
components/GridEmpty.vue
Normal file
22
components/GridEmpty.vue
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="bg-gray-500 text-white text-sm font-bold px-4 py-3 w-1/2 mx-auto"
|
||||||
|
role="alert"
|
||||||
|
>
|
||||||
|
<p>{{ message }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "GridEmpty",
|
||||||
|
props: {
|
||||||
|
message: {
|
||||||
|
type: String,
|
||||||
|
default: "0 items to be shown."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style></style>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
></path></svg></a
|
></path></svg></a
|
||||||
><a
|
><a
|
||||||
class="flex items-center hover:text-gray-700 mr-5"
|
class="flex items-center hover:text-gray-700 mr-5"
|
||||||
href="https://www.linkedin.com/in/no%C3%A9-v-395bba109/"
|
href="https://www.linkedin.com/in/no%C3%A9-v-395bba109"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -2,13 +2,21 @@
|
|||||||
<div>
|
<div>
|
||||||
<Header />
|
<Header />
|
||||||
<Hero />
|
<Hero />
|
||||||
<Grid />
|
<Grid :dataSource="projects" />
|
||||||
<Contact />
|
<Contact />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {};
|
import projects from "@/content/projects.json";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
projects: projects
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user