Erant-OldApp/README.md

110 lines
2.4 KiB
Markdown
Raw Normal View History

2022-12-01 11:25:45 +00:00
# Svelte + Appwrite = 🚀
Blazing fast development with done backend and fully-prepared frontend.
Frontend included:
* tailwind
* scss
2022-12-02 16:49:10 +00:00
* css reset
2022-12-01 11:25:45 +00:00
* typescript
* routing
2022-12-01 20:08:27 +00:00
* ready routes
2022-12-01 11:25:45 +00:00
* oauth
* folder structure
* common components
* simple icons
* service worker
* path aliases
2022-12-01 20:08:27 +00:00
* database realtime subscribers
2022-12-01 11:25:45 +00:00
* vite
Included:
* prettier
* editorconfig
2022-12-01 20:08:27 +00:00
## Database subscribers
```svelte
<script>
2022-12-02 15:35:24 +00:00
import CollectionSubscriber from '$lib/database'
2022-12-01 20:08:27 +00:00
import Layout from '$lib/components/Layout'
2022-12-02 15:35:24 +00:00
const subscriber = new CollectionSubscriber('[database-id]', '[collection-id]')
2022-12-01 20:08:27 +00:00
// listen changes in database and automatically rerender on change
2022-12-01 21:45:04 +00:00
// current data = [{ name: 'John', lastName: 'Doe' }, ...]
2022-12-01 20:08:27 +00:00
</script>
<Layout>
{$subscriber ? $subscriber[0].name : ''}
</Layout>
```
2022-12-01 21:45:04 +00:00
2022-12-02 15:35:24 +00:00
### Realtime todo app using CollectionSubscriber
2022-12-01 21:45:04 +00:00
2022-12-02 15:35:24 +00:00
```svelte
<script>
import CollectionSubscriber from '$lib/database'
import Layout from '$lib/components/Layout'
const subscriber = new CollectionSubscriber('[database-id]', '[collection-id]')
let value = ''
</script>
<Layout>
<div>
<input type="text" bind:value />
2022-12-02 15:37:29 +00:00
<button on:click={() => subscriber.add({ name: value })}>Add</button>
2022-12-02 15:35:24 +00:00
</div>
<div>
{#each $subscriber as collectionDocument}
<div>
<p>{collectionDocument.name}</p>
2022-12-02 15:37:29 +00:00
<button on:click={() => subscriber.delete(collectionDocument.$id)}>Remove</button>
2022-12-02 15:35:24 +00:00
</div>
{/each}
</div>
</Layout>
2022-12-01 21:45:04 +00:00
```
## Routing
```svelte
<script>
import { Router, Route, ProtectedRoute, Redirect, navigate, link, back, forward } from '$lib/router'
import Home from './routes/home.svelte'
import Profile from './routes/profile.svelte'
import { account } from '$lib/stores/appwrite'
import oauth from '$lib/stores/oauth'
const user = oauth(account)
</script>
<main>
<Router>
<Route path="/" component={Home}>
<ProtectedRoute path="/profile" allow={$user?.status} fallback="/" component={Profile}>
<a href="/about" use:link>About us</a>
</Router>
</main>
```
## Social auth icons
```svelte
<script>
import { Github } from '@icons-pack/svelte-simple-icons'
import Layout from '$lib/components/Layout'
import { account, url } from '$lib/stores/appwrite'
</script>
<Layout>
<button on:click={() => account.createOAuth2Session('github', url.oauth.success, url.oauth.failure)}>
<Github />
</button>
</Layout>
```