Skip to content

Commit

Permalink
fix: merge error
Browse files Browse the repository at this point in the history
  • Loading branch information
karlaoshikawa committed Dec 4, 2024
1 parent 0b999cf commit 9f8e06c
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 440 deletions.
36 changes: 0 additions & 36 deletions .deco/blocks/Header%20-%2001.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,4 @@
"searches": []
},
"__resolveType": "site/sections/Header/Header.tsx"
}
{
"cart": {
"freeShippingObjectiveQuantity": 600
},
"logo": {
"alt": "World Tools Logo",
"src": "https://ozksgdmyrqcxcwhnbepg.supabase.co/storage/v1/object/public/assets/3444/bb49f28f-6070-4d85-b88a-9ce3c7b1a4b2"
},
"alerts": [
"<b>Promoção</b> por tempo limitado - <b>Frete Grátis</b> para compras acima de R$ 500,00"
],
"navItems": {
"__resolveType": "navbar"
},
"ctaButton": {
"buttonLink": "/acessorios-para-maquinas",
"buttonText": "EU QUERO",
"alertsActive": false
},
"searchbar": {
"name": "busca",
"action": "/s",
"loader": {
"data": {
"__resolveType": "wake/loaders/suggestion.ts"
},
"__resolveType": "resolved"
},
"placeholder": "O que está procurando hoje ?"
},
"suggestions": {
"products": [],
"searches": []
},
"__resolveType": "site/sections/Header/Header.tsx"
}
15 changes: 8 additions & 7 deletions .deco/blocks/Luxury.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"fontFamily": "'Georgia'"
},
"mainColors": {
"primary": "#000000",
"base-100": "#09090b",
"tertiary": "#cddef9",
"secondary": "#164195"
"primary": "#FFFFFF",
"base-100": "#FFFFFF",
"tertiary": "#000000",
"secondary": "#164195",
"neutral": "#000000"
},
"buttonStyle": {
"--border-btn": "1px",
Expand All @@ -24,13 +25,13 @@
},
"base-300": "#dfeaffd4"
},
"colorScheme": "any",
"otherStyles": {
"--rounded-box": "1rem",
"--rounded-badge": "1.9rem",
"--animation-input": "0.2s",
"--tab-border": "1px",
"--tab-radius": "0.5rem"
},
"mode": "dark"
}
"mode": "dark",
"colorScheme": "any"
}
4 changes: 1 addition & 3 deletions .deco/blocks/pages-category-7493d4326022.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@
}
},
"startingPage": 1,
"__resolveType": "site/sections/Product/SearchResult.tsx",
"min": 0,
"max": 60000
"__resolveType": "site/sections/Product/SearchResult.tsx"
},
{
"title": "Preços promocionais, Aproveite!",
Expand Down
2 changes: 1 addition & 1 deletion .deco/metadata/blocks.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions components/product/ProductCardCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ const relative = (url: string) => {

export const calculate = (item: number, item2: number) => {
if (item - item2 > 0) {
const percentValue = Math.round((item - item2) / item * 100);
return `${percentValue}% OFF `;
// const percentValue = Math.round((item - item2) / item * 100);
// return `${percentValue}% OFF`;
}

//este valor esta colocado diretamente no codigo por causa de um erro na API da wake. Retirar e descomentar o codigo acima para calcular automaticamente.
return "12% OFF";
};

const WIDTH = 314;
Expand Down
7 changes: 4 additions & 3 deletions components/product/ProductCardOdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ const relative = (url: string) => {

const calculate = (item: number, item2: number) => {
if ((item - item2) > 0) {
const percentValue = Math.round((item - item2) / item * 100);
return `${percentValue}% OFF`;
// const percentValue = Math.round((item - item2) / item * 100);
// return `${percentValue}% OFF`;
}

//este valor esta colocado diretamente no codigo por causa de um erro na API da wake. Retirar e descomentar o codigo acima para calcular automaticamente.
return "12% OFF"
};


Expand Down
195 changes: 195 additions & 0 deletions components/search/FilterRange.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { useEffect, useId, useRef } from "preact/hooks";
import { RefObject } from "preact";
import { useSignal } from "@preact/signals";
import { formatPrice } from "site/sdk/format.ts";

function useDebounce(
// deno-lint-ignore no-explicit-any
func: (...args: any[]) => void,
timeout = 300,
// deno-lint-ignore no-explicit-any
): (...args: any[]) => void {
let timer: ReturnType<typeof setTimeout>;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
func(...args);
}, timeout);
};
}

const thumbsize = 14;

interface FilterRangeProps {
min: number;
max: number;
currentUrlFilterPrice?: string;
currentMaxFacet?: string;
currentMinFacet?: string;
}

function applyFilterPrice(
{ min, max, currentUrlFilterPrice }: FilterRangeProps,
) {
const searchParams = new URLSearchParams(currentUrlFilterPrice);
console.log("searchParams", searchParams);
searchParams.set("filter.price", `${min}:${max}`);
const newUrl = `${window.location.pathname}?${searchParams.toString()}`;

globalThis.location.href = newUrl;
}

const debouncedApplyFilterPrice = useDebounce((arg) => applyFilterPrice(arg));

function FilterRange(
{
min: minValue,
max: maxValue,
currentUrlFilterPrice = "",
currentMinFacet,
currentMaxFacet,
}: FilterRangeProps,
) {
const id = useId();
const slider: RefObject<HTMLDivElement> = useRef(null);
const min: RefObject<HTMLInputElement> = useRef(null);
const max: RefObject<HTMLInputElement> = useRef(null);
const rangemin = useSignal(Number(currentMinFacet));
const rangemax = useSignal(Number(currentMaxFacet));

const avgvalueprimary = (rangemin.value + rangemax.value) / 2;
const dataValue = useSignal({
min: minValue,
max: maxValue,
rangewitdh: 0,
});

function draw(splitvalue: number) {
if (
min.current &&
max.current &&
slider.current &&
!!dataValue.value.rangewitdh
) {
min.current.setAttribute("max", `${splitvalue}`);
max.current.setAttribute("min", `${splitvalue}`);

// Set css
min.current.style.width = `${
Math.floor(
thumbsize +
((splitvalue - minValue) /
(maxValue - minValue)) *
(dataValue.value.rangewitdh - 2 * thumbsize),
)
}px`;
max.current.style.width = `${
Math.floor(
thumbsize +
((maxValue - splitvalue) /
(maxValue - minValue)) *
(dataValue.value.rangewitdh - 2 * thumbsize),
)
}px`;

min.current.style.left = "0px";
max.current.style.left = min.current.style.width;

slider.current.style.height = `${min.current.offsetHeight}px`;

if (Number(max.current.value) > maxValue) {
max.current.setAttribute("data-value", `${dataValue.value.max}`);
}

rangemin.value = Number(min.current.getAttribute("data-value"));
rangemax.value = Number(max.current.getAttribute("data-value"));
}
}

function update(props: FilterRangeProps): void {
if (min.current && max.current) {
const minvalue = props.min;
const maxvalue = props.max;

min.current.setAttribute("data-value", `${minvalue}`);
max.current.setAttribute("data-value", `${maxvalue}`);

const avgvalue = (minvalue + maxvalue) / 2;
draw(Math.round(avgvalue));
}
}

function handleInput(props: FilterRangeProps) {
update(props);
debouncedApplyFilterPrice({
min: rangemin.value,
max: rangemax.value,
currentUrlFilterPrice,
});
}

useEffect(() => {
if (slider.current) {
dataValue.value.rangewitdh = slider.current.offsetWidth;
draw(Math.round(avgvalueprimary));
}
}, []);

return (
<div class="flex flex-col">
<div ref={slider} class="relative w-full text-center inline-block">
<label for="min" class="hidden">
Preço minimo
</label>
<input
ref={min}
id={`min-${id}`}
class="cursor-pointer absolute filter-range top-0"
name="min"
type="range"
step="1"
min={minValue}
max={Math.round(maxValue)}
data-value={rangemin.value}
onInput={(ev: React.ChangeEvent<HTMLInputElement>) =>
handleInput({
min: Math.round(Number(ev.currentTarget.value)),
max: rangemax.value,
})}
value={rangemin.value}
/>
<label for="max" class="hidden">
Preço máximo
</label>
<input
ref={max}
id={`max-${id}`}
class="cursor-pointer absolute filter-range top-0"
name="max"
type="range"
step="1"
min={minValue}
max={Math.round(maxValue)}
data-value={Math.round(rangemax.value)}
onInput={(ev: React.ChangeEvent<HTMLInputElement>) =>
handleInput({
max: Math.round(Number(ev.currentTarget.value)),
min: rangemin.value,
})}
value={Math.round(rangemax.value)}
/>
</div>
<div class="flex justify-end items-center">
<output class="font-caption text-caption">
{formatPrice(rangemin.value, "BRL")}
</output>
<span class="font-caption text-caption block mx-1">-</span>
<output class="font-caption text-caption">
{formatPrice(rangemax.value, "BRL")}
</output>
</div>
</div>
);
}

export default FilterRange;
Loading

0 comments on commit 9f8e06c

Please sign in to comment.