Skip to content

Commit

Permalink
Merge pull request #100 from sandikodev/main
Browse files Browse the repository at this point in the history
resolve confusing types
  • Loading branch information
icflorescu committed Jan 27, 2024
2 parents 4504df8 + f88adff commit 27b5746
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 11 deletions.
6 changes: 6 additions & 0 deletions examples/bookstall/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ node_modules
# !.env.example

vite.config.ts.timestamp-*.*

# LOCK
bun.lockb

# PRISMA
prisma/*.db
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export let visible = false;
const dispatch = createEventDispatcher<{ close: never }>();
const dispatch = createEventDispatcher();
const handleClose = () => {
dispatch('close');
Expand Down
14 changes: 12 additions & 2 deletions examples/bookstall/src/lib/components/DataTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
accessor: ((record: T) => string | number) | keyof T;
}[];
const dispatch = createEventDispatcher<{ add: never; edit: string; delete: string }>();
const dispatch = createEventDispatcher<{
add?: never;
edit: string;
delete: string;
}>();
const filter = debounce((q: string) => {
goto(`${location.pathname}${q ? `?q=${q}` : ''}`, { keepFocus: true });
Expand All @@ -46,14 +50,18 @@
on:input={(e) => filter(e.currentTarget.value)}
/>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="clear-filter"
title="Clear filter"
on:click={() => goto(location.pathname, { keepFocus: true })}
/>
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="icon-button" title="Add" on:click={() => dispatch('add')}><IconAdd /></div>
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="icon-button" title="Add" on:click={() => dispatch('add')}>
<IconAdd />
</div>
</div>
<figure>
<table>
Expand Down Expand Up @@ -92,6 +100,7 @@
<td class="align-right nowrap">{dayjs(item.updatedAt).fromNow()}</td>
<td class="align-right nowrap">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="icon-button row"
title="Edit"
Expand All @@ -100,6 +109,7 @@
<IconPencil />
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="icon-button row delete"
title="Delete"
Expand Down
2 changes: 1 addition & 1 deletion examples/bookstall/src/lib/components/HeaderNavLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export let to: string | undefined = undefined;
export let title: string;
const dispatch = createEventDispatcher<{ click: never }>();
const dispatch = createEventDispatcher();
const handleClick = (e: MouseEvent) => {
if (!to) {
Expand Down
2 changes: 1 addition & 1 deletion examples/bookstall/src/lib/components/ModalEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
export let busy = false;
export let arrayFields: string[] | undefined = undefined;
const dispatch = createEventDispatcher<{ cancel: never; save: T }>();
const dispatch = createEventDispatcher<{ cancel?: never; save: T }>();
const handleCancel = () => {
dispatch('cancel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let item: Record<string, unknown> | null;
export let errors: { message: string; path: string[] }[] | null = null;
$: value = item?.[name];
$: error = errors?.find((e) => e.path.includes(name));
</script>

Expand All @@ -20,7 +21,7 @@
{name}
{placeholder}
{required}
value={item?.[name] || ''}
{value}
aria-invalid={error ? 'true' : undefined}
/>
{#if error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
};
$: item?.[name], autosize();
$: value = item?.[name] as string;
</script>

<label>
Expand All @@ -34,7 +35,7 @@
{name}
{placeholder}
{required}
value={item?.[name]}
{value}
on:input={autosize}
aria-invalid={error ? 'true' : undefined}
/>
Expand Down
12 changes: 8 additions & 4 deletions examples/bookstall/src/routes/authors/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
export let data: PageData;
let busy = false;
let item: RouterInputs['authors']['save'] | null = null; // 👈 we're using a helper type
let item: RouterInputs['authors']['save'] | null; // 👈 we're using a helper type
let errors: { message: string; path: string[] }[] | null = null;
let needsAuthorization = false;
Expand Down Expand Up @@ -55,15 +55,15 @@
errors = null;
};
const handleSave = async (e: { detail: RouterInputs['authors']['save'] }) => {
const handleSave = async (e: CustomEvent<RouterInputs['authors']['save']>) => {
if (!data.isAuthenticated) {
needsAuthorization = true;
return;
}
busy = true;
try {
await trpc().authors.save.mutate(savable(e.detail));
await trpc().authors.save.mutate(e.detail);
item = null;
await invalidateAll();
} catch (err) {
Expand Down Expand Up @@ -92,7 +92,11 @@
grow: true,
accessor: ({ firstName, lastName }) => `${firstName} ${lastName}`
},
{ title: 'Books', align: 'right', accessor: (author) => author._count.books }
{
title: 'Books',
align: 'right',
accessor: (author) => author._count.books
}
]}
on:add={handleAdd}
on:edit={handleEdit}
Expand Down

0 comments on commit 27b5746

Please sign in to comment.