binajmen
binajmen
Explore posts from servers
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
😂
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
works fine ty !
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
async function get<Schema extends v.BaseSchema<any, any, any>>(
path: string,
schema: Schema,
): Promise<v.InferOutput<Schema>> {
return fetch(`${API_URL}${path}`)
.then((res) => res.json())
.then((json) => v.parse(schema, json));
}
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
async function get<Schema extends v.BaseSchema<any, any, any>>(
path: string,
schema: Schema,
): Promise<v.InferOutput<Schema>> {
return fetch(`${API_URL}${path}`)
.then((res) => res.json())
.then((json) => v.parse(schema, json));
}
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
ok 😄
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
linter
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
mmmh
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
Unexpected any. Specify a different type.
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
ok will try that
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
frontend/src/core/users/users.api.ts|11 col 35-47 error| Generic type 'BaseSchema<TInput, TOutput, TIssue>' requires 3 type argument(s).
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
and I get lost ;D
20 replies
SSolidJS
Created by binajmen on 2/22/2025 in #support
[valibot] Types generic
yeah it seems BaseSchema is more appropriate, but then I need to specify generic params
20 replies
SSolidJS
Created by binajmen on 2/15/2025 in #support
Using createAsync in SolidJS: Handling Data Dependencies
is this a pattern to return early from an action like that? this could indeed solve my problem.. i'll try this tomorrow and see how the network tab behave !
6 replies
SSolidJS
Created by binajmen on 2/15/2025 in #support
Using createAsync in SolidJS: Handling Data Dependencies
The main point is:
options={findVariantsSubmission.result || data()!.variants}
options={findVariantsSubmission.result || data()!.variants}
And using an action to retrieve the data via useSubmission, but this seems convoluted..
6 replies
SSolidJS
Created by binajmen on 2/15/2025 in #support
Using createAsync in SolidJS: Handling Data Dependencies
This is what I have after several iteration:
const loader = query(async (criterion_id: string) => {
"use server";
const criterion = await criterionRepo.find(criterion_id);
const programs = await programRepo.findAll();
const variants = await variantRepo.findByProgram(criterion.program_id);
return { criterion, programs, variants };
}, "admin-criterion");

const findVariantsByProgram = action(async (program_id: string) => {
"use server";
const variants = await variantRepo.findByProgram(program_id);
return json(variants, { revalidate: "nothing" });
}, "find-variants-by-program");

export default function AdminCriteriaAggregate() {
const params = useParams();
const data = createAsync(() => loader(params.id));

const findVariants = useAction(findVariantsByProgram);
const findVariantsSubmission = useSubmission(findVariantsByProgram);

const [programId, setProgramId] = createSignal<string | undefined>(
data()?.criterion.program_id,
);

return (
<Show when={data()}>
<form method="post" action={update} class="flex flex-col gap-md">
...
<Field
id="program_id"
label="Programm"
>
{(field) => (
<Select
{...field}
options={data()!.programs}
valueKey="id"
labelKey="name"
select={(program) => program.id === data()!.criterion.program_id}
onChange={(e) => findVariants(e.currentTarget.value)}
/>
)}
</Field>
<Field
id="variant_id"
label="Programmprofil"
>
{(field) => (
<Select
{...field}
options={findVariantsSubmission.result || data()!.variants}
valueKey="id"
labelKey="name"
select={(variant) => variant.id === data()!.criterion.variant_id}
/>
)}
</Field>
const loader = query(async (criterion_id: string) => {
"use server";
const criterion = await criterionRepo.find(criterion_id);
const programs = await programRepo.findAll();
const variants = await variantRepo.findByProgram(criterion.program_id);
return { criterion, programs, variants };
}, "admin-criterion");

const findVariantsByProgram = action(async (program_id: string) => {
"use server";
const variants = await variantRepo.findByProgram(program_id);
return json(variants, { revalidate: "nothing" });
}, "find-variants-by-program");

export default function AdminCriteriaAggregate() {
const params = useParams();
const data = createAsync(() => loader(params.id));

const findVariants = useAction(findVariantsByProgram);
const findVariantsSubmission = useSubmission(findVariantsByProgram);

const [programId, setProgramId] = createSignal<string | undefined>(
data()?.criterion.program_id,
);

return (
<Show when={data()}>
<form method="post" action={update} class="flex flex-col gap-md">
...
<Field
id="program_id"
label="Programm"
>
{(field) => (
<Select
{...field}
options={data()!.programs}
valueKey="id"
labelKey="name"
select={(program) => program.id === data()!.criterion.program_id}
onChange={(e) => findVariants(e.currentTarget.value)}
/>
)}
</Field>
<Field
id="variant_id"
label="Programmprofil"
>
{(field) => (
<Select
{...field}
options={findVariantsSubmission.result || data()!.variants}
valueKey="id"
labelKey="name"
select={(variant) => variant.id === data()!.criterion.variant_id}
/>
)}
</Field>
6 replies
SSolidJS
Created by binajmen on 1/28/2025 in #support
Why do I end up with a server-fns for a number input component?
with the one you suggested me: npm i https://pkg.pr.new/@solidjs/start@1715
5 replies
SSolidJS
Created by binajmen on 1/28/2025 in #support
Why do I end up with a server-fns for a number input component?
I might need to stop using "use server" in classes before transitioning:
5 replies
SSolidJS
Created by binajmen on 1/7/2025 in #support
`useSession()` unexpectedly changing
I'm having a hard time figuring out how to solve that..
4 replies
SSolidJS
Created by binajmen on 1/7/2025 in #support
`useSession()` unexpectedly changing
I suspect the issue comes from the fact getAdmin() is called at two different places in the AdminLayout(), and that there is some kind of unsync at some point where useSession() does not take into account the cookie from the request, and therefore reply with a different cookie (like the default session created by h3)
4 replies
SSolidJS
Created by binajmen on 1/7/2025 in #support
`useSession()` unexpectedly changing
The relevant code snippets are the following:
export const router = {
preload() {
getAdmin();
getVariants();
},
} satisfies RouteDefinition;

export default function AdminLayout(props: ParentProps) {
createAsync(() => getAdmin());
export const router = {
preload() {
getAdmin();
getVariants();
},
} satisfies RouteDefinition;

export default function AdminLayout(props: ParentProps) {
createAsync(() => getAdmin());
export const getAdmin = query(async () => {
"use server";
const authService = new AuthService();
const user = await authService.getUserBySession();
if (!user || !user.is_admin) {
throw redirect("/");
}
return user;
}, "admin");
export const getAdmin = query(async () => {
"use server";
const authService = new AuthService();
const user = await authService.getUserBySession();
if (!user || !user.is_admin) {
throw redirect("/");
}
return user;
}, "admin");
const sessionConfig = {
name: "cockpit",
maxAge: 60 * 60 * 24 * 14,
password: process.env.SESSION_SECRET,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
},
} satisfies SessionConfig;

type Session = {
user_id?: string;
};

function getSession() {
return useSession<Session>(sessionConfig);
}

async getUserBySession() {
"use server";
const session = await getSession();
console.log("getUserBySession: session =", session);
const userId = session.data.user_id;
console.log("getUserBySession: userId =", session.data.user_id);
if (!userId) throw redirect("/login");

const user = await this.userService.getUser(userId);
if (!user) throw this.logout();

const { hashed_password, ...safeUser } = user;
return safeUser;
}
const sessionConfig = {
name: "cockpit",
maxAge: 60 * 60 * 24 * 14,
password: process.env.SESSION_SECRET,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
},
} satisfies SessionConfig;

type Session = {
user_id?: string;
};

function getSession() {
return useSession<Session>(sessionConfig);
}

async getUserBySession() {
"use server";
const session = await getSession();
console.log("getUserBySession: session =", session);
const userId = session.data.user_id;
console.log("getUserBySession: userId =", session.data.user_id);
if (!userId) throw redirect("/login");

const user = await this.userService.getUser(userId);
if (!user) throw this.logout();

const { hashed_password, ...safeUser } = user;
return safeUser;
}
4 replies