Initial commit
@@ -0,0 +1,65 @@
|
|||||||
|
import type { Actions, Load } from '@sveltejs/kit';
|
||||||
|
import { Recipe } from '../../../models/Recipe';
|
||||||
|
import { dbConnect, dbDisconnect } from '../../../utils/db';
|
||||||
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const load: Load = async () => {
|
||||||
|
await dbConnect();
|
||||||
|
let todos = await Recipe.find().lean();
|
||||||
|
await dbDisconnect();
|
||||||
|
todos = JSON.parse(JSON.stringify(todos));
|
||||||
|
todos = todos.reverse();
|
||||||
|
return {
|
||||||
|
todos,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const actions: Actions = {
|
||||||
|
create: async ({ request }) => {
|
||||||
|
const formData = await request.formData();
|
||||||
|
const todoName = formData.get('todoName');
|
||||||
|
|
||||||
|
const newTodo = {
|
||||||
|
title: todoName,
|
||||||
|
isDone: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
await dbConnect();
|
||||||
|
await Recipe.create(newTodo);
|
||||||
|
await dbDisconnect();
|
||||||
|
|
||||||
|
console.log('New todo added: ', newTodo);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
update: async ({ request }) => {
|
||||||
|
const formData = await request.formData();
|
||||||
|
const todoId = formData.get('todoId');
|
||||||
|
const todoName = formData.get('todoName');
|
||||||
|
await dbConnect();
|
||||||
|
await Recipe.findByIdAndUpdate(todoId, {
|
||||||
|
title: todoName,
|
||||||
|
}).lean();
|
||||||
|
await dbDisconnect();
|
||||||
|
|
||||||
|
console.log('Todo updated: ', todoId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
delete: async ({ request }) => {
|
||||||
|
const formData = await request.formData();
|
||||||
|
const todoId = formData.get('todoId');
|
||||||
|
await dbConnect();
|
||||||
|
await Recipe.findByIdAndDelete(todoId);
|
||||||
|
await dbDisconnect();
|
||||||
|
|
||||||
|
console.log('Todo deleted: ', todoId);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
|
/build
|
||||||
|
/.svelte-kit
|
||||||
|
/package
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
vite.config.js.timestamp-*
|
||||||
|
vite.config.ts.timestamp-*
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# create-svelte
|
||||||
|
|
||||||
|
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
||||||
|
|
||||||
|
## Creating a project
|
||||||
|
|
||||||
|
If you're seeing this, you've probably already done this step. Congrats!
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# create a new project in the current directory
|
||||||
|
npm create svelte@latest
|
||||||
|
|
||||||
|
# create a new project in my-app
|
||||||
|
npm create svelte@latest my-app
|
||||||
|
```
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# or start the server and open the app in a new browser tab
|
||||||
|
npm run dev -- --open
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
To create a production version of your app:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
You can preview the production build with `npm run preview`.
|
||||||
|
|
||||||
|
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
||||||
|
After Width: | Height: | Size: 209 KiB |
|
After Width: | Height: | Size: 229 KiB |
|
After Width: | Height: | Size: 190 KiB |
|
After Width: | Height: | Size: 502 KiB |
|
After Width: | Height: | Size: 388 KiB |
|
After Width: | Height: | Size: 264 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 236 KiB |
|
After Width: | Height: | Size: 458 KiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 228 KiB |
|
After Width: | Height: | Size: 489 KiB |
|
After Width: | Height: | Size: 300 KiB |
|
After Width: | Height: | Size: 122 KiB |
|
After Width: | Height: | Size: 284 KiB |
|
After Width: | Height: | Size: 263 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 354 KiB |
|
After Width: | Height: | Size: 200 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 270 KiB |
|
After Width: | Height: | Size: 312 KiB |
|
After Width: | Height: | Size: 495 KiB |
|
After Width: | Height: | Size: 270 KiB |
|
After Width: | Height: | Size: 315 KiB |
|
After Width: | Height: | Size: 360 KiB |
|
After Width: | Height: | Size: 408 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 236 KiB |
|
After Width: | Height: | Size: 383 KiB |
|
After Width: | Height: | Size: 286 KiB |
|
After Width: | Height: | Size: 300 KiB |
|
After Width: | Height: | Size: 582 KiB |
|
After Width: | Height: | Size: 326 KiB |
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 329 KiB |
|
After Width: | Height: | Size: 260 KiB |
|
After Width: | Height: | Size: 207 KiB |
|
After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 339 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 214 KiB |
|
After Width: | Height: | Size: 326 KiB |
|
After Width: | Height: | Size: 188 KiB |
|
After Width: | Height: | Size: 246 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 511 KiB |
|
After Width: | Height: | Size: 283 KiB |
|
After Width: | Height: | Size: 395 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
After Width: | Height: | Size: 231 KiB |
|
After Width: | Height: | Size: 288 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 625 KiB |
|
After Width: | Height: | Size: 204 KiB |
|
After Width: | Height: | Size: 287 KiB |
|
After Width: | Height: | Size: 300 KiB |
@@ -0,0 +1,12 @@
|
|||||||
|
document.querySelectorAll('.url_insert').forEach(url_insert);
|
||||||
|
function url_insert(el) {
|
||||||
|
var url = el.dataset.url;
|
||||||
|
var xhttp = new XMLHttpRequest();
|
||||||
|
xhttp.onreadystatechange = function() {
|
||||||
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
el.innerHTML = this.response;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhttp.open("GET", url, true);
|
||||||
|
xhttp.send();
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 315 KiB |
|
After Width: | Height: | Size: 145 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 226 KiB |
|
After Width: | Height: | Size: 275 KiB |
|
After Width: | Height: | Size: 461 KiB |
|
After Width: | Height: | Size: 180 KiB |
|
After Width: | Height: | Size: 295 KiB |
|
After Width: | Height: | Size: 452 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 266 KiB |
|
After Width: | Height: | Size: 326 KiB |
|
After Width: | Height: | Size: 167 KiB |
|
After Width: | Height: | Size: 220 KiB |
|
After Width: | Height: | Size: 220 KiB |
|
After Width: | Height: | Size: 270 KiB |
|
After Width: | Height: | Size: 419 KiB |
|
After Width: | Height: | Size: 331 KiB |
|
After Width: | Height: | Size: 258 KiB |
|
After Width: | Height: | Size: 236 KiB |
|
After Width: | Height: | Size: 521 KiB |
|
After Width: | Height: | Size: 360 KiB |
|
After Width: | Height: | Size: 354 KiB |
|
After Width: | Height: | Size: 197 KiB |
|
After Width: | Height: | Size: 196 KiB |
|
After Width: | Height: | Size: 497 KiB |
|
After Width: | Height: | Size: 225 KiB |
|
After Width: | Height: | Size: 330 KiB |
|
After Width: | Height: | Size: 409 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 372 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 645 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 217 KiB |