Skip to content

Commit

Permalink
more typecheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil committed Oct 25, 2023
1 parent 32be98b commit 5071c83
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 0 additions & 2 deletions app/routes/account.mydevices.$boxId.edit.sensors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
title: sensor.title,
unit: sensor.unit,
sensorType: sensor.sensorType,
icon: sensor.icon,
});
} else if (sensor?.deleted === true) {
await deleteSensor(sensor.id);
Expand Down Expand Up @@ -520,4 +519,3 @@ export function ErrorBoundary() {
</div>
);
}

2 changes: 1 addition & 1 deletion app/routes/settings.account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default function AccountPage() {
<select
id="language"
name="language"
defaultValue={userData?.language}
defaultValue={userData?.language || ""}
onChange={(e) => setLang(e.target.value)}
className="appearance-auto w-full rounded border border-gray-200 px-2 py-1.5 text-base"
>
Expand Down
10 changes: 5 additions & 5 deletions app/session.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createCookieSessionStorage, redirect } from "@remix-run/node";
import type { User } from "db/schema";
import invariant from "tiny-invariant";

import type { User } from "~/models/user.server";
import { getUserById } from "~/models/user.server";

invariant(process.env.SESSION_SECRET, "SESSION_SECRET must be set");
Expand All @@ -25,7 +25,7 @@ export async function getUserSession(request: Request) {
}

export async function getUserId(
request: Request
request: Request,
): Promise<User["id"] | undefined> {
const session = await getUserSession(request);
const userId = session.get(USER_SESSION_KEY);
Expand Down Expand Up @@ -64,7 +64,7 @@ export async function getUser(request: Request) {

export async function requireUserId(
request: Request,
redirectTo: string = new URL(request.url).pathname
redirectTo: string = new URL(request.url).pathname,
) {
const userId = await getUserId(request);
if (!userId) {
Expand Down Expand Up @@ -96,7 +96,7 @@ export async function createUserSession({
}) {
const session = await getUserSession(request);
session.set(USER_SESSION_KEY, userId);
session.flash("global_message", "You successfully logged in.")
session.flash("global_message", "You successfully logged in.");
return redirect(redirectTo, {
headers: {
"Set-Cookie": await sessionStorage.commitSession(session, {
Expand All @@ -117,7 +117,7 @@ export async function logout({
}) {
const session = await getUserSession(request);
session.unset(USER_SESSION_KEY);
session.flash("global_message", "You successfully logged out.")
session.flash("global_message", "You successfully logged out.");
return redirect(redirectTo, {
headers: {
"Set-Cookie": await sessionStorage.commitSession(session),
Expand Down
26 changes: 15 additions & 11 deletions app/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useMatches } from "@remix-run/react";
import type { User } from "db/schema";
import { useMemo } from "react";

import type { User } from "~/models/user.server";

const DEFAULT_REDIRECT = "/";

/**
Expand All @@ -14,7 +13,7 @@ const DEFAULT_REDIRECT = "/";
*/
export function safeRedirect(
to: FormDataEntryValue | string | null | undefined,
defaultRedirect: string = DEFAULT_REDIRECT
defaultRedirect: string = DEFAULT_REDIRECT,
) {
if (!to || typeof to !== "string") {
return defaultRedirect;
Expand All @@ -34,12 +33,12 @@ export function safeRedirect(
* @returns {JSON|undefined} The router data or undefined if not found
*/
export function useMatchesData(
id: string
id: string,
): Record<string, unknown> | undefined {
const matchingRoutes = useMatches();
const route = useMemo(
() => matchingRoutes.find((route) => route.id === id),
[matchingRoutes, id]
[matchingRoutes, id],
);

return route?.data as Record<string, unknown>;
Expand All @@ -61,7 +60,7 @@ export function useUser(): User {
const maybeUser = useOptionalUser();
if (!maybeUser) {
throw new Error(
"No user found in root loader, but user is required by useUser. If user is optional, try useOptionalUser instead."
"No user found in root loader, but user is required by useUser. If user is optional, try useOptionalUser instead.",
);
}
return maybeUser;
Expand Down Expand Up @@ -90,7 +89,7 @@ export function validateName(name: string) {
//* validate passwords type (changePassword page)
export function validatePassType(passwords: any) {
const index = passwords.findIndex(
(password: any) => typeof password !== "string" || password.length === 0
(password: any) => typeof password !== "string" || password.length === 0,
);
return { isValid: index == -1 ? true : false, index: index };
}
Expand All @@ -107,11 +106,16 @@ export function validatePassLength(passwords: any) {
* @param devices all devices data
* @param filterParams attributes and selected values
*/
export function getFilteredDevices(devices: any, filterParams: URLSearchParams) {
export function getFilteredDevices(
devices: any,
filterParams: URLSearchParams,
) {
// if a param is missing/undefined set it as ALL
const { exposure= "ALL", status= "ALL", phenomenon= "ALL" } = Object.fromEntries(
filterParams.entries()
);
const {
exposure = "ALL",
status = "ALL",
phenomenon = "ALL",
} = Object.fromEntries(filterParams.entries());

let results: any = [];

Expand Down

0 comments on commit 5071c83

Please sign in to comment.