Skip to content

Commit

Permalink
refactor(www): use new trpc root provider
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Nov 17, 2024
1 parent 251b1df commit c4f370b
Show file tree
Hide file tree
Showing 35 changed files with 677 additions and 398 deletions.
5 changes: 1 addition & 4 deletions apps/www/app/(auth)/signup/student/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//

import { TrpcRootProvider } from ":trpc/root";
import { TRPC_SSR } from ":trpc/server";
import Form from ":widgets/auth/SignUpForm";
import { auth } from "@1.modules/auth.next";
Expand Down Expand Up @@ -38,9 +37,7 @@ async function Page() {

return (
<main className={base()}>
<TrpcRootProvider>
<Form categories={await TRPC_SSR.category.exchange.fetch()} />
</TrpcRootProvider>
<Form categories={await TRPC_SSR.category.exchange.fetch()} />
</main>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import { ProfileAvatarMedia } from ":components/avatar";
import type { inferInfiniteQueryObserverSuccessResult } from ":components/inferQueryResult";
import { Loading_Placeholder } from ":components/placeholder/Loading_Placeholder";
import { TRPC_React } from ":trpc/client";
import type { AvatarProfile } from "@1.modules/profile.domain";
import { EmptyList, LoadMoreButton } from "@1.ui/react/async";
import { button_item } from "@1.ui/react/button/atom";
import { Spinner } from "@1.ui/react/spinner";
import Link from "next/link";
import { P, match } from "ts-pattern";
import Loading_Placeholder from "../loading";

//

Expand Down
5 changes: 3 additions & 2 deletions apps/www/app/(main)/exchanges/@categories/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useSyncSearchQuery } from ":components/hooks/useSyncSearchQuery";
import { useAutoClose } from ":components/shell/AsideFilter.client";
import { TRPC_React } from ":trpc/client";
import { trpc_client } from "@1.infra/trpc/react-query/client";
import { CATEGORY_ALL } from "@1.modules/category.domain";
import { FilterRadioList } from "@1.ui/react/form/FilterRadioList";
import { usePathname, useRouter } from "next/navigation";
Expand All @@ -13,7 +13,8 @@ import { useMemo } from "react";
export function Filter() {
const { query, setQuery } = useSyncSearchQuery("category");
const { query: filter } = useSyncSearchQuery("f");
const { data: categories_, status } = TRPC_React.category.exchange.useQuery();
const { data: categories_, status } =
trpc_client.category.exchange.useQuery();
const { close } = useAutoClose();
const pathname = usePathname() ?? "";
const router = useRouter();
Expand Down
17 changes: 4 additions & 13 deletions apps/www/app/(main)/exchanges/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
///

import { AsideFilter } from ":components/shell/AsideFilter";
import { Exchanges_Filter } from ":widgets/exchanges/filter";
import { SearchForm } from ":widgets/exchanges/list";
import { Grid } from "@1.ui/react/grid";
import InputSearch from "@1.ui/react/input/InputSearch";
import dynamic from "next/dynamic";
import type { PropsWithChildren, ReactNode } from "react";
import { Exchanges_Filter } from "./_client/Exchanges_Filter";

//

const SearchForm = dynamic(() => import("./_client/SearchForm"), {
loading() {
return <InputSearch />;
},
});

//

Expand All @@ -37,9 +28,9 @@ export default async function Layout({
{categories}
</AsideFilter>
<div className="col-span-full md:col-span-6 md:my-10">{children}</div>
<aside className="mt-10 hidden xl:col-span-3 xl:block xl:px-10">
{/* <aside className="mt-10 hidden xl:col-span-3 xl:block xl:px-10">
{see_also}
</aside>
</aside> */}
</Grid>
);
}
6 changes: 3 additions & 3 deletions apps/www/app/(main)/exchanges/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//

import { TRPC_Hydrate } from ":trpc/server";
import { List } from ":widgets/exchanges/list";
import { trpc_server } from "@1.infra/trpc/react-query/server";
import { getServerSession } from "@1.modules/auth.next";
import { auth } from "@1.modules/auth.next";
import {
Exchange_Filter,
type ExchangeSearchParams,
Expand All @@ -12,7 +13,6 @@ import { PlusBox } from "@1.ui/react/icons";
import { link } from "@1.ui/react/link/atom";
import type { Metadata, ResolvingMetadata } from "next";
import Link from "next/link";
import List from "./_client/List";

//

Expand Down Expand Up @@ -61,7 +61,7 @@ export default async function Page({
}

async function NewExchangeSection() {
const session = await getServerSession();
const session = await auth();

if (!session) return null;
if (session.profile.role !== "STUDENT") return null;
Expand Down
4 changes: 2 additions & 2 deletions apps/www/app/(main)/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from ":components/navbar/notification_indicator.client";
import { MobileNavBar } from ":components/shell/MobileNavBar";
import { TRPC_SSR } from ":trpc/server";
import { getServerSession } from "@1.modules/auth.next";
import { auth } from "@1.modules/auth.next";
import { PROFILE_ROLES, type AuthProfile } from "@1.modules/profile.domain";
import { Avatar } from "@1.modules/profile.ui";
import { Grid } from "@1.ui/react/grid";
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function UserBar() {
}

async function UserNavGroup({ className }: ComponentPropsWithoutRef<"nav">) {
const session = await getServerSession();
const session = await auth();
const { base, icon } = user_nav_group_variants({
size: {
initial: "xsmall",
Expand Down
18 changes: 9 additions & 9 deletions apps/www/components/navbar/notification_indicator.client.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { TRPC_React } from ":trpc/client";
import { trpc_client } from "@1.infra/trpc/react-query/client";
import { useSession } from "@1.modules/auth.next/react";
import { NotificationGroup } from "@1.modules/notification.domain";
import { DotIndicator } from "@1.modules/notification.ui/DotIndicator";
Expand All @@ -11,8 +11,8 @@ import { useAsync, useUpdateEffect } from "@react-hookz/web";

export function Notification_DotIndicator() {
const { status } = useSession();
const utils = TRPC_React.useUtils();
const { data: count_unread } = TRPC_React.notification.count_unread.useQuery(
const utils = trpc_client.useUtils();
const { data: count_unread } = trpc_client.notification.count_unread.useQuery(
{},
{
enabled: status === "authenticated",
Expand Down Expand Up @@ -43,9 +43,9 @@ export function Notification_DotIndicator() {

export function MessageNews_DotIndicator() {
const { status } = useSession();
const utils = TRPC_React.useUtils();
const utils = trpc_client.useUtils();
const { data: count_unread, dataUpdatedAt } =
TRPC_React.notification.count_unread.useQuery(
trpc_client.notification.count_unread.useQuery(
{
type: NotificationGroup.Enum.INBOX,
},
Expand All @@ -64,9 +64,9 @@ export function MessageNews_DotIndicator() {

export function ExchangeNews_DotIndicator() {
const { status } = useSession();
const utils = TRPC_React.useUtils();
const utils = trpc_client.useUtils();
const { data: count_unread, dataUpdatedAt } =
TRPC_React.notification.count_unread.useQuery(
trpc_client.notification.count_unread.useQuery(
{
type: NotificationGroup.Enum.EXCHANGE,
},
Expand All @@ -85,7 +85,7 @@ export function ExchangeNews_DotIndicator() {

export function NewsInMessage_Indicator() {
const { status } = useSession();
const { data: count_unread } = TRPC_React.notification.count_unread.useQuery(
const { data: count_unread } = trpc_client.notification.count_unread.useQuery(
{
type: NotificationGroup.Enum.INBOX,
},
Expand All @@ -96,7 +96,7 @@ export function NewsInMessage_Indicator() {

export function NewsInExchange_Indicator() {
const { status } = useSession();
const { data: count_unread } = TRPC_React.notification.count_unread.useQuery(
const { data: count_unread } = trpc_client.notification.count_unread.useQuery(
{
type: NotificationGroup.Enum.EXCHANGE,
},
Expand Down
3 changes: 3 additions & 0 deletions apps/www/components/shell/AuthSessionProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"use client";

import type { Session } from "@1.modules/auth.next";
import { SessionProvider } from "@1.modules/auth.next/react";
import { sendGAEvent } from "@next/third-parties/google";
import { useEffect, type PropsWithChildren } from "react";

//

export function AuthSessionProvider({
children,
session,
Expand Down
4 changes: 2 additions & 2 deletions apps/www/components/shell/RootProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { LegalProvider } from ":components/terms/context";
import { TrpcProvider } from ":trpc/client";
import { TrpcRootProvider } from ":trpc/root";
import { SessionProvider } from "@1.modules/auth.next/react";
import { useMediaQuery } from "@react-hookz/web";
import {
Expand All @@ -27,7 +27,7 @@ export function RootProviders({ children }: PropsWithChildren) {
<LegalProvider>
<AuthSessionProvider>
<ReactQueryClientProvider>
<TrpcProvider>{children}</TrpcProvider>
<TrpcRootProvider>{children}</TrpcRootProvider>
</ReactQueryClientProvider>
</AuthSessionProvider>
</LegalProvider>
Expand Down
3 changes: 3 additions & 0 deletions apps/www/widgets/exchanges/filter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//

export { Exchanges_Filter } from "./Exchanges_Filter";
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use client";

import type { inferInfiniteQueryObserverSuccessResult } from ":components/inferQueryResult";
import { TRPC_React } from ":trpc/client";
import { Loading_Placeholder } from ":components/placeholder/Loading_Placeholder";
import { Exchange_Card } from ":widgets/exchanges/card";
import { trpc_client } from "@1.infra/trpc/react-query/client";
import { useSession } from "@1.modules/auth.next/react";
import type { Entity } from "@1.modules/core/domain";
import { Exchange_Filter, type Exchange } from "@1.modules/exchange.domain";
Expand All @@ -13,7 +14,6 @@ import { useSearchParams } from "next/navigation";
import { useEffect, type ComponentProps, type ReactNode } from "react";
import { match, P } from "ts-pattern";
import type { z } from "zod";
import Loading_Placeholder from "../loading";

//

Expand All @@ -22,7 +22,7 @@ function useQueryExchanges(input: {
filter: z.infer<typeof Exchange_Filter> | undefined;
search: string | undefined;
}) {
return TRPC_React.exchanges.find.useInfiniteQuery(input, {
return trpc_client.exchanges.find.useInfiniteQuery(input, {
getNextPageParam: ({ next_cursor }) => next_cursor,
keepPreviousData: true,
});
Expand Down Expand Up @@ -116,7 +116,7 @@ function Item({ id }: Entity) {
//

function useQueryExchangeById(id: string) {
return TRPC_React.exchanges.by_id.useQuery(id);
return trpc_client.exchanges.by_id.useQuery(id);
}

function Exchange_byId({
Expand Down
4 changes: 4 additions & 0 deletions apps/www/widgets/exchanges/list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//

export { default as List } from "./List";
export { default as SearchForm } from "./SearchForm";
35 changes: 35 additions & 0 deletions packages/@1/infra/database/seeding/inbox/greetings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//

import { PrismaClient } from "#prisma/client";

//

export async function create_greatings_message(
prisma: PrismaClient,
author_profile_id: string,
recipient_profile_id: string,
message = "Bonjour",
) {
await prisma.notification.create({
data: {
created_at: new Date(),
id: "greatings_notification_id",
inbox_message: {
create: {
message: {
create: {
author: { connect: { id: recipient_profile_id } },
content: message,
created_at: new Date(),
thread: { create: { id: "greatings_thread_id" } },
updated_at: new Date(),
},
},
},
},
owner: { connect: { id: author_profile_id } },
read_at: null,
type: "INBOX_NEW_MESSAGE",
},
});
}
1 change: 1 addition & 0 deletions packages/@1/infra/database/seeding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./category/film";
export * from "./category/masterclass";
export * from "./exchange/slap";
export * from "./exchange/the_creator";
export * from "./inbox/greetings";
export * from "./opportunity/concert_20240915";
export * from "./partner/vulfpeck";
export * from "./studient/douglas";
Expand Down
16 changes: 16 additions & 0 deletions packages/@1/infra/database/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ export async function empty_database() {
await client.exec(`DROP SCHEMA public CASCADE;`);
await client.exec(`CREATE SCHEMA public;`);
}

export async function database_status() {
console.log("🕵️ DATABASE STATUS");
console.log({
exchange_message_notification:
await prisma.exchangeMessageNotification.count(),
inbox_message_notification: await prisma.inboxMessageNotification.count(),
inbox_thread: await prisma.inboxThread.count(),
notification: await prisma.notification.count(),
profile_added_notification: await prisma.profileAddedNotification.count(),
profile: await prisma.profile.count(),
student: await prisma.student.count(),
thread: await prisma.thread.count(),
user: await prisma.user.count(),
});
}
27 changes: 15 additions & 12 deletions packages/@1/modules/exchange/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import {
Deal_Status_Schema,
Exchange_Create_Schema,
} from "@1.modules/exchange.domain";
import { next_auth_procedure, procedure, router } from "@1.modules/trpc";
import {
mergeRouters,
next_auth_procedure,
procedure,
router,
} from "@1.modules/trpc";
import { z } from "zod";
import { me } from "./me";
import by_id from "./public/by_id";
import find_router from "./public/find";
import by_id_api_router from "./public/by_id";
import find_api_router from "./public/find";

//

const exchange_api_router = router({
//
Expand Down Expand Up @@ -41,10 +48,6 @@ const exchange_api_router = router({

//

by_id,

//

by_particitpant: next_auth_procedure
.input(
z.object({
Expand Down Expand Up @@ -133,11 +136,11 @@ const exchange_api_router = router({
}),

//

find: find_router,

//
});

export default exchange_api_router;
export default mergeRouters(
by_id_api_router,
exchange_api_router,
find_api_router,
);
export type ExchangeApiRouter = typeof exchange_api_router;
Loading

0 comments on commit c4f370b

Please sign in to comment.