Merge pull request #84 from ProjectSegfault/implement-api-state

Implement api state (closes #81)
This commit is contained in:
Akis 2022-10-01 16:44:15 +03:00 committed by GitHub
commit dfe25c67be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2431 additions and 1730 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,131 @@
<script lang="ts">
import fetchState from "$lib/fetchState";
const promise = fetchState("announcements");
import Note from "$lib/Form/Note.svelte";
import dayjs from "dayjs";
let announcements: any = [];
async function fetchAnnouncements() {
const url = `https://segfautils.projectsegfau.lt/api/announcements`;
const response = await fetch(url);
announcements = await response.json();
return announcements;
}
</script>
{#await promise}
<span />
{:then state}
{#if state.enabled === "true"}
<div class="announcements">
{#await fetchAnnouncements()}
<span />
{:then}
<div class="announcement-container">
<div class="announcement">
<div class="general">
{#if announcements.severity === "info"}
<div class="i-fa6-solid:circle-info" />
{:else}
<div class="i-fa6-solid:triangle-exclamation" />
{/if}
<span>
{dayjs
.unix(announcements.created)
.format("DD/MM/YYYY HH:mm")}
</span>
</div>
<div class="title">
<h1>{announcements.title}</h1>
</div>
{#if announcements.link}
<div class="read-more">
<a href={announcements.link}>Read more...</a>
</div>
{/if}
</div>
</div>
{:catch}
<span />
{/await}
</div>
<noscript>
<div class="no-js">
<Note
content="Announcements do not work without JavaScript enabled."
/>
</div>
<style>
.announcements {
display: none;
}
</style>
</noscript>
{#if announcements.severity === "info"}
<style>
.announcement {
background-color: #8caaee;
}
</style>
{:else if announcements.severity === "low"}
<style>
.announcement {
background-color: #a6d189;
}
</style>
{:else if announcements.severity === "medium"}
<style>
.announcement {
background-color: #e5c890;
}
</style>
{:else if announcements.severity === "high"}
<style>
.announcement {
background-color: #e78284;
}
</style>
{/if}
<style>
.announcement-container {
display: flex;
justify-content: center;
margin-top: 4rem;
}
.announcement {
color: #252525 !important;
padding: 2rem 1rem;
border-radius: 10px;
width: fit-content;
display: flex;
flex-direction: column;
}
.announcement a {
color: #252525;
}
.announcement .general {
display: flex;
align-items: center;
gap: 8px;
}
.no-js {
@apply flex justify-center text-center text-red;
}
</style>
{:else}
<div class="flex items-center gap-1 text-center justify-center mt-16">
<div class="i-fa6-solid:circle-info" />
<span>Announcements are currently disabled.</span>
</div>
{/if}
{/await}

View File

@ -1,27 +1,43 @@
<script lang="ts"> <script lang="ts">
import { Note, Captcha, Form, Meta, TextArea } from "$lib/Form"; import { Note, Captcha, Form, Meta, TextArea } from "$lib/Form";
import fetchState from "$lib/fetchState";
const promise = fetchState("form");
</script> </script>
<Form {#await promise}
action="https://segfautils.projectsegfau.lt/api/form" <span />
method="POST" {:then state}
id="contact-form" {#if state.enabled === "true"}
> <Form
<Note action="https://segfautils.projectsegfau.lt/api/form"
content="Your IP will be logged for anti-abuse measures." method="POST"
icon="i-fa6-solid:lock" id="contact-form"
/> >
<Meta <Note
inputType="email" content="Your IP will be logged for anti-abuse measures."
inputPlaceholder="Your email" icon="i-fa6-solid:lock"
selectType="commentType" />
> <Meta
<option value="" selected disabled>Select a type of comment</option> inputType="email"
<option value="Feedback">Feedback</option> inputPlaceholder="Your email"
<option value="Suggestion">Suggestion</option> selectType="commentType"
<option value="Question">Question</option> >
<option value="Bug">Bug</option> <option value="" selected disabled
</Meta> >Select a type of comment</option
<TextArea id="comment" name="message" placeholder="Your message" /> >
<Captcha /> <option value="Feedback">Feedback</option>
</Form> <option value="Suggestion">Suggestion</option>
<option value="Question">Question</option>
<option value="Bug">Bug</option>
</Meta>
<TextArea id="comment" name="message" placeholder="Your message" />
<Captcha />
</Form>
{:else}
<div class="flex items-center gap-1">
<div class="i-fa6-solid:circle-info" />
<span>The contact form is currently disabled.</span>
</div>
{/if}
{/await}

View File

@ -18,4 +18,4 @@
textarea { textarea {
resize: vertical; resize: vertical;
} }
</style> </style>

View File

@ -38,7 +38,10 @@
href={url}>{name}</a href={url}>{name}</a
> >
{/each} {/each}
<a href="https://matrix.to/#/#project-segfault:projectsegfau.lt/" class="icon"> <a
href="https://matrix.to/#/#project-segfault:projectsegfau.lt/"
class="icon"
>
<div class="i-simple-icons:matrix" /> <div class="i-simple-icons:matrix" />
<span>Matrix</span> <span>Matrix</span>
</a> </a>

View File

@ -15,8 +15,11 @@
<DarkMode bind:theme /> <DarkMode bind:theme />
<button on:click={toggle} class="cursor-pointer flex items-center py-1 px-0 bg-transparent border-0 font-[var(--font-primary)] color-[var(--text)]"> <button
<div class="i-fa6-solid:{theme === "dark" ? "sun" : "moon"}" /> on:click={toggle}
class="cursor-pointer flex items-center py-1 px-0 bg-transparent border-0 font-[var(--font-primary)] color-[var(--text)]"
>
<div class="i-fa6-solid:{theme === 'dark' ? 'sun' : 'moon'}" />
<span class="ml-2">Toggle theme</span> <span class="ml-2">Toggle theme</span>
</button> </button>
@ -27,4 +30,4 @@
margin-left: 0.25rem; margin-left: 0.25rem;
} }
} }
</style> </style>

7
src/lib/fetchState.ts Normal file
View File

@ -0,0 +1,7 @@
let state: any = [];
export default async function fetchState(module: "announcements" | "form") {
const url = `https://segfautils.projectsegfau.lt/api/set/${module}`;
const response = await fetch(url);
state = await response.json();
return state;
}

View File

@ -2,20 +2,9 @@
import SvelteSeo from "svelte-seo"; import SvelteSeo from "svelte-seo";
import Hero from "$lib/Hero.svelte"; import Hero from "$lib/Hero.svelte";
import LinkButton from "$lib/LinkButton.svelte"; import LinkButton from "$lib/LinkButton.svelte";
import Note from "$lib/Form/Note.svelte"; import Announcements from "$lib/Announcements.svelte";
import dayjs from "dayjs";
let description: string = "Open source development and hosted services."; let description: string = "Open source development and hosted services.";
let announcements: any = [];
async function fetchAnnouncements() {
const url = `https://segfautils.projectsegfau.lt/api/announcements`;
const response = await fetch(url);
announcements = await response.json();
return announcements;
}
const promise = fetchAnnouncements();
</script> </script>
<SvelteSeo title="Home | Project Segfault" {description} /> <SvelteSeo title="Home | Project Segfault" {description} />
@ -41,76 +30,7 @@
</div> </div>
</Hero> </Hero>
<div class="announcements"> <Announcements />
{#await promise}
<span />
{:then}
<div class="announcement-container">
<div class="announcement">
<div class="general">
{#if announcements.severity === "info"}
<div class="i-fa6-solid:circle-info" />
{:else}
<div class="i-fa6-solid:triangle-exclamation" />
{/if}
<span>
{dayjs
.unix(announcements.created)
.format("DD/MM/YYYY HH:mm")}
</span>
</div>
<div class="title">
<h1>{announcements.title}</h1>
</div>
{#if announcements.link}
<div class="read-more">
<a href={announcements.link}>Read more...</a>
</div>
{/if}
</div>
</div>
{:catch}
<span />
{/await}
</div>
<noscript>
<div class="no-js">
<Note content="Announcements do not work without JavaScript enabled." />
</div>
<style>
.announcements {
display: none;
}
</style>
</noscript>
{#if announcements.severity === "info"}
<style>
.announcement {
background-color: #8caaee;
}
</style>
{:else if announcements.severity === "low"}
<style>
.announcement {
background-color: #a6d189;
}
</style>
{:else if announcements.severity === "medium"}
<style>
.announcement {
background-color: #e5c890;
}
</style>
{:else if announcements.severity === "high"}
<style>
.announcement {
background-color: #e78284;
}
</style>
{/if}
<style> <style>
.buttons { .buttons {
@ -127,33 +47,4 @@
flex-direction: column; flex-direction: column;
} }
} }
.announcement-container {
display: flex;
justify-content: center;
margin-top: 4rem;
}
.announcement {
color: #252525 !important;
padding: 2rem 1rem;
border-radius: 10px;
width: fit-content;
display: flex;
flex-direction: column;
}
.announcement a {
color: #252525;
}
.announcement .general {
display: flex;
align-items: center;
gap: 8px;
}
.no-js {
@apply flex justify-center text-center text-red;
}
</style> </style>

View File

@ -14,5 +14,6 @@ description: We're not anarchists, so we have some rules.
5. While we do try to keep your data safe, you have to acknowledge that **we are not responsible** if anything **unintentional** happens (such as **data loss**, **inability to extract your data** due to the server being down.). It is also **your responsibility** to **keep a backup of your data** if it matters to you. 5. While we do try to keep your data safe, you have to acknowledge that **we are not responsible** if anything **unintentional** happens (such as **data loss**, **inability to extract your data** due to the server being down.). It is also **your responsibility** to **keep a backup of your data** if it matters to you.
### Failure to comply will either end up **disabling** your account, and/or if it is illegal, **reporting** to the police. ### Failure to comply will either end up **disabling** your account, and/or if it is illegal, **reporting** to the police.
* Be aware that "**reporting** to the police" only happens if the individual is using our services to **post, promote, or encourage** actions that are **morally unnacceptable**. (Such as: pedophilia, murder, or CSAM.)
* **No warnings will be issued if we find this out.** - Be aware that "**reporting** to the police" only happens if the individual is using our services to **post, promote, or encourage** actions that are **morally unnacceptable**. (Such as: pedophilia, murder, or CSAM.)
- **No warnings will be issued if we find this out.**

View File

@ -232,11 +232,15 @@
<TimelineConnector /> <TimelineConnector />
</TimelineSeparator> </TimelineSeparator>
<TimelineContent> <TimelineContent>
<h3> <h3>Resignation of members and the start of a new era.</h3>
Resignation of members and the start of a new era.
</h3>
<p> <p>
Devnol, Odyssey and akisblack resigned from the team leading to a serious loss of manpower. To combat this, we decided to shut down some of our unused instances as well as the ones that were painful to deal with. You can read more over at <a href="https://blog.projectsegfau.lt/resignation-of-3-members-of-projectsegfault/">this blog post</a>. Devnol, Odyssey and akisblack resigned from the team leading to
a serious loss of manpower. To combat this, we decided to shut
down some of our unused instances as well as the ones that were
painful to deal with. You can read more over at <a
href="https://blog.projectsegfau.lt/resignation-of-3-members-of-projectsegfault/"
>this blog post</a
>.
</p> </p>
</TimelineContent> </TimelineContent>
</TimelineItem> </TimelineItem>