Skip to content

Commit

Permalink
Merge pull request #29 from biensupernice/chore/update-trpc
Browse files Browse the repository at this point in the history
Update to tRPC v10
  • Loading branch information
jalvarado91 authored Mar 13, 2024
2 parents d70de77 + 9e851a8 commit 8985ee3
Show file tree
Hide file tree
Showing 12 changed files with 756 additions and 950 deletions.
1,185 changes: 499 additions & 686 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"@expo/results": "^1.0.0",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-select": "^2.0.0",
"@trpc/client": "^9.27.2",
"@trpc/next": "^9.27.2",
"@trpc/react": "^9.27.2",
"@trpc/server": "^9.27.2",
"@tanstack/react-query": "^4.26.1",
"@trpc/client": "^10.16.0",
"@trpc/next": "^10.16.0",
"@trpc/react-query": "^10.16.0",
"@trpc/server": "^10.16.0",
"@types/lodash-es": "^4.17.5",
"@types/node": "^14.14.6",
"@types/react": "18.0.14",
"@types/react-dom": "18.0.5",
"@types/node": "18.15.3",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"@types/uuid": "^8.3.0",
"axios": "^0.21.1",
"class-variance-authority": "^0.7.0",
Expand All @@ -36,12 +37,11 @@
"react-aria": "^3.19.0",
"react-dom": "^18.2.0",
"react-modal-sheet": "1.8.1",
"react-query": "^3.39.2",
"react-spring-bottom-sheet": "^3.4.1",
"react-stately": "^3.24.0",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.18.0",
"zod": "^3.21.4",
"zustand": "^3.6.7"
},
"devDependencies": {
Expand All @@ -52,7 +52,7 @@
"prettier": "^2.7.1",
"prettier-plugin-tailwindcss": "^0.1.13",
"tailwindcss": "^3.3.3",
"typescript": "4.7.4",
"typescript": "4.9.5",
"uuid": "^8.3.2"
}
}
22 changes: 13 additions & 9 deletions src/client/TracksScreen/TracksScreenContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,22 @@ export function useTracksScreenContainer() {
};
}

export const playEpisodeMutationKey = {
queryKey: ["playEpisode"],
};

export function usePlayEpisodeMutation() {
const { fetchQuery } = trpc.useContext();
const utils = trpc.useUtils();
const fetchStreamUrl = utils["episode.getStreamUrl"].fetch;

return useCustomMutation(
"playEpisode",
playEpisodeMutationKey.queryKey,
async (episodeId: string) => {
const query = await fetchQuery(
[
"episode.getStreamUrl",
{
episodeId: episodeId,
},
],
const query = await fetchStreamUrl(
{
episodeId: episodeId,
},

{
staleTime: Infinity,
}
Expand Down
26 changes: 17 additions & 9 deletions src/client/TracksScreen/TracksStore.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import { inferQueryOutput, trpc } from "@/utils/trpc";
import { EpisodeRouter } from "@/server/router";
import { trpc } from "@/utils/trpc";
import { inferRouterOutputs } from "@trpc/server";

export type ITrack = inferQueryOutput<"episodes.all">[number];
export type RouterOutput = inferRouterOutputs<EpisodeRouter>;
export type ITrack = RouterOutput["episodes.all"][number];

export function useEpisodes() {
return trpc.useQuery(["episodes.all", { collective: "all" }], {
refetchOnWindowFocus: false,
});
return trpc["episodes.all"].useQuery(
{ collective: "all" },
{
refetchOnWindowFocus: false,
}
);
}

export function useEpisode(id: string | undefined) {
const { getQueryData } = trpc.useContext();
const utils = trpc.useUtils();
const getData = utils["episodes.all"].getData;

if (!id) {
return null;
}
const eps = getQueryData(["episodes.all"]) ?? [];
const eps = getData() ?? [];

return eps.filter((e) => e._id === id)?.[0] || null;
}

export function useGetEpisode(id: string) {
const { getQueryData } = trpc.useContext();
const utils = trpc.useUtils();
const getData = utils["episodes.all"].getData;

const eps = getQueryData(["episodes.all", { collective: "all" }]) ?? [];
const eps = getData({ collective: "all" }) ?? [];
return eps.filter((e) => e._id === id)[0];
}
6 changes: 3 additions & 3 deletions src/client/TracksScreen/useEpisodeAlbumArtColors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useEffect } from "react";
export function useEpisodeAlbumArtColors() {
const currentTrackId = usePlayerStore((state) => state.currentTrackId);

const { data } = trpc.useQuery(
["episode.getAccentColor", { episodeId: currentTrackId }],
const { data } = trpc["episode.getAccentColor"].useQuery(
{ episodeId: currentTrackId },
{
refetchOnWindowFocus: false,
refetchOnReconnect: false,
Expand All @@ -19,7 +19,7 @@ export function useEpisodeAlbumArtColors() {
const rgbString = data.rgb.join(" ");

const [h, s, l] = data.hsl;
const hslString = `${h*360} ${s*100}% ${l*100}%`;
const hslString = `${h * 360} ${s * 100}% ${l * 100}%`;

document.documentElement.style.setProperty("--accent", hslString);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/infra/useCustomMutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useMutation,
useIsMutating,
useQueryClient,
} from "react-query";
} from "@tanstack/react-query";

export const useCustomMutation = <
TData = unknown,
Expand Down
9 changes: 5 additions & 4 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { loggerLink } from "@trpc/client/links/loggerLink";
import { httpBatchLink } from "@trpc/client/links/httpBatchLink";
import Head from "next/head";
import { withTRPC } from "@trpc/next";
import { AppRouter } from "./api/trpc/[trpc]";
import { GoogleAnalytics } from "nextjs-google-analytics";
import { EpisodeRouter } from "@/server/router";

function MyApp({ Component, pageProps }: AppProps) {
return (
Expand Down Expand Up @@ -174,7 +174,7 @@ function MyApp({ Component, pageProps }: AppProps) {
}

function getBaseUrl() {
if (process.browser) {
if (typeof window !== "undefined") {
return "";
}
// reference for vercel.com
Expand All @@ -186,7 +186,7 @@ function getBaseUrl() {
return `http://localhost:${process.env.PORT ?? 3000}`;
}

export default withTRPC<AppRouter>({
export default withTRPC<EpisodeRouter>({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config() {
/**
Expand All @@ -201,7 +201,8 @@ export default withTRPC<AppRouter>({
// adds pretty logs to your console in development and logs errors in production
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === "development" ||
(process.env.NODE_ENV === "development" &&
typeof window !== "undefined") ||
(opts.direction === "down" && opts.result instanceof Error),
}),
httpBatchLink({
Expand Down
1 change: 0 additions & 1 deletion src/pages/api/internal/sync-episodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import _ from "lodash";
import { SoundCloudApiClient } from "@/server/crosscutting/soundCloudApiClient";
import { createDbConnection } from "@/server/db";
import { Db } from "mongodb";
import { ITrack } from "../trpc/[trpc]";

function createLargeSoundtrackThumbUrl(url: string) {
const newUrl = url.replace("-large", "-t500x500");
Expand Down
Loading

1 comment on commit 8985ee3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for soulector ready!

✅ Preview
https://soulector-3fzd4rpgv-jalvarado91.vercel.app

Built with commit 8985ee3.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.