Skip to content

Commit

Permalink
fix(web): move createList to /lists
Browse files Browse the repository at this point in the history
  • Loading branch information
manekenpix committed Jul 9, 2024
1 parent d2092af commit a257325
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
31 changes: 31 additions & 0 deletions web/src/routes/user/lists/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { fail } from '@sveltejs/kit';
import type { Lists, ListType } from '../../../ambient';
import type { RequestEvent } from './$types.js';
import { API_HOST } from '$env/static/private';
import { LISTS_PER_PAGE } from '../../../utils/consts';

Expand Down Expand Up @@ -113,3 +115,32 @@ export const load = async ({ fetch, locals }) => {
console.error(e);
}
};

/** @type {import('./$types').Actions} */
export const actions = {
createList: async ({ request, fetch, locals }: RequestEvent) => {
const data = await request.formData();
const listName = data.get('list-name') as string;

try {
const list = {
name: listName
};

const response = await fetch(`${API}/lists`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: locals.cookie as string
},
body: JSON.stringify(list)
});

if (response.status !== 200) {
return fail(400);
}
} catch (e) {
console.error(e);
}
}
};
10 changes: 6 additions & 4 deletions web/src/routes/user/lists/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
</button>
</TopSection>
<ListContainer lists="{lists}" />
<div class="flex md:text-3xl sm:text-2xl mt-10 mb-4 mx-5 justify-between">
<Title>shared with you</Title>
</div>
<ListContainer lists="{sharedLists}" />
{#if sharedLists.length}
<div class="flex md:text-3xl sm:text-2xl mt-10 mb-4 mx-5 justify-between">
<Title>shared with you</Title>
</div>
<ListContainer lists="{sharedLists}" />
{/if}

<ListModal bind:showModal="{showModal}" />
25 changes: 0 additions & 25 deletions web/src/routes/user/lists/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,6 @@ export const actions = {
console.error(e);
}
},
createList: async ({ request, fetch, locals }: RequestEvent) => {
const data = await request.formData();
const listName = data.get('list-name') as string;

try {
const list = {
name: listName
};

const response = await fetch(`${API}/lists`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: locals.cookie as string
},
body: JSON.stringify(list)
});

if (response.status !== 200) {
return fail(400);
}
} catch (e) {
console.error(e);
}
},
deleteList: async ({ request, fetch, locals }: RequestEvent) => {
const data = await request.formData();
const listId = data.get('listId');
Expand Down

0 comments on commit a257325

Please sign in to comment.