~thecashewtrader/minb

fbae887c2ded28c75624bedcf6b57c666902cc33 — thecashewtrader 1 year, 9 months ago 56f0820
Auto save child Todos on saving a Todo Group
2 files changed, 14 insertions(+), 4 deletions(-)

M src/lib/components/TodoGroupRenderer.svelte
M src/lib/components/TodoRenderer.svelte
M src/lib/components/TodoGroupRenderer.svelte => src/lib/components/TodoGroupRenderer.svelte +10 -3
@@ 11,12 11,15 @@
	const dispatch = createEventDispatcher();

	export let todo_group: TodoGroup;
	$: completed = todo_group.todos.filter((todo) => !todo.completed).length == 0 && todo_group.todos.length > 0;
	$: completed =
		todo_group.todos.filter((todo) => !todo.completed).length == 0 && todo_group.todos.length > 0;

	let saveLoading = false;
	let deleteLoading = false;
	let createLoading = false;

	let todoSaveFunctions: (() => Promise<void>)[] = [];

	let isEdited = false;
	const setIsEdited = () => {
		isEdited = true;


@@ 25,6 28,10 @@
	const handleSave = async () => {
		saveLoading = true;

		await Promise.all(
			todoSaveFunctions.map((todoSaveFunction: () => Promise<void>) => todoSaveFunction())
		);

		const { error } = await supabase
			.from('todo_groups')
			.update({


@@ 142,8 149,8 @@
		</button>
	</div>
	<section class="my-6">
		{#each todo_group.todos as todo}
			<TodoRenderer {todo} on:update={updateTodos} />
		{#each todo_group.todos as todo, i}
			<TodoRenderer {todo} on:update={updateTodos} bind:runSaveRequest={todoSaveFunctions[i]} />
		{/each}
		<div>
			<button

M src/lib/components/TodoRenderer.svelte => src/lib/components/TodoRenderer.svelte +4 -1
@@ 13,7 13,7 @@
	const setIsEdited = () => {
		isEdited = true;
	};
	const handleSave = async () => {
	export const runSaveRequest = async () => {
		saveLoading = true;

		const { error } = await supabase


@@ 31,6 31,9 @@

		isEdited = false;
		saveLoading = false;
	};
	const handleSave = async () => {
		await runSaveRequest();
		dispatch('update');
	};