ciscoheat / sveltekit-flash-message

Send temporary data after redirect, usually from endpoints. Works with both SSR and client.
https://www.npmjs.com/package/sveltekit-flash-message
MIT License
263 stars 6 forks source link

Feature Request: More properties to work better with svelte-sonner #39

Closed Schmell closed 4 months ago

Schmell commented 6 months ago

I love this library especially with forms. Thanks I have recently started using svelte-sonner and it would be really cool if we could send down the properties of description and action. and add the enums for type ie: warning, info, promise, etc.. I mean it already works, but I get type errors, so i guess you just need to add more types

if (!session) {
throw redirect(
        302,
        '/auth/login',
        {
            // @ts-ignore
            type: 'warning',
            message: 'Not Authorized',
            description: 'You need to be logged in to Create event',
            action: {
                label: 'Back',
                onClick: () => goto(url.searchParams.get('from') ?? '')
            }
    },
     cookies
    )
}
const flash = getFlash(page) as any

$: if ($flash) {
    toast[$flash.type]($flash.message, {
        description: $flash.description,
        action: $flash.action
    })
}

EDIT: Actually i think this would make it work better with svelte french toast as well

ciscoheat commented 6 months ago

You cannot serialize functions, only JSON-friendly structures are allowed. Therefore you need to make the action/onClick property serializable and add the function on the client instead. When you have fixed that, adding the type to src/app.d.ts should make it type-safe: https://github.com/ciscoheat/sveltekit-flash-message?tab=readme-ov-file#1-add-the-flash-message-to-appdts-typescript-only

Schmell commented 6 months ago

Oh ya I totally forgot that was part of the set up. Thanks