From d6a59538b036c8b5ec2448b0569f564ec65134bc Mon Sep 17 00:00:00 2001 From: Nilesh <19304+nileshtrivedi@users.noreply.github.com> Date: Sun, 22 May 2022 19:05:13 +0100 Subject: [PATCH 1/2] Fetch reviews on ItemDetail page --- src/ItemDetail.svelte | 57 ++++++++++--------------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/src/ItemDetail.svelte b/src/ItemDetail.svelte index a97e046..480cc61 100644 --- a/src/ItemDetail.svelte +++ b/src/ItemDetail.svelte @@ -4,12 +4,19 @@ export let itemid; let item; + let reviews = []; $: fetch(`/learn/items/${itemid}.json?_shape=object`) .then(r => r.json()) .then(data => { item = data[itemid]; }); + + $: fetch(`/learn/reviews.json?_shape=array&item_id__exact=${itemid}`) + .then(r => r.json()) + .then(data => { + reviews = data; + }); function saveStatusToLocalStorage(event){ // console.log($bookmarks) @@ -127,55 +134,17 @@
+ {#each reviews as review}
-

About the book

-

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Velit architecto praesentium expedita? Similique dolor iusto expedita enim, optio dignissimos eaque officiis perferendis eum ullam voluptas esse quia tenetur natus modi.

+

{review.blurb.toString().slice(0,10)}...

+

{review.blurb}

- ★★★★★ - Sep 22, 2021 - Priyanka Trivedi + + ...{review.by}
+ {/each} -
-

About the book

-

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Velit architecto praesentium expedita? Similique dolor iusto expedita enim, optio dignissimos eaque officiis perferendis eum ullam voluptas esse quia tenetur natus modi.

-
- ★★★★★ - Sep 22, 2021 - Priyanka Trivedi -
-
- -
-

About the book

-

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Velit architecto praesentium expedita? Similique dolor iusto expedita enim, optio dignissimos eaque officiis perferendis eum ullam voluptas esse quia tenetur natus modi.

-
- ★★★★★ - Sep 22, 2021 - Priyanka Trivedi -
-
- -
-

About the book

-

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Velit architecto praesentium expedita? Similique dolor iusto expedita enim, optio dignissimos eaque officiis perferendis eum ullam voluptas esse quia tenetur natus modi.

-
- ★★★★★ - Sep 22, 2021 - Priyanka Trivedi -
-
- -
-

About the book

-

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Velit architecto praesentium expedita? Similique dolor iusto expedita enim, optio dignissimos eaque officiis perferendis eum ullam voluptas esse quia tenetur natus modi.

-
- ★★★★★ - Sep 22, 2021 - Priyanka Trivedi -
-

From 941fccd78276ad2d6997e98afd0942d7601bc06a Mon Sep 17 00:00:00 2001 From: Nilesh <19304+nileshtrivedi@users.noreply.github.com> Date: Sun, 22 May 2022 19:40:55 +0100 Subject: [PATCH 2/2] Fix RandomItem link --- src/App.svelte | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 6aa1ebe..f019872 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -15,9 +15,13 @@ import { SearchIcon } from "@rgossiaux/svelte-heroicons/outline"; let currentView = "/topics"; + let randomItemId; - function handleTabChanged(event) { - currentView = event.detail.tab; + function getRandomItemId(){ + fetch('/learn.json?_shape=array&sql=select+rowid+from+items+order+by+random()+limit+1').then(r => r.json()) + .then(data => { + randomItemId = data[0].rowid; + }); } async function hashchange() { @@ -32,8 +36,11 @@ } } + onMount(getRandomItemId); onMount(hashchange); + + @@ -56,6 +63,8 @@ {:else if currentView.startsWith("/item/")} + {:else if currentView == "/random"} + {#if randomItemId}{/if} {:else if currentView === "/search"} {:else if currentView === "/wanttolearn"} @@ -74,7 +83,7 @@ Formats - + Random Item