Skip to content

Commit

Permalink
ProjectFilters are now dynamicly calculated based on projectFilterTag…
Browse files Browse the repository at this point in the history
…s of projects. If not projectFilter name is provided, tag is used as a name. Fixes #25
  • Loading branch information
noisy committed Feb 9, 2023
1 parent 1a0e345 commit a9d4699
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
24 changes: 24 additions & 0 deletions src/composables/useProjectFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { IProjectFilter } from "@/types";
import { allFilterTag } from "@/types";
import { useDB } from "./useDB";
import { useProjectFiltersTags } from "./useProjectFiltersTags";

const { projectFilters } = useDB();
const { projectFilterTags } = useProjectFiltersTags();

export function useProjectFilters(): { projectFilters: IProjectFilter[] } {
const dynamiclyCalculatedProjectFilters = projectFilterTags.map(
(tag) =>
projectFilters.find((f) => f.tag === tag) || {
name: tag,
tag,
}
);

return {
projectFilters: [
...dynamiclyCalculatedProjectFilters,
{ name: "All", tag: allFilterTag },
],
};
}
19 changes: 19 additions & 0 deletions src/composables/useProjectFiltersTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IProjectFilterTag } from "@/types";
import { useDB } from "./useDB";

export function useProjectFiltersTags(): {
projectFilterTags: IProjectFilterTag[];
} {
const { projects } = useDB();
const projectFilterTags = new Set<IProjectFilterTag>();

projects.forEach(({ filterTags: tags }) => {
tags.forEach((tag) => {
projectFilterTags.add(tag);
});
});

return {
projectFilterTags: [...projectFilterTags],
};
}
8 changes: 4 additions & 4 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allFilterTag } from "./types";
import { allFilterTag, type IProjectFilter } from "./types";
import type { IDB } from "./types/IDB";

const db: IDB = {
Expand Down Expand Up @@ -100,7 +100,7 @@ const db: IDB = {
thumbnail: "opera-mobile.png",
summaryTitle: "Example title",
summary: "Opera Mobile was a mobile application for",
filterTags: ["android", "java", "ccpp"],
filterTags: ["android", "java", "c-cpp"],
badges: ["Java", "C/C++", "Android", "Python"],
technologies: ["android", "c", "cpp", "java"],
thumbnailLogo: "logo-opera.svg",
Expand Down Expand Up @@ -173,7 +173,7 @@ const db: IDB = {
{ name: "Angular", tag: "angular" },
{ name: "React", tag: "react" },
{ name: "Android", tag: "android" },
{ name: "C/C++", tag: "ccpp" },
{ name: "C/C++", tag: "c-cpp" },
{ name: "Java", tag: "java" },
{ name: "Blockchain", tag: "blockchain" },
],
Expand Down Expand Up @@ -283,7 +283,7 @@ const db: IDB = {
description: "",
date: "Feb 5, 2018",
filterTags: ["blockchain"],
}
},
// {
// source: "youtube",
// id: "",
Expand Down
3 changes: 2 additions & 1 deletion src/types/IProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type IProjectFilterTag =
| "java"
| "blockchain"
| "react"
| "ccpp";
| "c-cpp";

export type IProjectBadge =
| "Angular"
| "Java"
Expand Down
5 changes: 4 additions & 1 deletion src/views/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
<script setup lang="ts">
import { Filters, PageHeader, ProjectsGrid } from "@/components";
import { useDB } from "@/composables";
import { useProjectFilters } from "@/composables/useProjectFilters";
import { setupIsotopeFilters } from "@/libs/isotope-custom";
import { onMounted } from "vue";
const { projects, projectFilters } = useDB();
const { projects } = useDB();
const { projectFilters } = useProjectFilters();
onMounted(() => setupIsotopeFilters(["project-filters"]));
</script>
2 changes: 1 addition & 1 deletion src2/components/__tests__/HelloWorld.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";

import { mount } from "@vue/test-utils";
import HelloWorld from "../HelloWorld.vue";
Expand Down

0 comments on commit a9d4699

Please sign in to comment.