feat: dump

This commit is contained in:
Aravinth Manivannan 2023-09-19 22:01:51 +05:30
parent d68b103f36
commit 29202fd43b
Signed by: realaravinth
GPG key ID: F8F50389936984FF
12 changed files with 122 additions and 229 deletions

View file

@ -1,38 +1,19 @@
# create-svelte 1. Please clone and build
https://git.batsense.net/realaravinth/forgejo-notifications-core in the
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). parent directory and install it on this project.
2. Please deploy a local instance of https://github.com/Bassetts/warp-cors with:
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```bash ```bash
# create a new project in the current directory docker run -dp 3030:3030 bassetts/warp-cors
npm create svelte@latest
# create a new project in my-app
npm create svelte@latest my-app
``` ```
## Developing The URL is hardcoded, so it won't work if warp-cors isn't running on
`localhost:3030`
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: 3. I Haven't figured out how to build and deploy this project. I'm not
even sure if it is possible (I'm new to svelte). But I know the
development server works ;) :
```bash ```bash
npm run dev pnpm 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.

View file

@ -1120,7 +1120,7 @@ packages:
dev: true dev: true
file:../forgejo-notifications-core/forgejo-notifications-core-0.1.0-alpha-1.tgz: file:../forgejo-notifications-core/forgejo-notifications-core-0.1.0-alpha-1.tgz:
resolution: {integrity: sha512-Xz61PNEyFfQw+StI78kqMEp0QnI4TDU69JK3V1Ty1w5FWpF9Nv+3s6vZbXdv9GfEk630VTY3ELedbVB+nu9FBA==, tarball: file:../forgejo-notifications-core/forgejo-notifications-core-0.1.0-alpha-1.tgz} resolution: {integrity: sha512-zXpAZjwjN1kPW/JBpziAG/YNvoXfco0ocWYHPut3NCsFUMqaWs0PfQ+vPRo8IaCeVP+sBgB6xTvMasclXmkP9g==, tarball: file:../forgejo-notifications-core/forgejo-notifications-core-0.1.0-alpha-1.tgz}
name: forgejo-notifications-core name: forgejo-notifications-core
version: 0.1.0-alpha-1 version: 0.1.0-alpha-1
dev: false dev: false

View file

@ -15,12 +15,11 @@
</script> </script>
<main> <main>
<Search />
{#if user_value} {#if user_value}
<Search />
<p>Hello {user_value.username}</p> <p>Hello {user_value.username}</p>
<Notifications />
{:else}
<Login />
{/if} {/if}
<Login />
<Notifications />
</main> </main>

View file

@ -19,7 +19,7 @@
<span> <span>
{#if assignments > 0} {#if assignments > 0}
{#if user_val} {#if user_val}
<IssueAttr count={user.avatar_url} img={mentions_icon} /> <IssueAttr count={assignments} img={user.avatar_url} />
{/if} {/if}
{/if} {/if}

View file

@ -11,6 +11,11 @@
user_val = value; user_val = value;
}); });
let api_val;
api.subscribe((value) => {
api_val = value;
});
let notification_val; let notification_val;
notification.subscribe((value) => { notification.subscribe((value) => {
notification_val = value; notification_val = value;
@ -125,11 +130,23 @@
}); });
}; };
const login = async (e) => { const isIssueAssigned = (i) => {
e.preventDefault(); let local_assigned = false;
let api_val = new Forgejo(instanceUrl); if (i.assignee) {
await api_val.setTokenAuth(accessToken); if (i.assignee.username == user_val.username) {
let tmpUser = await api_val.getUser(); local_assigned = true;
}
}
if (i.assignees) {
i.assignees.forEach((a) => {
if (a.username == user_val.username) {
local_assigned = true;
}
});
}
};
const hydrate = async () => {
let local_notifications = await api_val.getNotifications(); let local_notifications = await api_val.getNotifications();
local_notifications.forEach(async (n) => { local_notifications.forEach(async (n) => {
if (n.subject.type == "Issue") { if (n.subject.type == "Issue") {
@ -142,33 +159,29 @@
indexNotification(n, i); indexNotification(n, i);
let local_assigned = false;
if (i.assignee) {
if (i.assignee.username == user_val.username) {
local_assigned = true;
}
}
if (i.assignees) {
i.assignees.forEach((a) => {
if (a.username == user_val.username) {
local_assigned = true;
}
});
}
n.subject["local_issue"] = i; n.subject["local_issue"] = i;
n.subject["local_assigned"] = isIssueAssigned(i);
n.subject["local_mention"] = await api_val.findMentionsInIssue(i); n.subject["local_mention"] = await api_val.findMentionsInIssue(i);
} }
organisations.update(() => updateOrg(n, organisations_val)); organisations.update(() => updateOrg(n, organisations_val));
}); });
user.update(() => tmpUser);
api.update(() => api_val);
notification.update(() => { notification.update(() => {
return local_notifications; return local_notifications;
}); });
}; };
const login = async (e) => {
e.preventDefault();
api_val = new Forgejo(instanceUrl);
api_val.setCors();
await api_val.setTokenAuth(accessToken);
user_val = await api_val.getUser();
user.update(() => user_val);
api.update(() => api_val);
await hydrate();
};
</script> </script>
<form on:submit|preventDefault={login}> <form on:submit|preventDefault={login}>

View file

@ -1,42 +0,0 @@
<script>
import { organisations, user } from "./store.js";
import IssueAttrGrp from "./IssueAttrGrp.svelte";
let organisations_val = [];
organisations.subscribe((value) => {
organisations_val = value;
});
let user_val = [];
user.subscribe((value) => {
user_val = value;
});
</script>
<section>
<h2>Repositories</h2>
<ol>
{#each organisations_val as org}
<h3>
{org.name}
<IssueAttrGrp
mentions={org.mentions}
assignments={org.assignments}
issues={org.issues}
/>
</h3>
<ol>
{#each org.repo as repo}
<li>
{repo.name}
<IssueAttrGrp
mentions={repo.mentions}
assignments={repo.assignments}
issues={repo.issues}
/>
</li>
{/each}
</ol>
{/each}
</ol>
</section>

View file

@ -8,6 +8,9 @@
notification.subscribe((value) => { notification.subscribe((value) => {
notification_val = value; notification_val = value;
}); });
let mentions_icon = "/at-sign.svg";
let issues_icon = "/bell.svg";
</script> </script>
<section> <section>
@ -34,8 +37,14 @@
{/if} {/if}
{/if} {/if}
{n.subject.title} {n.subject.title}
{#if n.subject.html_url.local_assignments}
{#if user_val}
<IssueAttr count="1" img={user.avatar_url} />
{/if}
{/if}
{#if n.subject.html_url.local_mention} {#if n.subject.html_url.local_mention}
<img src="/at-sign.svg" /> <IssueAttr count="1" img={mentions_icon} />
{/if} {/if}
</a> </a>
</li> </li>

View file

@ -13,12 +13,16 @@
}); });
</script> </script>
<section> <aside>
<h2>Repositories</h2> <h2>Repositories</h2>
<ol> <ol>
{#each organisations_val as org} {#each organisations_val as org}
<h3> <h3>
{org.name} {#if org.name == user_val.username}
Personal
{:else}
{org.name}
{/if}
<IssueAttrGrp <IssueAttrGrp
mentions={org.mentions} mentions={org.mentions}
assignments={org.assignments} assignments={org.assignments}
@ -39,4 +43,4 @@
</ol> </ol>
{/each} {/each}
</ol> </ol>
</section> </aside>

View file

@ -1,74 +1,70 @@
<script> <script>
import { user, api, notification, organisations, index } from "./store.js"; import { user, api, notification, organisations, index } from "./store.js";
let index_val; let index_val;
index.subscribe((value) => { index.subscribe((value) => {
index_val = value; index_val = value;
}); });
let search = ""; let search = "";
let results = []; let results = [];
const findDocuments = () => { const findDocuments = () => {
let trimmed = search.trim(); let trimmed = search.trim();
results = index_val.search(trimmed); results = index_val.search(trimmed);
if (results.length > 0) { };
enableClearResults = true;
}
};
let enableClearResults = false; const clearResults = () => {
$: results = [];
const clearResults = () => { console.log("cleared");
$: results = []; };
console.log("cleared");
enableClearResults = false;
};
</script> </script>
<input <input
type="search" type="search"
id="search" id="search"
placeholder="Search" placeholder="Search"
bind:value={search} bind:value={search}
on:keydown={findDocuments} on:keydown={findDocuments}
/> />
{#if enableClearResults} {#if results.length > 0}
<button on:click={clearResults}>Clear</button> <button on:click={clearResults}>Clear</button>
{/if} {/if}
<ol> <ol>
<h2>Search Results</h2> {#if results.length > 0}
{#each results as r} <h2>Search Results</h2>
<a href={r.id}> {/if}
<li> {#each results as r}
<p>{r.content}</p> <a href={r.id}>
{r.id} <li>
<div> <p>{r.content}</p>
{#each r.itemType as i} {r.id}
<span class="type">{i}</span> <div>
{/each} {#each r.itemType as i}
</div> <span class="type">{i}</span>
</li></a {/each}
> </div>
{/each} </li></a
>
{/each}
</ol> </ol>
<style> <style>
.type { .type {
background-color: grey; background-color: grey;
padding: 2px; padding: 2px;
margin: 1px; margin: 1px;
} }
a { a {
display: block; display: block;
text-decoration: none !important; text-decoration: none !important;
color: black !important; color: black !important;
border-bottom: 1px solid grey; border-bottom: 1px solid grey;
} }
a:hover { a:hover {
background-color: lightgrey; background-color: lightgrey;
} }
</style> </style>

View file

@ -1,26 +0,0 @@
<script>
import Forgejo from "../../../forgejo-notifications-core/dist/web.js";
import Login from "./Login.svelte";
import Notifications from "./Notifications.svelte";
import Search from "./Search.svelte";
import { user } from "./store.js";
let user_value;
user.subscribe((value) => {
user_value = value;
});
</script>
<main>
<Search />
{#if user_value}
<p>Hello {user_value.username}</p>
{/if}
<Login />
<Notifications />
</main>

View file

@ -1,8 +0,0 @@
<script>
export let count = 0;
export let img;
</script>
{#if count > 0 && img}
<img src={img} /> {count}
{/if}

View file

@ -1,33 +0,0 @@
<script>
import { user } from "./store.js";
import IssueAttr from "./IssueAttr.svelte";
let user_val = [];
user.subscribe((value) => {
user_val = value;
});
export let mentions = 0;
export let assignments = 0;
export let issues = 0;
let mentions_icon = "/at-sign.svg";
let issues_icon = "/bell.svg";
</script>
<span>
{#if assignments > 0}
{#if user_val}
<IssueAttr count={user.avatar_url} img={mentions_icon} />
{/if}
{/if}
{#if mentions > 0}
<IssueAttr count={mentions} img={mentions_icon} />
{/if}
{#if issues > 0}
<IssueAttr count={issues} img={issues_icon} />
{/if}
</span>