renamed stores

This commit is contained in:
cupcakearmy 2020-06-24 11:51:53 +02:00
parent 0895d38a59
commit 1101252642
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
9 changed files with 62 additions and 24 deletions

View File

@ -1,9 +1,8 @@
import { writable } from 'svelte/store'
import axios from 'axios' import axios from 'axios'
axios.defaults.baseURL = '//localhost:8000' import { todos } from '../stores'
export const todos = writable([]) axios.defaults.baseURL = '//localhost:8000'
export async function refresh() { export async function refresh() {
const { data } = await axios({ const { data } = await axios({

View File

@ -2,7 +2,7 @@
import Button from './Button.svelte' import Button from './Button.svelte'
import Field from './Field.svelte' import Field from './Field.svelte'
import { add } from '../api' import { add } from '../api/todo.js'
let title = '' let title = ''

View File

@ -7,11 +7,13 @@
outline: none; outline: none;
border: none; border: none;
color: hsl(0, 0%, 100%); color: hsl(0, 0%, 100%);
background-color: hsl(0, 0%, 0%); background-color: var(--clr-accent);
padding: 0.5em 1em; padding: 0.5em 1em;
border-radius: 1em; border-radius: 1em;
font-size: inherit; font-size: inherit;
cursor: pointer; cursor: pointer;
min-width: 5em;
text-align: center;
} }
</style> </style>

View File

@ -6,7 +6,7 @@
<style> <style>
input { input {
outline: none; outline: none;
border: 3px solid hsl(0, 0%, 0%); border: 3px solid var(--clr-accent);
border-radius: 1em; border-radius: 1em;
font-size: inherit; font-size: inherit;
padding: 0.25em 1em; padding: 0.25em 1em;

View File

@ -1,6 +1,6 @@
<script> <script>
import Todo from './Todo.svelte' import Todo from './Todo.svelte'
import { todos } from '../api' import { todos } from '../stores.js'
</script> </script>
<style> <style>

View File

@ -2,33 +2,53 @@
import Button from './Button.svelte' import Button from './Button.svelte'
import Field from './Field.svelte' import Field from './Field.svelte'
import { remove, update } from '../api' import { remove, update } from '../api/todo.js'
export let todo export let todo
function toggle() {
update({
...todo,
done: !todo.done,
})
}
</script> </script>
<style> <style>
li { li {
display: block;
}
li.done {
--clr-accent: #c9c9c9;
}
div {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; margin-top: 0.5em;
margin-bottom: 2.5em; margin-bottom: 3em;
} }
span { span {
display: block; display: block;
width: 1em; width: 0.5em;
} }
</style> </style>
<li> <li class:done={todo.done}>
<Field bind:value={todo.title} full /> <Field bind:value={todo.title} full />
<span /> <div>
<Button <Button on:click={toggle} text={todo.done ? 'Reopen' : 'Completed'} />
on:click={() => (window.location.pathname = '/todo/' + todo._id)} {#if !todo.done}
text="View" />
<span /> <span />
<Button on:click={() => update(todo)} text="Update" /> <Button on:click={() => update(todo)} text="Update" />
<span /> <span />
<a href={'/todo/' + todo._id}>
<Button text="View" />
</a>
{/if}
<span />
<Button on:click={() => remove(todo._id)} text="Delete" /> <Button on:click={() => remove(todo._id)} text="Delete" />
</div>
</li> </li>

View File

@ -2,16 +2,19 @@
// import 'bootstrap/dist/css/bootstrap.min.css' // import 'bootstrap/dist/css/bootstrap.min.css'
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { refresh } from '../api' import { refresh } from '../api/todo.js'
onMount(() => { onMount(() => {
refresh() refresh()
console.log('mounted')
}) })
</script> </script>
<style> <style>
* { :root {
--clr-accent: #000;
}
:global(*) {
box-sizing: border-box; box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;

View File

@ -6,13 +6,21 @@
<script> <script>
import Todo from '../../components/Todo.svelte' import Todo from '../../components/Todo.svelte'
import { todos } from '../../api' import Button from '../../components/Button.svelte'
import { todos } from '../../stores.js'
export let id export let id
$: todo = $todos.find(todo => todo._id === id) $: todo = $todos.find(todo => todo._id === id)
</script> </script>
<a href="/">
<Button text="← Back" />
</a>
<br />
<br />
{#if todo} {#if todo}
<Todo {todo} /> <Todo {todo} />
{/if} {/if}

6
client/src/stores.js Normal file
View File

@ -0,0 +1,6 @@
import { writable } from 'svelte/store'
export const todos = writable([])
// And so on...
export const someOtherStore = writable('something')