Skip to content

Commit

Permalink
Merge branch 'Weaverse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-phan authored Aug 5, 2024
2 parents 4cf6f3a + c21defb commit ff50208
Show file tree
Hide file tree
Showing 99 changed files with 778 additions and 561 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules
/.mf
.env
.vscode
.idea
.shopify
.turbo
/test-results/
Expand Down
2 changes: 1 addition & 1 deletion app/components/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
InspectorGroup,
HydrogenComponentProps,
HydrogenComponentSchema,
InspectorGroup,
} from "@weaverse/hydrogen";
import type { VariantProps } from "class-variance-authority";
import { cva } from "class-variance-authority";
Expand Down
81 changes: 81 additions & 0 deletions app/components/Marquee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useCallback, useEffect, useRef, useState } from "react";

interface MarqueeProps {
children: React.ReactNode;
gap?: number;
speed?: number;
}
const ANIMATION_SPEED = 100;
export function Marquee({
children,
gap = 0,
speed = ANIMATION_SPEED,
}: MarqueeProps) {
const contentRef = useRef<HTMLDivElement>(null);
const [contentWidth, setContentWidth] = useState(0);
const animationTime = Math.floor(contentWidth / speed);
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
if (contentRef.current && !contentWidth) {
const { width } = contentRef.current.getBoundingClientRect();
setContentWidth(width);
}
}, []);
return (
<div
className="flex items-center"
style={{ ["--animation-speed" as string]: `${animationTime}s` }}
>
{contentWidth === 0 ? (
<div ref={contentRef}>{children}</div>
) : (
<OneView contentWidth={contentWidth} gap={gap}>
{children}
</OneView>
)}
</div>
);
}

function OneView({
children,
contentWidth,
gap,
}: {
children: React.ReactNode;
contentWidth: number;
gap: number;
}) {
const [contentRepeat, setContentRepeat] = useState(0);

const calculateRepeat = useCallback(() => {
if (contentWidth < window.innerWidth) {
// if it is, set the contentRepeat to the number of times the text can fit on the screen
const repeat = Math.ceil(window.innerWidth / (contentWidth + gap));
setContentRepeat(repeat);
}
}, [contentWidth, gap]);
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
calculateRepeat();
window.addEventListener("resize", calculateRepeat);
return () => {
window.removeEventListener("resize", calculateRepeat);
};
}, []);
let oneView = (
<div className="flex" style={{ paddingRight: gap, gap }}>
{Array.from({ length: contentRepeat || 1 }).map((_, index) => (
<div key={index} className="shrink-0">
{children}
</div>
))}
</div>
);
return (
<div className="flex items-center">
<div className="shrink-0 animate-marquee">{oneView}</div>
<div className="shrink-0 animate-marquee">{oneView}</div>
</div>
);
}
6 changes: 3 additions & 3 deletions app/components/SubHeading.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
type HydrogenComponentProps,
type HydrogenComponentSchema,
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from "@weaverse/hydrogen";
import type { VariantProps } from "class-variance-authority";
import { cva } from "class-variance-authority";
Expand Down
4 changes: 2 additions & 2 deletions app/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { HydrogenComponent } from "@weaverse/hydrogen";

import * as Button from "./Button";
import * as Heading from "./Heading";
import * as SubHeading from "./SubHeading";
import * as Paragraph from "./Paragraph";
import * as Button from "./Button";
import * as SubHeading from "./SubHeading";

export let sharedComponents: HydrogenComponent[] = [
SubHeading,
Expand Down
2 changes: 1 addition & 1 deletion app/components/predictive-search/PredictiveSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Input } from "~/modules";
import { IconMagnifyingGlass } from "~/components/Icons";
import { Input } from "~/modules";
import { PredictiveSearchResults } from "./PredictiveSearchResults";
import { PredictiveSearchForm } from "./SearchForm";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Link } from "@remix-run/react";
import clsx from "clsx";
import { SearchResultItem } from "./ResultItem";
import type {
NormalizedPredictiveSearchResultItem,
NormalizedPredictiveSearchResults,
SearchResultTypeProps,
} from "./types";
import clsx from "clsx";

export function PredictiveSearchResult({
goToSearchResult,
Expand Down
5 changes: 4 additions & 1 deletion app/components/predictive-search/SearchForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useFetcher, useParams } from "@remix-run/react";
import { NormalizedPredictiveSearchResults, SearchFromProps } from "./types";
import { useEffect, useRef } from "react";
import type {
NormalizedPredictiveSearchResults,
SearchFromProps,
} from "./types";

/**
* Search form component that posts search requests to the `/search` route
Expand Down
2 changes: 1 addition & 1 deletion app/components/predictive-search/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormProps, useFetcher } from "@remix-run/react";
import type { FormProps, useFetcher } from "@remix-run/react";
import type {
PredictiveArticleFragment,
PredictiveCollectionFragment,
Expand Down
2 changes: 1 addition & 1 deletion app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { StrictMode, startTransition } from "react";
import { hydrateRoot } from "react-dom/client";

startTransition(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RemixServer } from "@remix-run/react";
import { createContentSecurityPolicy } from "@shopify/hydrogen";
import type { AppLoadContext, EntryContext } from "@shopify/remix-oxygen";
import { isbot } from "isbot";
import { renderToReadableStream } from "react-dom/server";
import { createContentSecurityPolicy } from "@shopify/hydrogen";

import { getWeaverseCsp } from "~/weaverse/create-weaverse.server";

Expand Down
2 changes: 1 addition & 1 deletion app/hooks/useIsHydrated.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useEffect, useState } from "react";

// @feedback - This hook could be replaced by remix-utils's ow hook should we want to go down this route.
export function useIsHydrated() {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/cn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clsx, type ClassValue } from "clsx";
import { type ClassValue, clsx } from "clsx";
import { twMerge as merge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ProductFilter } from "@shopify/hydrogen/storefront-api-types";
import type { Location, useLocation } from "@remix-run/react";
import type { ProductFilter } from "@shopify/hydrogen/storefront-api-types";
import { FILTER_URL_PREFIX } from "./const";

export type AppliedFilter = {
Expand Down
31 changes: 15 additions & 16 deletions app/lib/locale.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import type { Locale } from "./type";

export function getCountryUrlPath({
countryLocale,
defaultLocalePrefix,
pathWithoutLocale,
}: {
countryLocale: Locale;
pathWithoutLocale: string;
defaultLocalePrefix: string;
}) {
let countryPrefixPath = "";
const countryLocalePrefix = `${countryLocale.language}-${countryLocale.country}`;

if (countryLocalePrefix !== defaultLocalePrefix) {
countryPrefixPath = `/${countryLocalePrefix.toLowerCase()}`;
}
return `${countryPrefixPath}${pathWithoutLocale}`;
countryLocale,
defaultLocalePrefix,
pathWithoutLocale,
}: {
countryLocale: Locale;
pathWithoutLocale: string;
defaultLocalePrefix: string;
}) {
let countryPrefixPath = "";
const countryLocalePrefix = `${countryLocale.language}-${countryLocale.country}`;

if (countryLocalePrefix !== defaultLocalePrefix) {
countryPrefixPath = `/${countryLocalePrefix.toLowerCase()}`;
}

return `${countryPrefixPath}${pathWithoutLocale}`;
}
5 changes: 3 additions & 2 deletions app/modules/AccountAddressBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ function Address({
address?.lastName}
</li>
)}
{address.formatted &&
address.formatted.map((line: string) => <li key={line}>{line}</li>)}
{address.formatted?.map((line: string) => (
<li key={line}>{line}</li>
))}
</ul>

<div className="flex flex-row font-medium mt-6 items-baseline">
Expand Down
14 changes: 9 additions & 5 deletions app/modules/Cart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
CartForm,
type CartReturn,
Image,
Money,
type OptimisticCart,
Expand Down Expand Up @@ -38,9 +37,9 @@ export function Cart({
}: {
layout: Layouts;
onClose?: () => void;
cart: CartReturn | null;
cart: CartApiQueryFragment;
}) {
let optimisticCart = useOptimisticCart(cart);
let optimisticCart = useOptimisticCart<CartApiQueryFragment>(cart);

const linesCount = Boolean(optimisticCart?.lines?.nodes?.length || 0);

Expand Down Expand Up @@ -101,7 +100,7 @@ function CartDiscounts({
<Text as="dt">Discount(s)</Text>
<div className="flex items-center justify-between">
<UpdateDiscountForm>
<button>
<button type="button">
<IconRemove
aria-hidden="true"
style={{ height: 18, marginRight: 4 }}
Expand All @@ -127,7 +126,10 @@ function CartDiscounts({
name="discountCode"
placeholder="Discount code"
/>
<button className="flex justify-end font-medium whitespace-nowrap">
<button
type="button"
className="flex justify-end font-medium whitespace-nowrap"
>
Apply Discount
</button>
</div>
Expand Down Expand Up @@ -353,6 +355,7 @@ function CartLineQuantityAdjust({ line }: { line: CartLine }) {
<div className="flex items-center border rounded">
<UpdateCartButton lines={[{ id: lineId, quantity: prevQuantity }]}>
<button
type="button"
name="decrease-quantity"
aria-label="Decrease quantity"
className="w-10 h-10 transition text-secondary/50 hover:text-secondary disabled:text-secondary/10"
Expand All @@ -373,6 +376,7 @@ function CartLineQuantityAdjust({ line }: { line: CartLine }) {

<UpdateCartButton lines={[{ id: lineId, quantity: nextQuantity }]}>
<button
type="button"
className="w-10 h-10 transition text-secondary/50 hover:text-secondary disabled:text-secondary/10"
name="increase-quantity"
value={nextQuantity}
Expand Down
5 changes: 2 additions & 3 deletions app/modules/CountrySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function CountrySelector() {
const { pathname, search } = useLocation();
const pathWithoutLocale = `${pathname.replace(
selectedLocale.pathPrefix,
""
"",
)}${search}`;

const countries = (fetcher.data ?? {}) as Localizations;
Expand Down Expand Up @@ -65,7 +65,6 @@ export function CountrySelector() {
redirectTo: string;
buyerIdentity: CartBuyerIdentityInput;
}) => {
console.log("🚀 ~ CountrySelector:", buyerIdentity, redirectTo);
const cartFormInput = {
action: CartForm.ACTIONS.BuyerIdentityUpdate,
inputs: { buyerIdentity },
Expand All @@ -83,7 +82,7 @@ export function CountrySelector() {
return (
<div ref={observerRef} className="grid gap-4 w-80">
<Popover>
<PopoverButton className="w-full border rounded border-contrast/30 overflow-clip px-4 py-3 cursor-pointer text-left outline-none flex items-center justify-between gap-2">
<PopoverButton className="w-full border border-contrast/30 overflow-clip px-4 py-3 cursor-pointer text-left outline-none flex items-center justify-between gap-2">
{selectedLocale.label}
<IconCaretDown className="w-5 h-5" />
</PopoverButton>
Expand Down
6 changes: 3 additions & 3 deletions app/modules/FeaturedProducts.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import clsx from "clsx";
import { useEffect, useId, useMemo } from "react";
import { useFetcher } from "@remix-run/react";
import type {
Product,
ProductSortKeys,
} from "@shopify/hydrogen/storefront-api-types";
import clsx from "clsx";
import { useEffect, useId, useMemo } from "react";

import { Heading, ProductCard, Skeleton, Text } from "~/modules";
import { usePrefixPathWithLocale } from "~/lib/utils";
import { Heading, ProductCard, Skeleton, Text } from "~/modules";

interface FeaturedProductsProps {
count: number;
Expand Down
2 changes: 1 addition & 1 deletion app/modules/FeaturedSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from "react";
import { useFetcher } from "@remix-run/react";
import { useEffect } from "react";
import { usePrefixPathWithLocale } from "~/lib/utils";
import type { FeaturedData } from "~/routes/($locale).featured-products";
import { ProductSwimlane } from "./ProductSwimlane";
Expand Down
Loading

0 comments on commit ff50208

Please sign in to comment.