Skip to content

Commit

Permalink
History API introduced to handle back button click
Browse files Browse the repository at this point in the history
Lazy image placeholder with aspect ratio
  • Loading branch information
itswadesh committed Apr 23, 2023
1 parent 5c31545 commit 2235eb7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/lib/CatelogNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script lang="ts">
import { enhance } from '$app/forms'
import { goto, invalidateAll } from '$app/navigation'
import { toast } from '$lib/utils'
import { goback, toast } from '$lib/utils'
import { createEventDispatcher, getContext, onMount } from 'svelte'
import { cubicOut } from 'svelte/easing'
import { fade, fly } from 'svelte/transition'
Expand Down Expand Up @@ -130,7 +130,7 @@ const getSelectionLabel = (option) => option.name
<button
type="button"
class="block shrink-0 focus:outline-none lg:hidden"
on:click="{() => window.history.go(-1)}">
on:click="{goback}">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fade, fly, slide } from 'svelte/transition'
import { goto, invalidateAll } from '$app/navigation'
import { logo } from './config'
import { page } from '$app/stores'
import { toast } from '$lib/utils'
import { goback, toast } from '$lib/utils'
import Autocomplete from './components/Autocomplete/Autocomplete.svelte'
import AutosuggestModal from './AutosuggestModal.svelte'
import Cookie from 'cookie-universal'
Expand Down Expand Up @@ -178,7 +178,7 @@ const getSelectionLabel = (option) => option.name
<button
type="button"
class="block shrink-0 focus:outline-none sm:hidden"
on:click="{() => window.history.go(-1)}">
on:click="{goback}">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand Down
3 changes: 2 additions & 1 deletion src/lib/ProductNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { page } from '$app/stores'
import AutosuggestModal from './AutosuggestModal.svelte'
import type { Cart, Me } from './types'
import { goback } from './utils'
export let cart: Cart
export let data
Expand Down Expand Up @@ -38,7 +39,7 @@ let show = false
<button
type="button"
class="h-8 w-8 shrink-0 flex items-center justify-center frosted-white rounded-full focus:outline-none"
on:click="{() => window.history.go(-1)}">
on:click="{goback}">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand Down
6 changes: 4 additions & 2 deletions src/lib/components/Image/LazyImg.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ onDestroy(() => {

<img
alt="{alt}"
class="lazy {clazz}"
src="{`${getCdnImageUrl(src, IMAGE_CDN_URL)}?tr=w-${aspect_ratio.split(':')[0]},h-${
class="aspect-[{aspect_ratio.split(':')[0]}/{aspect_ratio.split(':')[1]}] lazy {clazz}"
width="{w}"
height="{h}"
src="{`${getCdnImageUrl(src, IMAGE_CDN_URL)}?tr=w-1,h-1:w-${aspect_ratio.split(':')[0]},h-${
aspect_ratio.split(':')[1]
},ar-${aspect_ratio.replace(':', '-')}`}"
data-src="{`${getCdnImageUrl(src, IMAGE_CDN_URL)}?tr=w-${w},h-${h},ar-${aspect_ratio.replace(
Expand Down
9 changes: 9 additions & 0 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import { currency as currencyConfig } from '../config'
import { toasts } from 'svelte-toasts'
import type { AllOrders, AllProducts, Category, Order, Product } from '$lib/types'
import type { ToastProps, ToastType } from 'svelte-toasts/types/common'
import { goto } from '$app/navigation'

let allToasts: any

export const goback = () => {
if (history.length < 3) {
goto('/')
} else {
window.history.go(-1)
}
}

export function constructURL2(url: string, fl: any) {
url += '?'
Object.keys(fl).forEach((e) => {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(product)/product/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ function handleMobileCanvas() {
<LazyImg
src="{img}"
alt="{data.product?.name}"
height="262"
height="512"
class="object-contain object-top w-full h-auto first-line:text-xs" />
</button>
{/each}
Expand Down

1 comment on commit 2235eb7

@vercel
Copy link

@vercel vercel bot commented on 2235eb7 Apr 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.