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
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!
1. Please clone and build
https://git.batsense.net/realaravinth/forgejo-notifications-core in the
parent directory and install it on this project.
2. Please deploy a local instance of https://github.com/Bassetts/warp-cors with:
```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
docker run -dp 3030:3030 bassetts/warp-cors
```
## 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
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.
```bash
pnpm run dev
````

View File

@ -1120,7 +1120,7 @@ packages:
dev: true
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
version: 0.1.0-alpha-1
dev: false

View File

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

View File

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

View File

@ -11,6 +11,11 @@
user_val = value;
});
let api_val;
api.subscribe((value) => {
api_val = value;
});
let notification_val;
notification.subscribe((value) => {
notification_val = value;
@ -125,11 +130,23 @@
});
};
const login = async (e) => {
e.preventDefault();
let api_val = new Forgejo(instanceUrl);
await api_val.setTokenAuth(accessToken);
let tmpUser = await api_val.getUser();
const isIssueAssigned = (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;
}
});
}
};
const hydrate = async () => {
let local_notifications = await api_val.getNotifications();
local_notifications.forEach(async (n) => {
if (n.subject.type == "Issue") {
@ -142,33 +159,29 @@
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_assigned"] = isIssueAssigned(i);
n.subject["local_mention"] = await api_val.findMentionsInIssue(i);
}
organisations.update(() => updateOrg(n, organisations_val));
});
user.update(() => tmpUser);
api.update(() => api_val);
notification.update(() => {
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>
<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_val = value;
});
let mentions_icon = "/at-sign.svg";
let issues_icon = "/bell.svg";
</script>
<section>
@ -34,8 +37,14 @@
{/if}
{/if}
{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}
<img src="/at-sign.svg" />
<IssueAttr count="1" img={mentions_icon} />
{/if}
</a>
</li>

View File

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

View File

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