Skip to content

Commit

Permalink
fix: 🐛 load jewellery products with search component
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskaransarkaria committed Jan 5, 2021
1 parent 0568d48 commit 64edfdd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .routify/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ module.exports = {
"svx",
"md"
],
"started": "2021-01-05T15:47:29.802Z"
"started": "2021-01-05T16:06:04.404Z"
}
4 changes: 2 additions & 2 deletions .routify/routes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

/**
* @roxi/routify 2.7.3
* File generated Tue Jan 05 2021 15:47:31 GMT+0000 (Greenwich Mean Time)
* File generated Tue Jan 05 2021 16:06:05 GMT+0000 (Greenwich Mean Time)
*/

export const __version = "2.7.3"
export const __timestamp = "2021-01-05T15:47:31.768Z"
export const __timestamp = "2021-01-05T16:06:05.703Z"

//buildRoutes
import { buildClientTree } from "@roxi/routify/runtime/buildRoutes"
Expand Down
24 changes: 22 additions & 2 deletions src/components/SearchJewellery/SearchJewellery.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
<script lang="ts">
import { jewellery } from '../../stores/jewellery';
let searchValue: string;
import { onMount } from 'svelte';
let searchValue: string = '';
let results: any[] = [];
const fetchJewelleryProducts = async () => {
try {
const response = await fetch(
`${process.env.SERVER_URL}/jewellery-products`
);
const parsedResult = await response.json();
return parsedResult;
} catch (err) {
console.error('fetching jewellery products failed', err);
}
};
onMount(async () => {
const data = await fetchJewelleryProducts();
jewellery.set(data);
});
const searchJewelleryForValue = (event: Event) =>
event.target.value === ''
? []
Expand All @@ -19,8 +37,10 @@
</form>

<ul>
{#if searchValue != ''}
<h1>Total matches: {results.length}</h1>
{/if}
{#each results as match}
<h1>Total matches: {results.length}</h1>
<h1>{match.Name}</h1>
<h1>CategoryId: {match.CategoryId}</h1>
<h1>Product Id: {match.Id}</h1>
Expand Down
24 changes: 0 additions & 24 deletions src/pages/online-shop/[category].svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@
import { params, goto } from '@roxi/routify';
import { onMount } from 'svelte';
import { categories } from '../../stores/categories';
import { jewellery } from '../../stores/jewellery';
import ProductView from '../../components/ProductView/ProductView.svelte';
import SearchJewellery from '../../components/SearchJewellery/SearchJewellery.svelte';
export let category: string;
const isCategoryJewellery = async (id: string) => {
try {
if (id === '1821413') {
const data = await fetchJewelleryProducts();
saveJewelleryToStore(data);
}
} catch (err) {
console.error('fetching jewellery products failed', err);
}
};
const saveJewelleryToStore = (parsedJewelleryResult: any) =>
jewellery.set(parsedJewelleryResult);
const fetchJewelleryProducts = async () => {
const response = await fetch(
`${process.env.SERVER_URL}/jewellery-products`
);
const parsedResult = await response.json();
return parsedResult;
};
const fetchCategoryById = async (id: string) => {
const response = await fetch(`${process.env.SERVER_URL}/category?id=${id}`);
const parsedResult = JSON.parse(await response.json());
Expand All @@ -44,7 +21,6 @@
} catch (err) {
console.error('fetching category failed', err);
}
await isCategoryJewellery(category);
}
});
</script>
Expand Down

0 comments on commit 64edfdd

Please sign in to comment.