diff --git a/src/components/Card/TagRow.astro b/src/components/Card/TagRow.astro index e1a644e..d9f8646 100644 --- a/src/components/Card/TagRow.astro +++ b/src/components/Card/TagRow.astro @@ -6,7 +6,7 @@ const { tags } = Astro.props { (tags ?? []).map(tag => ( {tag.name} diff --git a/src/components/Header.astro b/src/components/Header.astro index 28dd602..89595c5 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -7,8 +7,9 @@
- new - tags - search + new + add + + search
\ No newline at end of file diff --git a/src/data/pocketbase.ts b/src/data/pocketbase.ts index ef6d8de..8684c0a 100644 --- a/src/data/pocketbase.ts +++ b/src/data/pocketbase.ts @@ -29,7 +29,7 @@ class APIClient { // IMAGE async getImageURL(imgID: string, relative: boolean = true) { - const record = await this.client.collection("images").getOne(imgID) + const record = await this.client.collection(Collection.IMAGES).getOne(imgID) const res = this.client.files.getURL(record, record.image) return relative ? res.substring(21) : res } @@ -44,6 +44,28 @@ class APIClient { return urls } + async getAllTags() { + return await this.client.collection(Collection.TAGS).getFullList() + } + + async getTag(name: string) { + return await this.client.collection(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` }) + } + + async getRecipesOfTag(tagName: string) { + // get the tag id first + const tagResult = await this.getTag(tagName) + if (tagResult.items.length === 0) { + return [] + } + const tag = tagResult.items[0] + + return await this.client.collection(Collection.RECIPES).getFullList({ + filter: `tags ~ '${tag.id}'`, + expand: 'ingredients,tags,steps,images,steps.ingredients' + }) + } + } const client = new APIClient() export default client; \ No newline at end of file diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..a678d68 --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,9 @@ +--- +import Base from "@/layouts/base"; +--- + + +
+ 🥧 404 🥧 +
+ \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index 592c409..47d2734 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -9,7 +9,7 @@ const recipes = await client.getAllRecipes() -
+
{ recipes.map(r => ( diff --git a/src/pages/tags/[name].astro b/src/pages/tags/[name].astro new file mode 100644 index 0000000..130a9bf --- /dev/null +++ b/src/pages/tags/[name].astro @@ -0,0 +1,22 @@ +--- +import SiteLayout from "@/layouts/base"; +import client from "@/data/pocketbase"; +import OverviewCard from "@/components/Card/OverviewCard"; + +const { name } = Astro.params +const recipes = await client.getRecipesOfTag(name) // todo redir to 404 if not found +--- + + +

+ {recipes.length} { recipes.length == 1 ? "Recipe" : "Recipes" } with: {name} +

+ +
+ { + recipes.map(r => ( + + )) + } +
+
\ No newline at end of file diff --git a/src/pages/tags/index.astro b/src/pages/tags/index.astro new file mode 100644 index 0000000..0f691a4 --- /dev/null +++ b/src/pages/tags/index.astro @@ -0,0 +1,24 @@ +--- +import client from "@/data/pocketbase"; +import SiteLayout from "@/layouts/base"; + +const tags = await client.getAllTags() + +const countsPerTag = await Promise.all( + tags.map(async t => (await client.getRecipesOfTag(t.name)).length) +) +--- + + +

+ {tags.length} Tags +

+ { + (tags ?? []).map((t, i) => ( + //

{t.name} -> {countsPerTag[i]} {countsPerTag[i] == 1 ? "Recipe" : "Recipes" }

+ + {t.name} ({countsPerTag[i]}) +
+ )) + } +
\ No newline at end of file diff --git a/src/styles/global.css b/src/styles/global.css index 12ec143..bdf651e 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -7,4 +7,8 @@ html { /* @apply font-; */ @apply font-sans; /* font-family: 'SF Pro Display', 'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif; */ +} + +.title { + @apply text-2xl; } \ No newline at end of file