Skip to content

Commit

Permalink
chore(sm): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaoxuan committed Oct 28, 2024
1 parent 833eaee commit 69e76f8
Show file tree
Hide file tree
Showing 38 changed files with 176,260 additions and 25,151 deletions.
27 changes: 0 additions & 27 deletions starters/shopify-meilisearch/app/actions/collection.actions.ts

This file was deleted.

8 changes: 0 additions & 8 deletions starters/shopify-meilisearch/app/actions/page.actions.ts

This file was deleted.

84 changes: 0 additions & 84 deletions starters/shopify-meilisearch/app/actions/product.actions.ts

This file was deleted.

2 changes: 0 additions & 2 deletions starters/shopify-meilisearch/app/api/redirects/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ type RedirectEntry = {
permanent: boolean
}

export const runtime = "edge"

export function GET(request: NextRequest) {
const pathname = request.nextUrl.searchParams.get("pathname")

Expand Down
2 changes: 1 addition & 1 deletion starters/shopify-meilisearch/app/favorites/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cookies } from "next/headers"
import { Suspense } from "react"
import { getProduct } from "app/actions/product.actions"
import { ProductCard } from "components/product-card"
import { Skeleton } from "components/ui/skeleton"
import { COOKIE_FAVORITES } from "constants/index"
import { getProduct } from "clients/search"

export const revalidate = 86400

Expand Down
2 changes: 1 addition & 1 deletion starters/shopify-meilisearch/app/pages/[slug]/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPage } from "clients/storefrontClient"
import { Metadata } from "next"
import { getPage } from "app/actions/page.actions"

export async function generateMetadata({ params: { slug } }: { params: { slug: string } }): Promise<Metadata> {
const page = await getPage(slug)
Expand Down
2 changes: 1 addition & 1 deletion starters/shopify-meilisearch/app/pages/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { format } from "date-fns/format"
import { getAllPages, getPage } from "app/actions/page.actions"
import { getAllPages, getPage } from "clients/storefrontClient"

export const revalidate = 86400
export const dynamic = "force-static"
Expand Down
6 changes: 3 additions & 3 deletions starters/shopify-meilisearch/app/product/[slug]/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getProduct } from "clients/search"
import { env } from "env.mjs"
import { Metadata } from "next"
import { Product, WithContext } from "schema-dts"
import { getProduct } from "app/actions/product.actions"
import { env } from "env.mjs"
import type { CommerceProduct } from "types"
import { makeKeywords } from "utils/make-keywords"
import { removeOptionsFromUrl } from "utils/product-options-utils"
import type { CommerceProduct } from "types"
import { slugToName } from "utils/slug-name"

interface ProductProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* eslint-disable jsx-a11y/alt-text */

import { ImageResponse } from "next/og"
import { getProduct } from "app/actions/product.actions"
import { removeOptionsFromUrl } from "utils/product-options-utils"
import { env } from "env.mjs"
import { getProduct } from "clients/search"

export const revalidate = 86400

Expand Down
42 changes: 18 additions & 24 deletions starters/shopify-meilisearch/app/product/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { getProduct, getProductReviews } from "app/actions/product.actions"
import { Breadcrumbs } from "components/breadcrumbs"
import { notFound } from "next/navigation"

import { getProduct, meilisearch } from "clients/search"

import { env } from "env.mjs"

import { isDemoMode } from "utils/demo-utils"
import { slugToName } from "utils/slug-name"
import { CurrencyType, mapCurrencyToSign } from "utils/map-currency-to-sign"
import { getCombination, getOptionsFromUrl, hasValidOption, removeOptionsFromUrl } from "utils/product-options-utils"

import { Breadcrumbs } from "components/breadcrumbs"

import { BackButton } from "views/product/back-button"
import { FavoriteMarker } from "views/product/favorite-marker"
import { SimilarProductsSection } from "views/product/similar-products-section"
import { SimilarProductsSectionSkeleton } from "views/product/similar-product-section-skeleton"
import { VariantsSection } from "views/product/variants-section"
import { slugToName } from "utils/slug-name"

import { generateJsonLd } from "./metadata"
import { ReviewsSection } from "views/product/reviews-section"

import type { CommerceProduct } from "types"
import { isDemoMode } from "utils/demo-utils"
import { meilisearch } from "clients/search"
import { env } from "env.mjs"
import { ProductTitle } from "views/product/product-title"
import { CurrencyType, mapCurrencyToSign } from "utils/map-currency-to-sign"
import { ProductImages } from "views/product/product-images"
import { RightSection } from "views/product/right-section"
import { FaqSection } from "views/product/faq-section"
import { AddToCartButton } from "views/product/add-to-cart-button"
import { ReviewsSection } from "views/product/reviews-section"

import type { CommerceProduct } from "types"

import { generateJsonLd } from "./metadata"

export const revalidate = 86400
export const dynamic = "force-static"
Expand All @@ -33,8 +36,6 @@ interface ProductProps {
params: { slug: string }
}

export { generateMetadata } from "./metadata"

export async function generateStaticParams() {
if (isDemoMode()) return []

Expand All @@ -50,7 +51,7 @@ export async function generateStaticParams() {
}

export default async function Product({ params: { slug } }: ProductProps) {
const [product, { reviews, total: totalReviews }] = await Promise.all([getProduct(removeOptionsFromUrl(slug)), getProductReviews(removeOptionsFromUrl(slug), { limit: 16 })])
const product = await getProduct(removeOptionsFromUrl(slug))

const { color } = getOptionsFromUrl(slug)
const hasInvalidOptions = !hasValidOption(product?.variants, "color", color)
Expand Down Expand Up @@ -97,14 +98,7 @@ export default async function Product({ params: { slug } }: ProductProps) {
</RightSection>
</div>
<Suspense>
<ReviewsSection
avgRating={product.avgRating}
productHandle={product.handle}
productId={product.id}
reviews={reviews?.map((review) => ({ ...review, author: review.reviewer.name })) || []}
total={totalReviews}
summary={product.reviewsSummary}
/>
<ReviewsSection avgRating={product.avgRating} productHandle={product.handle} productId={product.id} slug={slug} summary={product.reviewsSummary} />
</Suspense>
<Suspense fallback={<SimilarProductsSectionSkeleton />}>
<SimilarProductsSection collectionHandle={lastCollection?.handle} slug={slug} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getProduct } from "app/actions/product.actions"
import { env } from "process"
import { makeKeywords } from "utils/make-keywords"
import { removeOptionsFromUrl } from "utils/product-options-utils"
import type { ProductReviewsPageProps } from "./page"
import { Metadata } from "next"
import { getProduct } from "clients/search"

export async function generateMetadata({ params: { slug } }: ProductReviewsPageProps): Promise<Metadata> {
const product = await getProduct(removeOptionsFromUrl(slug))
Expand Down
27 changes: 13 additions & 14 deletions starters/shopify-meilisearch/app/reviews/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { notFound, redirect } from "next/navigation"
import { getProduct, getProductReviews } from "app/actions/product.actions"

import { getProduct, getProductReviews } from "clients/search"

import { Breadcrumbs } from "components/breadcrumbs"

import { BackButton } from "views/product/back-button"
Expand All @@ -8,6 +10,7 @@ import { PaginationSection } from "views/listing/pagination-section"

import { removeOptionsFromUrl } from "utils/product-options-utils"
import type { CommerceProduct } from "types"
import { HITS_PER_PAGE } from "constants/index"

export { generateMetadata } from "./metadata"

Expand All @@ -19,29 +22,29 @@ export interface ProductReviewsPageProps {
}

export default async function ProductReviews({ params: { slug }, searchParams }: ProductReviewsPageProps) {
return <ProductReviewsView searchParams={searchParams} slug={slug} />
}

async function ProductReviewsView({ slug, searchParams }: { slug: string; searchParams: ProductReviewsPageProps["searchParams"] }) {
const limit = 20
const page = searchParams.page ? parseInt(searchParams.page as string) : 1

const product = await getProduct(removeOptionsFromUrl(slug))
const { reviews, total: totalReviews } = await getProductReviews(removeOptionsFromUrl(slug), { limit, page })
const [product, { reviews, total: totalReviews }] = await Promise.all([
getProduct(removeOptionsFromUrl(slug)),
getProductReviews(removeOptionsFromUrl(slug), { HITS_PER_PAGE, page }),
])

const totalPages = Math.ceil(totalReviews / limit)
const totalPages = Math.ceil(totalReviews / HITS_PER_PAGE)

if (!product) {
return notFound()
}

if (page > Math.ceil(totalReviews / HITS_PER_PAGE)) {
redirect(`/reviews/${slug}`)
}

if (totalReviews <= 0) {
return (
<div className="relative mx-auto mb-20 max-w-container-md px-4 xl:px-0">
<div className="relative w-fit py-4 md:pt-12">
<BackButton href={`/product/${product.handle}`} className="mb-8 hidden md:block" />
</div>

<main className="container mx-auto max-w-5xl px-4 md:px-6">
<Breadcrumbs className="mb-8" items={makeBreadcrumbs(product)} />
<div className="my-20 text-center">
Expand All @@ -53,10 +56,6 @@ async function ProductReviewsView({ slug, searchParams }: { slug: string; search
)
}

if (page > Math.ceil(totalReviews / limit)) {
redirect(`/reviews/${slug}`)
}

return (
<div className="relative mx-auto mb-20 max-w-container-md px-4 xl:px-0">
<div className="relative w-fit py-4 md:pt-12">
Expand Down
Loading

0 comments on commit 69e76f8

Please sign in to comment.