mirror of
https://github.com/zschaffer/rating-room.git
synced 2024-06-19 07:27:08 +00:00
Adjusted helper functions to call from single index file
This commit is contained in:
parent
cafb35108a
commit
1cbe0758c1
|
@ -1,7 +1,5 @@
|
|||
const getAvgRating = (ratings) => {
|
||||
export const getAvgRating = (ratings) => {
|
||||
if (!ratings) return 0;
|
||||
if (ratings.length === 1) return ratings[0].rating;
|
||||
else return ratings.reduce((prev, curr) => prev.rating + curr.rating) / ratings.length;
|
||||
};
|
||||
|
||||
export default getAvgRating;
|
||||
|
|
4
src/helpers/index.js
Normal file
4
src/helpers/index.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export * from './toProduct';
|
||||
export * from './parse';
|
||||
export * from './normalize';
|
||||
export * from './getAvgRating';
|
|
@ -1,3 +1,2 @@
|
|||
const normalize = (str) => str.toLowerCase().trim()
|
||||
export const normalize = (str) => str.toLowerCase().trim()
|
||||
|
||||
export default normalize;
|
|
@ -1,4 +1,4 @@
|
|||
import normalize from './normalize';
|
||||
import {normalize }from './normalize';
|
||||
|
||||
export function parseSlug(slug) {
|
||||
return normalize(slug).replaceAll("-", " ")
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
import normalize from './normalize';
|
||||
import { parseName } from './parse';
|
||||
import {normalize, parseName} from './index';
|
||||
|
||||
const toProduct = (product, currentProduct) => {
|
||||
export const toProduct = (product, currentProduct) => {
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('product', normalize(parseName(product.name)));
|
||||
window.history.pushState({}, '', url);
|
||||
currentProduct.set(product)
|
||||
}
|
||||
|
||||
export default toProduct;
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { urlFor } from '$lib/sanityClient';
|
||||
import { productsView, currentProduct } from '$lib/stores';
|
||||
import { currentProduct } from '$lib/stores';
|
||||
</script>
|
||||
|
||||
<div class="content">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script>
|
||||
import { urlFor } from './sanityClient';
|
||||
import { currentProduct } from '$lib/stores.js';
|
||||
import toProduct from '$helpers/toProduct';
|
||||
import { toProduct } from '$helpers';
|
||||
export let products;
|
||||
|
||||
const {container} = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<script>
|
||||
import { productsView, products, tags } from '$lib/stores';
|
||||
import normalize from '$helpers/normalize';
|
||||
import getAvgRating from '$helpers/getAvgRating';
|
||||
import {normalize, getAvgRating } from '$helpers';
|
||||
export let filters;
|
||||
export let reset;
|
||||
let { selectedCat, selectedRating } = filters;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script>
|
||||
export let productsView;
|
||||
export let currentProduct;
|
||||
import toProduct from '$helpers/toProduct';
|
||||
import { toProduct } from '$helpers';
|
||||
|
||||
const { container, productStyle } = {
|
||||
container: 'pt-4',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { products, productsView } from '$lib/stores';
|
||||
import normalize from '$helpers/normalize';
|
||||
import { normalize } from '$helpers';
|
||||
|
||||
const searchProducts = (e) => {
|
||||
productsView.set(
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<script>
|
||||
import SortOption from './SortOption.svelte';
|
||||
import { productsView } from '$lib/stores';
|
||||
import normalize from '$helpers/normalize';
|
||||
import getAvgRating from '$helpers/getAvgRating';
|
||||
import {normalize, getAvgRating } from '$helpers';
|
||||
|
||||
const sortOptions = ['Rating', 'Name', 'Created'];
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<script>
|
||||
import '../app.css';
|
||||
import { page } from '$app/stores';
|
||||
import { products, productsView, currentProduct } from '$lib/stores';
|
||||
import Products from '$lib/Layout/Products.svelte';
|
||||
import Header from '$lib/Layout/Header.svelte';
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
import Feature from '$lib/Feature.svelte';
|
||||
import { products, productsView, tags, currentProduct } from '$lib/stores';
|
||||
import { browser } from '$app/env';
|
||||
import normalize from '$helpers/normalize';
|
||||
import { parseSlug } from '$helpers/parse';
|
||||
import {normalize, parseSlug } from '$helpers';
|
||||
|
||||
export let data;
|
||||
products.set(data.products);
|
||||
|
@ -31,7 +30,6 @@
|
|||
|
||||
if (browser) {
|
||||
window.onpopstate = () => {
|
||||
console.log('sttae poped')
|
||||
goToProduct();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user