-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e0be56
commit 828dd63
Showing
9 changed files
with
128 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,5 @@ module.exports = { | |
"svx", | ||
"md" | ||
], | ||
"started": "2021-01-30T20:58:04.111Z" | ||
"started": "2021-01-31T12:48:46.113Z" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,73 @@ | ||
<script lang="ts"> | ||
import { params } from '@roxi/routify'; | ||
import { onMount } from 'svelte'; | ||
import ProductView from '../../../components/ProductView/ProductView.svelte'; | ||
import { categories } from '../../../stores/categories'; | ||
import { retrieveStateFn, getCategoryId } from '../../../libs/requests'; | ||
import type { Category } from '../../../stores/categories'; | ||
export let subCategory: string; | ||
let showProduct = false; | ||
let productToShow: string; | ||
onMount(async () => { | ||
// This prevents the app for fetching the categories if it has already pulled them | ||
// but will pull them if visiting the link directly | ||
// if (!$categories.hasOwnProperty('Id') || $categories.Id === '') { | ||
// const result = await retrieveStateFn( | ||
// `${process.env.SERVER_URL}/category?id=${subCategory}`, | ||
// getCategoryId | ||
// )()(); | ||
// const data: Category = | ||
// result['_tag'] === 'Right' | ||
// ? JSON.parse(result.right as string) | ||
// : { Id: '', Name: '', Children: [] }; | ||
// categories.set(data); | ||
// } else { | ||
// // show category children OR show productview | ||
// const matchedCat = [...$categories.Children]; | ||
// categories.set(matchedCat.find(obj => obj.Id.toString() === subCategory)!) | ||
// } | ||
const result = await retrieveStateFn( | ||
`${process.env.SERVER_URL}/category?id=${subCategory}`, | ||
getCategoryId | ||
)()(); | ||
const data: Category = | ||
result['_tag'] === 'Right' | ||
? JSON.parse(result.right as string) | ||
: { Id: '', Name: '', Children: [] }; | ||
categories.set(data); | ||
}); | ||
</script> | ||
|
||
<h1>{JSON.stringify($params.subCategory)}</h1> | ||
<h1>{subCategory}</h1> | ||
<ProductView categoryId={subCategory} /> | ||
|
||
<!-- <SearchJewellery /> --> | ||
|
||
{#if $categories.hasOwnProperty('Id') || $categories.Id === ''} | ||
<h1>{$categories.Id}</h1> | ||
<h1>{$categories.Name}</h1> | ||
{#if $categories.Children.length > 0} | ||
{#each $categories.Children as cat} | ||
<button | ||
on:click={() => { | ||
showProduct = true | ||
console.log(cat.Id) | ||
productToShow = cat.Id | ||
console.log(productToShow) | ||
}}> | ||
{cat.Name} | ||
</button> | ||
{/each} | ||
{:else} | ||
<ProductView categoryId={subCategory} /> | ||
{/if} | ||
|
||
{#if showProduct} | ||
{console.log("product to show:", productToShow)} | ||
<ProductView categoryId={productToShow} /> | ||
{/if} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export const categories = writable({}); | ||
export interface Category { | ||
Id: string; | ||
Name: string; | ||
Children: Category[]; | ||
} | ||
|
||
|
||
export const categories = writable<Category>({ | ||
Id: '', | ||
Name: '', | ||
Children: [] | ||
}); |