huntabyte / showcase

Full stack application built with SvelteKit & PocketBase.
109 stars 30 forks source link

Episode #4 - Deleting thumbnail clears form. #9

Closed engageintellect closed 1 year ago

engageintellect commented 1 year ago

Using the thumbnail delete button appears to clear the form. See below for example.

Before: image

After - Clicking red trash button clears the whole form, yet yields the expected result in PocketBase (remove thumbnail): image

I copied your files for $lib/components/MyProjectItem.svelte as well as everything under /routes/projects just to make sure I didn't mistype anything, the result appears to be the same.

I have made a branch in my own repository to isolate/highlight this issue: https://github.com/engageintellect/sveltekit-pocket/tree/delete-thumbnail-issue

Hopefully someone can point out what I may be missing?

dsincl12 commented 1 year ago

I solved this by redirecting back to the edit page:

deleteThumbnail: async ({ locals, params }) => {
        try {
            await locals.pb.collection('projects').update(params.projectId, { thumbnail: null });
        } catch (err) {
            console.log('** ERROR:', err);
            throw error(err.status, err.message);
        }

        throw redirect(303, `/projects/${params.projectId}/edit`);
    }
engageintellect commented 1 year ago

I solved this by redirecting back to the edit page:


deleteThumbnail: async ({ locals, params }) => {

      try {

          await locals.pb.collection('projects').update(params.projectId, { thumbnail: null });

      } catch (err) {

          console.log('** ERROR:', err);

          throw error(err.status, err.message);

      }

      throw redirect(303, `/projects/${params.projectId}/edit`);

  }

Exactly what I needed. Thank you! And, happy 4th.

dsincl12 commented 1 year ago

The proper solution comes later https://youtu.be/Ct3TSEJeD8I?list=PLq30BP0TIcqW3sMm404UIEA7osPEkKAyg&t=2453