Skip to content

Commit 94e33c6

Browse files
authored
RFC/refactor: code-split ui package (#234)
* refactor: split the code * 'chore: update @preconstruct/cli and typescript versions for compatibility * chore: update imports * fix: use correct styles.css imports * docs: add documentation on how to add components in ui package
1 parent 86147ee commit 94e33c6

File tree

77 files changed

+537
-285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+537
-285
lines changed

core/app/(user)/forgot/ForgotForm.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"use client";
22
import React, { FormEvent, useState } from "react";
3-
import { Button, Icon } from "ui";
3+
import { Button } from "ui/button";
4+
import { Loader2 } from "ui/icon";
5+
46
import { supabase } from "lib/supabase";
57
import { useEnvContext } from "next-runtime-env";
68

7-
89
export default function ForgotForm() {
9-
const { NEXT_PUBLIC_PUBPUB_URL } = useEnvContext()
10+
const { NEXT_PUBLIC_PUBPUB_URL } = useEnvContext();
1011

1112
const [email, setEmail] = useState("");
1213
const [isLoading, setIsLoading] = useState(false);
@@ -50,9 +51,7 @@ export default function ForgotForm() {
5051

5152
<Button variant="outline" type="submit" disabled={!email || isLoading}>
5253
Send password reset email
53-
{isLoading && (
54-
<Icon.Loader2 className="h-4 w-4 ml-4 animate-spin" />
55-
)}
54+
{isLoading && <Loader2 className="h-4 w-4 ml-4 animate-spin" />}
5655
</Button>
5756

5857
{failure && (

core/app/(user)/login/LoginForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22
import React, { useState, FormEvent } from "react";
3-
import { Button } from "ui";
3+
import { Button } from "ui/button";
44
import { supabase } from "lib/supabase";
55
import Link from "next/link";
66
import { useRouter } from "next/navigation";
@@ -38,7 +38,7 @@ export default function LoginForm() {
3838
router.push("/settings");
3939
}
4040
}
41-
}
41+
};
4242

4343
return (
4444
<div className="border p-4">

core/app/(user)/reset/ResetForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22
import React, { useState, FormEvent } from "react";
3-
import { Button, Icon } from "ui";
3+
import { Button } from "ui/button";
4+
import { Loader2 } from "ui/icon";
45
import { formatSupabaseError, supabase } from "lib/supabase";
56
import { useRouter } from "next/navigation";
67

@@ -57,7 +58,7 @@ export default function ResetForm() {
5758

5859
<Button variant="outline" type="submit" disabled={!password || isLoading}>
5960
Set new password
60-
{isLoading && <Icon.Loader2 className="h-4 w-4 ml-4 animate-spin" />}
61+
{isLoading && <Loader2 className="h-4 w-4 ml-4 animate-spin" />}
6162
</Button>
6263

6364
{error && (

core/app/(user)/settings/SettingsForm.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { supabase } from "lib/supabase";
44
import Link from "next/link";
55
import { useRouter } from "next/navigation";
66
import { FormEvent, useState } from "react";
7-
import { Avatar, AvatarFallback, AvatarImage, Button, Icon } from "ui";
7+
import { Button } from "ui/button";
8+
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
9+
import { Loader2 } from "ui/icon";
810
import LogoutButton from "~/app/components/LogoutButton";
911
import { UserPutBody, UserSettings } from "~/lib/types";
1012
import { useEnvContext } from "next-runtime-env";
@@ -162,7 +164,7 @@ export default function SettingsForm({
162164
{!resetSuccess && (
163165
<Button onClick={resetPassword} disabled={resetIsLoading}>
164166
Send password reset email
165-
{resetIsLoading && <Icon.Loader2 className="h-4 w-4 ml-4 animate-spin" />}
167+
{resetIsLoading && <Loader2 className="h-4 w-4 ml-4 animate-spin" />}
166168
</Button>
167169
)}
168170
{resetSuccess && (

core/app/(user)/signup/SignupForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22
import React, { useState, FormEvent } from "react";
3-
import { Button } from "ui";
3+
import { Button } from "ui/button";
44
import { UserPostBody } from "~/lib/types";
55

66
export default function SignupForm() {

core/app/InitClient.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ import { useEffect } from "react";
33
import { REFRESH_NAME, TOKEN_NAME } from "lib/auth/cookies";
44
import { createBrowserSupabase, supabase } from "lib/supabase";
55
import { usePathname } from "next/navigation";
6-
import { useEnvContext } from 'next-runtime-env';
6+
import { useEnvContext } from "next-runtime-env";
77

88
export default function InitClient() {
9-
const { NEXT_PUBLIC_SUPABASE_PUBLIC_KEY , NEXT_PUBLIC_SUPABASE_URL } = useEnvContext();
9+
const { NEXT_PUBLIC_SUPABASE_PUBLIC_KEY, NEXT_PUBLIC_SUPABASE_URL } = useEnvContext();
1010

1111
const pathname = usePathname();
1212
useEffect(() => {
1313
const isLocalhost = window.location.origin.includes("localhost");
1414
const securityValue = isLocalhost ? "secure" : "";
15-
createBrowserSupabase(
16-
NEXT_PUBLIC_SUPABASE_URL,
17-
NEXT_PUBLIC_SUPABASE_PUBLIC_KEY
18-
);
15+
createBrowserSupabase(NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_PUBLIC_KEY);
1916
supabase.auth.onAuthStateChange(async (event, session) => {
2017
if (event === "SIGNED_OUT") {
2118
// delete cookies on sign out

core/app/c/[communitySlug]/CommunitySwitcher.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import Link from "next/link";
2+
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
23
import {
3-
Avatar,
4-
AvatarFallback,
5-
AvatarImage,
64
DropdownMenu,
75
DropdownMenuItem,
86
DropdownMenuContent,
97
DropdownMenuTrigger,
10-
} from "ui";
8+
} from "ui/dropdown-menu";
119
import { CommunityData } from "./layout";
1210

1311
type Props = {

core/app/c/[communitySlug]/LoginSwitcher.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getLoginData } from "~/lib/auth/loginData";
2-
import { Avatar, AvatarFallback, AvatarImage, Button } from "ui";
2+
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
3+
import { Button } from "ui/button";
34
import LogoutButton from "../../components/LogoutButton";
45
import Link from "next/link";
56

@@ -27,7 +28,9 @@ export default async function LoginSwitcher() {
2728
<div className="mt-1 flex flex-row items-">
2829
<LogoutButton />
2930
<Link className="ml-2" href="/settings">
30-
<Button variant="outline" size="sm">Settings</Button>
31+
<Button variant="outline" size="sm">
32+
Settings
33+
</Button>
3134
</Link>
3235
</div>
3336
</div>

core/app/c/[communitySlug]/integrations/IntegrationsList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use client";
22

33
import NextLink from "next/link";
4-
import { Button, Card, CardContent, CardHeader } from "ui";
4+
5+
import { Button } from "ui/button";
6+
import { Card, CardContent, CardHeader } from "ui/card";
57
import { IntegrationData } from "./page";
68
import { Row, RowContent, RowFooter } from "~/app/components/Row";
79

core/app/c/[communitySlug]/pubs/PubHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Link from "next/link";
2-
import { Button } from "ui";
2+
import { Button } from "ui/button";
33

44
type Props = {};
55

core/app/c/[communitySlug]/pubs/[pubId]/page.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import { Prisma, PubField, PubFieldSchema, PubValue } from "@prisma/client";
22
import { AnySchema, JSONSchemaType } from "ajv";
33
import Link from "next/link";
4-
import {
5-
Avatar,
6-
AvatarFallback,
7-
AvatarImage,
8-
Button,
9-
CardContent,
10-
CardHeader,
11-
CardTitle,
12-
HoverCard,
13-
HoverCardContent,
14-
HoverCardTrigger,
15-
Separator,
16-
} from "ui";
4+
import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
5+
import { Button } from "ui/button";
6+
import { CardContent, CardHeader, CardTitle } from "ui/card";
7+
import { HoverCard, HoverCardContent, HoverCardTrigger } from "ui/hover-card";
8+
import { Separator } from "ui/separator";
179

1810
import IntegrationActions from "~/app/components/IntegrationActions";
1911
import { PubTitle } from "~/app/components/PubTitle";

core/app/c/[communitySlug]/stages/components/Assign.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
"use client";
22
import Image from "next/image";
33
import React from "react";
4-
import {
5-
Button,
6-
Card,
7-
CardContent,
8-
CardFooter,
9-
CardTitle,
10-
Dialog,
11-
DialogContent,
12-
DialogTrigger,
13-
Popover,
14-
PopoverContent,
15-
PopoverTrigger,
16-
useToast,
17-
} from "ui";
4+
import { Button } from "ui/button";
5+
import { Card, CardContent, CardFooter, CardTitle } from "ui/card";
6+
import { Dialog, DialogContent, DialogTrigger } from "ui/dialog";
7+
import { Popover, PopoverContent, PopoverTrigger } from "ui/popover";
8+
import { useToast } from "ui/use-toast";
9+
1810
import {
1911
PermissionPayloadUser,
2012
PubPayload,

core/app/c/[communitySlug]/stages/components/Move.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client";
2-
import { Button, Popover, PopoverContent, PopoverTrigger, useToast } from "ui";
2+
import { Button } from "ui/button";
3+
import { useToast } from "ui/use-toast";
4+
import { Popover, PopoverContent, PopoverTrigger } from "ui/popover";
35
import { PubPayload, StagePayload, StagePayloadMoveConstraintDestination } from "~/lib/types";
46
import { move } from "./lib/actions";
57

core/app/c/[communitySlug]/stages/components/StageList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Link from "next/link";
44
import { Fragment } from "react";
5-
import { Button } from "ui";
5+
import { Button } from "ui/button";
66
import PubRow from "~/app/components/PubRow";
77
import { getPubUsers } from "~/lib/permissions";
88
import { StagesById, StagePayload, UserLoginData } from "~/lib/types";

core/app/c/[communitySlug]/stages/manage/StageEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from "react";
2-
import { Tabs, TabsContent, TabsList, TabsTrigger, toast } from "ui";
2+
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui/tabs";
3+
import { toast } from "ui/use-toast";
34
import { StageFormSchema, moveConstraintSourcesForStage } from "~/lib/stages";
45
import { DeepPartial, StagesById, StagePayload } from "~/lib/types";
56
import StageForm from "./StageForm";

core/app/c/[communitySlug]/stages/manage/StageForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { useCallback, useEffect } from "react";
22
import { useForm } from "react-hook-form";
3+
import { Button } from "ui/button";
34
import {
4-
Button,
55
Form,
66
FormControl,
77
FormDescription,
88
FormField,
99
FormItem,
1010
FormLabel,
1111
FormMessage,
12-
Icon,
13-
Input,
14-
} from "ui";
12+
} from "ui/form";
13+
import * as Icon from "ui/icon";
14+
import { Input } from "ui/input";
1515
import { assert } from "utils";
1616
import { StageFormSchema } from "~/lib/stages";
1717
import { StagePayload, StagesById, DeepPartial } from "~/lib/types";

core/app/c/[communitySlug]/stages/manage/StageManagement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useState } from "react";
4-
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui";
4+
import { Tabs, TabsContent, TabsList, TabsTrigger } from "ui/tabs";
55
import StageEditor from "./StageEditor";
66
import { StagePayload, StagesById } from "~/lib/types";
77

core/app/c/[communitySlug]/types/TypeBlock.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22
import { useState } from "react";
3-
import { Button, Card, CardContent } from "ui";
3+
import { Button } from "ui/button";
4+
import { Card, CardContent } from "ui/card";
45
import { TypesData } from "./page";
56

67
type Props = { type: NonNullable<TypesData>[number] };

core/app/components/IntegrationActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Popover, PopoverTrigger, Button, PopoverContent } from "ui";
1+
import { Button } from "ui/button";
22
import { PubPayload } from "~/lib/types";
33

44
type Props = {

core/app/components/LogoutButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22
import { supabase } from "~/lib/supabase";
3-
import { Button } from "ui";
3+
import { Button } from "ui/button";
44
import { useRouter } from "next/navigation";
55

66
export default function LogoutButton() {

core/app/components/PubRow.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import Link from "next/link";
44
import React, { Fragment } from "react";
5-
import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from "ui";
5+
import { Button } from "ui/button";
6+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "ui/collapsible";
67
import { cn } from "utils";
78
import { PubPayload } from "~/lib/types";
89
import IntegrationActions from "./IntegrationActions";
@@ -48,7 +49,10 @@ const ChildHierarchy = ({ pub }: { pub: PubPayload["children"][number] }) => {
4849
<span className="text-gray-500 mr-2 font-semibold">
4950
{group.pubType.name}
5051
</span>
51-
<Link href={`/pubs/${child.id}`} className="text-sm hover:underline">
52+
<Link
53+
href={`/pubs/${child.id}`}
54+
className="text-sm hover:underline"
55+
>
5256
{getTitle(child)}
5357
</Link>
5458
</div>

core/app/components/Row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { PropsWithChildren } from "react";
4-
import { Card, CardContent, CardFooter, CardHeader } from "ui";
4+
import { Card, CardContent, CardFooter, CardHeader } from "ui/card";
55
import { cn } from "utils";
66

77
type Props = PropsWithChildren<{ className?: string }>;

core/app/layout.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Toaster } from "ui";
1+
import { Toaster } from "ui/toaster";
22
import "ui/styles.css";
33
import InitClient from "./InitClient";
4-
import { PublicEnvProvider } from 'next-runtime-env';
4+
import { PublicEnvProvider } from "next-runtime-env";
55
import "./globals.css";
66

77
export const metadata = {
@@ -13,11 +13,11 @@ export default function RootLayout({ children }: { children: React.ReactNode })
1313
return (
1414
<html lang="en">
1515
<body>
16-
<PublicEnvProvider>
17-
<InitClient />
18-
{children}
19-
<Toaster />
20-
</PublicEnvProvider>
16+
<PublicEnvProvider>
17+
<InitClient />
18+
{children}
19+
<Toaster />
20+
</PublicEnvProvider>
2121
</body>
2222
</html>
2323
);

core/lib/supabase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export const createBrowserSupabase = (url, publicKey) => {
1111
});
1212
};
1313

14-
export const formatSupabaseError = (error: AuthError) => `${error.name} ${error.status}: ${error.message}`
14+
export const formatSupabaseError = (error: AuthError) =>
15+
`${error.name} ${error.status}: ${error.message}`;

core/scripts/invite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { randomUUID } from "crypto";
88
import { unJournalId } from "../prisma/exampleCommunitySeeds/unjournal";
99

1010
const getServerSupabase = () => {
11-
// can use the process.env here, because this code only runs in server context
11+
// can use the process.env here, because this code only runs in server context
1212
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
1313
const key = process.env.SUPABASE_SERVICE_ROLE_KEY;
1414
if (!url || !key) {

infrastructure/terraform/aws/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Dependencies
44

55
### State file bucket/config
6+
67
You must have some way of storing terraform state files.
78
We use and recommend the s3 backend, but you can change
89
that configuration. In order to keep this code generic, however,
@@ -24,7 +25,6 @@ If you need to change the backend, update this file and `init` again.
2425
the module exposes its configuration area, but those configurations
2526
need to be supplied at plan/apply time using the flag `-var-file=demo-env.tfvars`.
2627

27-
2828
## Adding secrets
2929

3030
To provide secrets to ECS containers, you should put them in AWS Secrets Manager.

0 commit comments

Comments
 (0)