Skip to content

Commit

Permalink
solid router update
Browse files Browse the repository at this point in the history
  • Loading branch information
LexSwed committed Oct 31, 2024
1 parent a3d75b0 commit 9342b16
Show file tree
Hide file tree
Showing 23 changed files with 245 additions and 1,105 deletions.
1,231 changes: 185 additions & 1,046 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/acceptance-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"author": "",
"devDependencies": {
"@faker-js/faker": "^9.1.0",
"@types/node": "^22.8.4"
"@types/node": "^22.8.6"
},
"dependencies": {
"@dotenvx/dotenvx": "^1.21.0",
"@dotenvx/dotenvx": "^1.21.1",
"@playwright/test": "^1.48.2"
}
}
16 changes: 8 additions & 8 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
"@solid-primitives/presence": "^0.0.6",
"@solid-primitives/refs": "^1.0.8",
"@solid-primitives/rootless": "^1.4.5",
"@solidjs/router": "^0.14.10",
"@solidjs/router": "^0.15.0",
"class-variance-authority": "^0.7.0",
"solid-js": "^1.9.3",
"tailwind-merge": "^2.5.4"
},
"devDependencies": {
"@nou/config": "^1.0.0",
"@storybook/addon-essentials": "^8.3.6",
"@storybook/addon-interactions": "^8.3.6",
"@storybook/addon-links": "^8.3.6",
"@storybook/blocks": "^8.3.6",
"@storybook/docs-tools": "^8.3.6",
"@storybook/test": "^8.3.6",
"@storybook/addon-essentials": "^8.4.0",
"@storybook/addon-interactions": "^8.4.0",
"@storybook/addon-links": "^8.4.0",
"@storybook/blocks": "^8.4.0",
"@storybook/docs-tools": "^8.4.0",
"@storybook/test": "^8.4.0",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"remark-gfm": "^4.0.0",
"storybook": "^8.3.6",
"storybook": "^8.4.0",
"storybook-solidjs": "^1.0.0-beta.2",
"storybook-solidjs-vite": "^1.0.0-beta.2",
"tailwindcss": "^3.4.14",
Expand Down
10 changes: 5 additions & 5 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"@solid-primitives/refs": "^1.0.8",
"@solid-primitives/storage": "^4.2.1",
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.14.10",
"@solidjs/router": "^0.15.0",
"@solidjs/start": "^1.0.9",
"arctic": "^2.2.0",
"arctic": "^2.2.1",
"better-sqlite3": "^11.5.0",
"class-variance-authority": "^0.7.0",
"date-fns": "^4.1.0",
"drizzle-orm": "^0.35.3",
"drizzle-orm": "^0.36.0",
"drizzle-valibot": "^0.2.0",
"lucia": "^3.2.2",
"nanoid": "^5.0.8",
Expand All @@ -47,10 +47,10 @@
"devDependencies": {
"@faker-js/faker": "^9.1.0",
"@nou/config": "^1.0.0",
"@storybook/builder-vite": "^8.3.6",
"@storybook/builder-vite": "^8.4.0",
"@types/better-sqlite3": "^7.6.11",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.26.2",
"drizzle-kit": "^0.27.0",
"tailwindcss": "^3.4.14",
"tsx": "^4.19.2",
"vite": "^5.4.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/lib/utils/make-persisted-signal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cache, createAsync, revalidate } from "@solidjs/router";
import { createAsync, query, revalidate } from "@solidjs/router";
import { untrack } from "solid-js";
import { isServer } from "solid-js/web";

Expand Down Expand Up @@ -27,7 +27,7 @@ const getServerSetting = async <T>(name: string) => {
return deserialize<T>(getCookie(name));
};

const setting = cache(async <T>(name: string): Promise<T | null> => {
const setting = query(async <T>(name: string): Promise<T | null> => {
if (isServer) {
return getServerSetting<T>(name);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/(www).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Icon, NavCard, type SvgIcons, Text } from "@nou/ui";
import type { RouteDefinition } from "@solidjs/router";
import { type Accessor, For, type ParentProps } from "solid-js";

import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";

import { LogoLink } from "~/lib/logo-link";

export const route = {
preload() {
void cacheTranslations("www");
void queryDictionary("www");
},
} satisfies RouteDefinition;

Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Toaster } from "@nou/ui";
import type { RouteDefinition, RouteSectionProps } from "@solidjs/router";

import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";

export const route = {
async preload() {
void cacheTranslations("app");
void queryDictionary("app");
},
} satisfies RouteDefinition;

Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/(home)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { For, Match, Show, Suspense, Switch, createUniqueId, lazy } from "solid-

import { getUserPets } from "~/server/api/pet";
import { getUserFamily } from "~/server/api/user";
import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";

import { AppHeader } from "~/lib/app-header";
import { FamilyInviteDialog } from "~/lib/family-invite";
Expand All @@ -15,7 +15,7 @@ const CreateNewPetForm = lazy(() => import("~/lib/create-new-pet-form"));

export const route = {
preload() {
void cacheTranslations("app");
void queryDictionary("app");
void getUserPets();
void getUserFamily();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { Match, Show, Suspense, Switch } from "solid-js";
import { checkFamilyInvite, joinFamilyWithLink } from "~/server/api/family-invite";
import { getUserProfile } from "~/server/api/user";
import { UserAlreadyInFamily, isErrorResponse } from "~/server/errors";
import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";

import { AccountMenu } from "~/lib/account-menu";
import { FamilyInviteBenefits } from "~/lib/family-invite-benefits";
import { HeroImage } from "~/lib/hero-image";

export const route = {
preload() {
void cacheTranslations("invited");
void queryDictionary("invited");
void getUserProfile();
},
} satisfies RouteDefinition;
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/family.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { type RouteDefinition, type RouteSectionProps, createAsync } from "@soli
import { Match, Show, Suspense, Switch } from "solid-js";

import { getUserFamily } from "~/server/api/user";
import { T, cacheTranslations, createTranslator } from "~/server/i18n";
import { T, createTranslator, queryDictionary } from "~/server/i18n";

import { AppHeader } from "~/lib/app-header";
import { FamilyInviteDialog } from "~/lib/family-invite";

export const route = {
preload() {
void cacheTranslations("family");
void queryDictionary("family");
void getUserFamily();
},
} satisfies RouteDefinition;
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/family/(family).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import { For, Match, Show, Suspense, Switch } from "solid-js";

import { cancelFamilyJoin, getFamilyMembers, leaveFamily } from "~/server/api/family";
import { getUserFamily } from "~/server/api/user";
import { T, cacheTranslations, createTranslator } from "~/server/i18n";
import { T, createTranslator, queryDictionary } from "~/server/i18n";

import { FamilyInviteDialog } from "~/lib/family-invite";
import { FamilyNameForm } from "~/lib/family-invite/family-name-form";
import { WaitingFamilyConfirmation } from "~/lib/family-invite/waiting-family-confirmation";

export const route = {
preload() {
void cacheTranslations("family");
void queryDictionary("family");
void getUserFamily();
void getFamilyMembers();
},
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/family/[memberId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { type RouteDefinition, type RouteSectionProps, createAsync } from "@soli
import { Show } from "solid-js";

import { getFamilyMember, getFamilyMembers } from "~/server/api/family";
import { cacheTranslations } from "~/server/i18n";
import { queryDictionary } from "~/server/i18n";
import type { UserID } from "~/server/types";

export const route = {
load({ params }) {
void cacheTranslations("family");
void queryDictionary("family");
void getFamilyMember(params.memberId as UserID);
},
} satisfies RouteDefinition;
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/pets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { Match, Switch } from "solid-js";
import { AppHeader } from "~/lib/app-header";
import { getPet } from "~/server/api/pet";
import { getUserFamily } from "~/server/api/user";
import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";
import type { PetID } from "~/server/types";

export const route = {
preload({ params }) {
void cacheTranslations("pets");
void queryDictionary("pets");
void getUserFamily();
if (params.petId) {
void getPet(params.petId as PetID);
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/pets/[petId]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { GenderSwitch } from "~/lib/species-selector";
import { isSubmissionValidationError } from "~/lib/utils/submission";
import { deletePet, getPet, updatePet } from "~/server/api/pet";
import type { DatabasePet } from "~/server/db/schema";
import { T, cacheTranslations, createTranslator } from "~/server/i18n";
import { T, createTranslator, queryDictionary } from "~/server/i18n";
import type { PetGender, PetID, PetSpecies } from "~/server/types";

export const route = {
preload({ params }) {
void cacheTranslations("pets");
void queryDictionary("pets");
void getPet(params.petId as PetID);
},
} satisfies RouteDefinition;
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/pets/[petId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { PetPicture } from "~/lib/pet-home-card";
import { getPetScheduledActivities, listAllPetActivities } from "~/server/api/activity";
import { getPet } from "~/server/api/pet";
import { getUser, getUserProfile } from "~/server/api/user";
import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";
import type { ActivityType, PetID, UserSession } from "~/server/types";
import { PetPastActivities } from "./_lib/past-activities";
import { PetPrescriptions, type PrescriptionActivity } from "./_lib/pet-prescriptions";

export const route = {
preload({ params }) {
void cacheTranslations("pets");
void queryDictionary("pets");
void getPet(params.petId as PetID);
void getUserProfile();
void getUser();
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/routes/app/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import { Show, Suspense } from "solid-js";

import { getUserProfile, updateUserProfile } from "~/server/api/user";
import type { DatabaseUser } from "~/server/db/schema";
import { cacheTranslations, createTranslator } from "~/server/i18n";
import { createTranslator, queryDictionary } from "~/server/i18n";
import type { SupportedLocale } from "~/server/i18n/shared";

import { AppHeader } from "~/lib/app-header";
import { pickSubmissionValidationErrors } from "~/lib/utils/submission";

export const route = {
preload() {
void cacheTranslations("profile");
void queryDictionary("profile");
void getUserProfile();
},
} satisfies RouteDefinition;
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/server/api/activity.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { action, cache } from "@solidjs/router";
import { action, query } from "@solidjs/router";
import {
createPetActivityServer,
getPetScheduledActivitiesServer,
listAllPetActivitiesServer,
} from "./activity.server";

export const getPetScheduledActivities = cache(
export const getPetScheduledActivities = query(
(...args: Parameters<typeof getPetScheduledActivitiesServer>) =>
getPetScheduledActivitiesServer(...args),
"pet-activities-scheduled",
);

export const listAllPetActivities = cache(
export const listAllPetActivities = query(
(...args: Parameters<typeof listAllPetActivitiesServer>) => listAllPetActivitiesServer(...args),
"pet-activities",
);
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/server/api/family-invite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, cache } from "@solidjs/router";
import { action, query } from "@solidjs/router";

import {
checkFamilyInviteServer,
Expand All @@ -8,9 +8,9 @@ import {
moveUserFromTheWaitListServer,
} from "./family-invite.server";

export const getFamilyInvite = cache(getFamilyInviteServer, "family-invite-code");
export const getFamilyInvite = query(getFamilyInviteServer, "family-invite-code");

export const checkFamilyInvite = cache(checkFamilyInviteServer, "check-family-invite");
export const checkFamilyInvite = query(checkFamilyInviteServer, "check-family-invite");

export const joinFamilyWithLink = action(joinFamilyWithLinkServer, "join-family");

Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/server/api/family.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, cache } from "@solidjs/router";
import { action, query } from "@solidjs/router";

import {
cancelFamilyJoinServer,
Expand All @@ -9,9 +9,9 @@ import {
updateFamilyServer,
} from "./family.server";

export const getFamilyMembers = cache(getFamilyMembersServer, "family-members");
export const getFamilyMembers = query(getFamilyMembersServer, "family-members");

export const getFamilyMember = cache(getFamilyMemberServer, "family-member");
export const getFamilyMember = query(getFamilyMemberServer, "family-member");

export const updateFamily = action(updateFamilyServer, "update-family");

Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/server/api/pet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, cache } from "@solidjs/router";
import { action, query } from "@solidjs/router";

import {
createPetServer,
Expand All @@ -11,7 +11,7 @@ import {
updatePetWeightServer,
} from "./pet.server";

export const getUserPets = cache(getUserPetsServer, "user-pets");
export const getUserPets = query(getUserPetsServer, "user-pets");

export const createPet = action(createPetServer, "create-pet");

Expand All @@ -23,6 +23,6 @@ export const updatePetBreed = action(updatePetBreedServer, "update-pet-breed");

export const updatePet = action(updatePetServer, "update-pet");

export const getPet = cache(getPetServer, "user-pet");
export const getPet = query(getPetServer, "user-pet");

export const deletePet = action(deletePetServer, "delete-pet");
8 changes: 4 additions & 4 deletions packages/web/src/server/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { action, cache } from "@solidjs/router";
import { action, query } from "@solidjs/router";

import { getRequestUser } from "~/server/auth/request-user";
import { userFamily } from "~/server/db/queries/user-family";

import { getUserProfileServer, updateUserProfileServer } from "./user.server";

export const getUserFamily = cache(async () => {
export const getUserFamily = query(async () => {
"use server";
const currentUser = await getRequestUser();

Expand All @@ -17,12 +17,12 @@ export const getUserFamily = cache(async () => {
return user;
}, "user-family");

export const getUser = cache(async () => {
export const getUser = query(async () => {
"use server";
const user = await getRequestUser();
return user;
}, "user");

export const getUserProfile = cache(getUserProfileServer, "user-profile");
export const getUserProfile = query(getUserProfileServer, "user-profile");

export const updateUserProfile = action(updateUserProfileServer, "update-user-profile");
Loading

0 comments on commit 9342b16

Please sign in to comment.