Skip to content

Commit

Permalink
Merge pull request #3 from deco-sites/dev
Browse files Browse the repository at this point in the history
release 0.1.1!!!!!
  • Loading branch information
vitormiura authored Nov 4, 2023
2 parents c906f9f + ee800bb commit 098f98e
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 876 deletions.
2 changes: 1 addition & 1 deletion .release.json

Large diffs are not rendered by default.

52 changes: 28 additions & 24 deletions manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ import * as $$$$$$22 from "./sections/Miscellaneous/CookieConsent.tsx";
import * as $$$$$$23 from "./sections/Newsletter/Newsletter.tsx";
import * as $$$$$$24 from "./sections/Product/ImageGalleryFrontBack.tsx";
import * as $$$$$$25 from "./sections/Product/ImageGallerySlider.tsx";
import * as $$$$$$26 from "./sections/Product/NotFound.tsx";
import * as $$$$$$27 from "./sections/Product/NotFoundChallenge.tsx";
import * as $$$$$$28 from "./sections/Product/ProductInfo.tsx";
import * as $$$$$$29 from "./sections/Product/ProductList.tsx";
import * as $$$$$$30 from "./sections/Product/ProductShelf.tsx";
import * as $$$$$$31 from "./sections/Product/ProductShelfTabbed.tsx";
import * as $$$$$$32 from "./sections/Product/SearchResult.tsx";
import * as $$$$$$33 from "./sections/Product/Wishlist.tsx";
import * as $$$$$$34 from "./sections/sideModalPromotion.tsx";
import * as $$$$$$35 from "./sections/Social/InstagramPosts.tsx";
import * as $$$$$$36 from "./sections/Social/WhatsApp.tsx";
import * as $$$$$$37 from "./sections/Theme/Theme.tsx";
import * as $$$$$$26 from "./sections/Product/MostSeen.tsx";
import * as $$$$$$27 from "./sections/Product/NotFound.tsx";
import * as $$$$$$28 from "./sections/Product/NotFoundChallenge.tsx";
import * as $$$$$$29 from "./sections/Product/ProductInfo.tsx";
import * as $$$$$$30 from "./sections/Product/ProductList.tsx";
import * as $$$$$$31 from "./sections/Product/ProductShelf.tsx";
import * as $$$$$$32 from "./sections/Product/ProductShelfTabbed.tsx";
import * as $$$$$$33 from "./sections/Product/RecommenderProducts.tsx";
import * as $$$$$$34 from "./sections/Product/SearchResult.tsx";
import * as $$$$$$35 from "./sections/Product/Wishlist.tsx";
import * as $$$$$$36 from "./sections/sideModalPromotion.tsx";
import * as $$$$$$37 from "./sections/Social/InstagramPosts.tsx";
import * as $$$$$$38 from "./sections/Social/WhatsApp.tsx";
import * as $$$$$$39 from "./sections/Theme/Theme.tsx";
import * as $$$$$$$$$$$0 from "./apps/decohub.ts";
import * as $$$$$$$$$$$1 from "./apps/site.ts";

Expand Down Expand Up @@ -78,18 +80,20 @@ const manifest = {
"deco-sites/recommender/sections/Product/ImageGalleryFrontBack.tsx":
$$$$$$24,
"deco-sites/recommender/sections/Product/ImageGallerySlider.tsx": $$$$$$25,
"deco-sites/recommender/sections/Product/NotFound.tsx": $$$$$$26,
"deco-sites/recommender/sections/Product/NotFoundChallenge.tsx": $$$$$$27,
"deco-sites/recommender/sections/Product/ProductInfo.tsx": $$$$$$28,
"deco-sites/recommender/sections/Product/ProductList.tsx": $$$$$$29,
"deco-sites/recommender/sections/Product/ProductShelf.tsx": $$$$$$30,
"deco-sites/recommender/sections/Product/ProductShelfTabbed.tsx": $$$$$$31,
"deco-sites/recommender/sections/Product/SearchResult.tsx": $$$$$$32,
"deco-sites/recommender/sections/Product/Wishlist.tsx": $$$$$$33,
"deco-sites/recommender/sections/sideModalPromotion.tsx": $$$$$$34,
"deco-sites/recommender/sections/Social/InstagramPosts.tsx": $$$$$$35,
"deco-sites/recommender/sections/Social/WhatsApp.tsx": $$$$$$36,
"deco-sites/recommender/sections/Theme/Theme.tsx": $$$$$$37,
"deco-sites/recommender/sections/Product/MostSeen.tsx": $$$$$$26,
"deco-sites/recommender/sections/Product/NotFound.tsx": $$$$$$27,
"deco-sites/recommender/sections/Product/NotFoundChallenge.tsx": $$$$$$28,
"deco-sites/recommender/sections/Product/ProductInfo.tsx": $$$$$$29,
"deco-sites/recommender/sections/Product/ProductList.tsx": $$$$$$30,
"deco-sites/recommender/sections/Product/ProductShelf.tsx": $$$$$$31,
"deco-sites/recommender/sections/Product/ProductShelfTabbed.tsx": $$$$$$32,
"deco-sites/recommender/sections/Product/RecommenderProducts.tsx": $$$$$$33,
"deco-sites/recommender/sections/Product/SearchResult.tsx": $$$$$$34,
"deco-sites/recommender/sections/Product/Wishlist.tsx": $$$$$$35,
"deco-sites/recommender/sections/sideModalPromotion.tsx": $$$$$$36,
"deco-sites/recommender/sections/Social/InstagramPosts.tsx": $$$$$$37,
"deco-sites/recommender/sections/Social/WhatsApp.tsx": $$$$$$38,
"deco-sites/recommender/sections/Theme/Theme.tsx": $$$$$$39,
},
"apps": {
"deco-sites/recommender/apps/decohub.ts": $$$$$$$$$$$0,
Expand Down
106 changes: 106 additions & 0 deletions sections/Product/MostSeen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import type { SectionProps } from "deco/mod.ts";
import { supabase } from "../../routes/supabase/index.ts";
import { calculatePercentageDifference } from "../../utils/CalculatePercentageDifference.ts";
import { countDuplicates } from "../../utils/CountDuplicates.ts";

export type Props = {
title?: string;
subTitle?: string;
};

export async function loader(props: Props, _req: Request, ctx: any) {
const { data } = await supabase.from("recommender").select("*");

const duplicateItemsCount = countDuplicates(data!);

function findFourLargestValues(arr, property) {
arr.sort((a, b) => b[property] - a[property]);
const largestValues = arr.slice(0, 4);
return largestValues;
}

const property = "count";
const trendResult = findFourLargestValues(duplicateItemsCount!, property);

const results = trendResult?.map(async (r) => {
const newUrl = r.key.split("/").splice(3, 10);
const result = await ctx.invoke(
"vtex/loaders/intelligentSearch/productDetailsPage.ts",
{ slug: `/${newUrl.join("/")}` }
);

const salesPrice = parseInt(
result.product.isVariantOf.hasVariant[0].offers.offers[0]
.priceSpecification[1].price
);

const listPrice = parseInt(
result.product.isVariantOf.hasVariant[0].offers.offers[0]
.priceSpecification[0].price
);

const offer = calculatePercentageDifference({
num1: salesPrice,
num2: listPrice,
});

return {
title: result.product.name,
description: result.product.description,
url: result.product.url,
image: result.product.isVariantOf.hasVariant[0].image[0].url,
salesPrice:
result.product.isVariantOf.hasVariant[0].offers.offers[0]
.priceSpecification[1].price,
listPrice:
result.product.isVariantOf.hasVariant[0].offers.offers[0]
.priceSpecification[0].price,
off: Math.round(offer),
};
});

const promiseResult = await Promise.all(results!);

const products = promiseResult;

return {
title: "Trending products 🔥",
subTitle: "The most seen products",
products,
};
}

export default function MostSeen({
title,
subTitle,
products,
}: SectionProps<typeof loader>) {
return (
<div class="mx-auto max-w-2xl px-4 py-16 sm:px-6 sm:py-24 lg:max-w-7xl lg:px-8">
<h2 class="text-2xl leading-8 lg:leading-10 text-base-content text-center lg:text-4xl">
{title}
</h2>
<h3 class="leading-6 lg:leading-8 text-neutral text-center lg:text-2xl">
{subTitle}
</h3>

<div class="grid grid-cols-1 mt-8 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
{products.map((p) => (
<a href={p?.url} class="group">
<div class="aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-lg bg-gray-200 xl:aspect-h-8 xl:aspect-w-7">
<img
src={p?.image}
alt="Tall slender porcelain bottle with natural clay textured body and cork stopper."
class="h-full w-full object-cover object-center group-hover:opacity-75"
/>
</div>
<h3 class="mt-4 text-sm text-gray-700">{p?.title}</h3>
<p class="mt-1 text-lg font-medium text-gray-900">
{p?.salesPrice}
</p>
</a>
))}
</div>
</div>
);
}
55 changes: 11 additions & 44 deletions sections/Product/ProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,8 @@ import type { SectionProps } from "deco/mod.ts";
import type { ImageWidget } from "apps/admin/widgets.ts";
import { supabase } from "../../routes/supabase/index.ts";
import { getIP } from "https://deno.land/x/get_ip/mod.ts";

interface DataItem {
userId: string;
url: string;
count: number;
}

function calculatePercentageDifference({
num1,
num2,
}: {
num1: number;
num2: number;
}) {
const percentageDiff = (num1 / num2) * 100;
return percentageDiff;
}

const countDuplicates = (data: DataItem[]) => {
const countMap = new Map<string, number>();

data.forEach((item) => {
const key = `${item.userId}_${item.url}`;
if (countMap.has(key)) {
countMap.set(key, countMap.get(key)! + 1);
} else {
countMap.set(key, 1);
}
});

const duplicates: DataItem[] = [];
countMap.forEach((count, key) => {
if ((count) => 1) {
const [userId, url] = key.split("_");
duplicates.push({ userId, url, count });
}
});

return duplicates;
};
import { calculatePercentageDifference } from "../../utils/CalculatePercentageDifference.ts";
import { countDuplicatesByUser } from "../../utils/CountDuplicates.ts";

export type Product = {
title?: string;
Expand All @@ -57,6 +19,7 @@ export type Product = {

export type Props = {
title?: string;
subTitle?: string;
products?: Product[];
};

Expand All @@ -71,10 +34,9 @@ export async function loader(props: Props, _req: Request, ctx: any) {
new Map(data?.map((obj) => [obj.url, obj])).values()
);

const duplicateItemsCount = countDuplicates(data!);
const duplicateItemsCount = countDuplicatesByUser(data!);

const results = newData?.map(async (r) => {
// const title = r?.title.replace(/\s+/g, '-').toLowerCase()
const newUrl = r.url.split("/").splice(3, 10);
const result = await ctx.invoke(
"vtex/loaders/intelligentSearch/productDetailsPage.ts",
Expand Down Expand Up @@ -128,22 +90,27 @@ export async function loader(props: Props, _req: Request, ctx: any) {
const products = rawResult.sort((a, b) => b!.timesClicked - a!.timesClicked);

return {
title: "Keep shopping",
title: "Keep shopping 🔍",
subTitle: "Continue where you left off",
products,
};
}

export default function ProductList({
title,
subTitle,
products,
}: SectionProps<typeof loader>) {
return (
<>
{products.length != 0 ? (
<div class="mx-auto max-w-2xl px-4 py-16 sm:px-6 sm:py-24 lg:max-w-7xl lg:px-8 ">
<h2 class="text-2xl font-bold tracking-tight text-gray-900">
<h2 class="text-2xl leading-8 lg:leading-10 text-base-content text-center lg:text-4xl">
{title}
</h2>
<h3 class="leading-6 lg:leading-8 text-neutral text-center lg:text-2xl">
{subTitle}
</h3>

<div class="mt-6 grid grid-cols-1 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-4 xl:gap-x-8">
{products?.map((p) => (
Expand Down
Loading

0 comments on commit 098f98e

Please sign in to comment.