This commit is contained in:
Kieran 2023-09-15 16:43:33 +01:00
commit 38ee6a425f
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
13 changed files with 1242 additions and 0 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

2
.npmrc Normal file
View File

@ -0,0 +1,2 @@
engine-strict=true
resolution-mode=highest

38
README.md Normal file
View File

@ -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.

25
package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "snort-svelte",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.20.4",
"svelte": "^4.0.5",
"svelte-check": "^3.4.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2"
},
"type": "module",
"dependencies": {
"@snort/system": "^1.0.21"
}
}

11
src/app.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}

12
src/app.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

36
src/lib/index.ts Normal file
View File

@ -0,0 +1,36 @@
// place files you want to import through the `$lib` alias in this folder.
import {
NostrSystem,
type NoteStore,
type RequestBuilder,
type StoreSnapshot,
type SystemInterface,
} from "@snort/system";
import { getContext } from "svelte";
export function useRequestBuilder<T extends NoteStore>(
type: new () => T,
rb: RequestBuilder
) {
const system = getContext("snort") as SystemInterface;
type TSnap = StoreSnapshot<ReturnType<T["getSnapshotData"]>>;
return {
subscribe: (set) => {
const q = system.Query(type, rb);
q.uncancel();
const release = q.feed.hook(() => {
set(q.feed.snapshot as TSnap);
});
return () => {
q.cancel();
release();
};
},
} as SvelteStore<TSnap>;
}
export const system = new NostrSystem({});
["wss://relay.snort.social/", "wss://nos.lol/"].forEach((v) =>
system.ConnectToRelay(v, { read: true, write: true })
);

54
src/routes/+page.svelte Normal file
View File

@ -0,0 +1,54 @@
<script>
import { system, useRequestBuilder } from "$lib";
import { NoteCollection, RequestBuilder, transformText } from "@snort/system";
import { setContext } from "svelte";
setContext("snort", system);
const rb = new RequestBuilder("posts");
rb.withOptions({
leaveOpen: true,
});
rb.withFilter().kinds([1]).limit(10);
const store = useRequestBuilder(NoteCollection, rb);
</script>
<div class="flex-column g8">
{#each ($store?.data ?? []).sort((a, b) => b.created_at > a.created_at ? 1 : -1) as ev}
<div class="note">
<time>{new Date(ev.created_at * 1000)}</time>
<br/>
{#each transformText(ev.content, ev.tags) as f}
{#if f.type === "text"}
{f.content}
{:else if f.type === "link"}
<a href={f.content}>{f.content}</a>
{:else if f.type === "media"}
<br/>
<img src={f.content} alt="post" />
{:else}
{f.content}
{/if}
{/each}
</div>
{/each}
</div>
<style>
.flex-column {
display: flex;
flex-direction: column;
}
.g8 {
gap: 8px;
}
.note {
border: 1px solid;
padding: 8px 16px;
border-radius: 12px;
}
.note img {
max-height: 200px;
}
</style>

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

18
svelte.config.js Normal file
View File

@ -0,0 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;

17
tsconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

6
vite.config.ts Normal file
View File

@ -0,0 +1,6 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
});

1013
yarn.lock Normal file

File diff suppressed because it is too large Load Diff