Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/src/common/generic/lib/create-url/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isEmpty } from "es-toolkit/compat";
import { mapValues } from "es-toolkit/object";
import { trimStart } from "es-toolkit/string";

import type { CreateUrlInput, CreateUrlOutput } from "./types";
Expand All @@ -14,11 +13,20 @@ export function createUrl({
}: CreateUrlInput): CreateUrlOutput {
const basePart =
scheme && host ? `${scheme}://${host}${port ? `:${port}` : ""}` : "";

const pathPart = path ? `/${trimStart(path, "/")}` : "";

const queryPart =
query && !isEmpty(query)
? `?${new URLSearchParams(mapValues(query, (value) => String(value))).toString()}`
? `?${new URLSearchParams(
Object.entries(query).flatMap(([key, value]) =>
Array.isArray(value)
? value.map((v) => [key, String(v)])
: [[key, String(value)]],
),
).toString()}`
: "";

const fragmentPart = fragment ? `#${fragment}` : "";

const url = basePart + pathPart + queryPart + fragmentPart;
Expand Down
4 changes: 3 additions & 1 deletion src/src/common/generic/lib/create-url/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type QueryValue = boolean | number | string;

type AnyUrlInput = {
fragment?: null | string;
query?: null | { [key: string]: boolean | number | string };
query?: null | { [key: string]: QueryValue | QueryValue[] };
};

type AbsoluteUrlInput = AnyUrlInput & {
Expand Down
4 changes: 2 additions & 2 deletions src/src/isomorphic/state/hooks/use-global-state/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { State, StateSubscribe } from "../../types";
import type { ReadonlyState, State, StateSubscribe } from "../../types";

export type StateContainer = {
current: State;
snapshot: State;
snapshot: ReadonlyState;
subscribe: StateSubscribe;
};

Expand Down
4 changes: 4 additions & 0 deletions src/src/isomorphic/state/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "client-only";

import type { ReadonlyDeep } from "type-fest";

export type NowState = {
counter: number;
timer: number;
Expand All @@ -10,6 +12,8 @@ export type State = {
now?: NowState;
};

export type ReadonlyState = ReadonlyDeep<State>;

export type StateSubscribeCallback = (state: State) => void;

export type StateUnsubscribe = () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export function useIdentity({}: UseIdentityInput = {}): UseIdentityOutput {

const identity = useMemo(() => ({ user: snapshot.user }), [snapshot.user]);

return useMemo(() => ({ identity }), [identity]);
return useMemo(() => ({ identity: identity }), [identity]);
}
Loading