2024-06-17 21:17:27 +01:00
|
|
|
<script>
|
2024-06-29 10:46:27 +01:00
|
|
|
import Feed from '$lib/ui/Feed.svelte';
|
|
|
|
import { Client } from '$lib/client/client.js';
|
|
|
|
import Button from '$lib/ui/Button.svelte';
|
2024-06-28 06:19:00 +01:00
|
|
|
import { get } from 'svelte/store';
|
2024-06-19 22:13:16 +01:00
|
|
|
|
2024-06-28 06:19:00 +01:00
|
|
|
let client = get(Client.get());
|
2024-06-29 15:52:52 +01:00
|
|
|
let logged_in;
|
2024-06-28 06:19:00 +01:00
|
|
|
let instance_url_error = false;
|
|
|
|
let logging_in = false;
|
2024-06-19 22:13:16 +01:00
|
|
|
|
2024-06-28 06:19:00 +01:00
|
|
|
if (client.app && client.app.token) {
|
2024-06-28 08:43:12 +01:00
|
|
|
// this triggers the client actually getting the authenticated user's data.
|
2024-06-29 15:52:52 +01:00
|
|
|
client.verifyCredentials().then(user => {
|
|
|
|
if (user) {
|
|
|
|
console.log(`Logged in as @${user.username}@${user.host}`);
|
|
|
|
logged_in = true;
|
|
|
|
} else {
|
|
|
|
logged_in = false;
|
2024-06-28 06:19:00 +01:00
|
|
|
}
|
|
|
|
});
|
2024-06-29 15:52:52 +01:00
|
|
|
} else {
|
|
|
|
logged_in = false;
|
2024-06-28 06:19:00 +01:00
|
|
|
}
|
|
|
|
|
2024-06-17 21:17:27 +01:00
|
|
|
function log_in(event) {
|
|
|
|
event.preventDefault();
|
2024-06-29 15:24:33 +01:00
|
|
|
instance_url_error = false;
|
|
|
|
|
|
|
|
logging_in = true;
|
2024-06-19 22:13:16 +01:00
|
|
|
const host = event.target.host.value;
|
|
|
|
|
2024-06-29 15:24:33 +01:00
|
|
|
if (!host || host === "") {
|
|
|
|
instance_url_error = "Please enter an instance domain.";
|
|
|
|
logging_in = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-21 03:02:18 +01:00
|
|
|
client.init(host).then(res => {
|
2024-06-28 06:19:00 +01:00
|
|
|
logging_in = false;
|
2024-06-21 03:02:18 +01:00
|
|
|
if (!res) return;
|
2024-06-28 06:19:00 +01:00
|
|
|
if (res.constructor === String) {
|
|
|
|
instance_url_error = res;
|
|
|
|
return;
|
|
|
|
};
|
2024-06-19 22:13:16 +01:00
|
|
|
let oauth_url = client.getOAuthUrl();
|
|
|
|
location = oauth_url;
|
|
|
|
});
|
2024-06-17 21:17:27 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-06-29 17:27:46 +01:00
|
|
|
{#if logged_in === undefined}
|
|
|
|
<div class="loading throb">
|
|
|
|
<span>just a moment...</span>
|
|
|
|
</div>
|
|
|
|
{:else if logged_in === false}
|
|
|
|
<form on:submit={log_in} id="login-form">
|
|
|
|
<img class="app-icon light-only" src={LogoLight} width="320px" aria-label="Space Social"/>
|
|
|
|
<img class="app-icon dark-only" src={LogoDark} width="320px" aria-label="Space Social"/>
|
|
|
|
<p>Welcome, fediverse user!</p>
|
|
|
|
<p>Please enter your instance domain to log in.</p>
|
|
|
|
<div class="input-wrapper">
|
|
|
|
<input type="text" id="host" aria-label="instance domain" class={logging_in ? "throb" : ""}>
|
|
|
|
{#if instance_url_error}
|
|
|
|
<p class="error">{instance_url_error}</p>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<button type="submit" id="login" class={logging_in ? "disabled" : ""}>Log in</button>
|
|
|
|
<p><small>
|
|
|
|
Please note this is
|
|
|
|
<strong><em>extremely experimental software</em></strong>;
|
|
|
|
things are likely to break!
|
|
|
|
<br>
|
|
|
|
If that's all cool with you, welcome aboard!
|
|
|
|
</small></p>
|
|
|
|
|
|
|
|
<p class="form-footer">made with ❤️ by <a href="https://arimelody.me">ari melody</a>, 2024</p>
|
|
|
|
</form>
|
|
|
|
{:else}
|
2024-06-28 06:19:00 +01:00
|
|
|
<header>
|
2024-06-29 17:27:46 +01:00
|
|
|
<h1>Home</h1>
|
|
|
|
<nav>
|
|
|
|
<Button centered active>Home</Button>
|
2024-06-29 19:52:52 +01:00
|
|
|
<Button centered disabled>Local</Button>
|
|
|
|
<Button centered disabled>Federated</Button>
|
2024-06-29 17:27:46 +01:00
|
|
|
</nav>
|
2024-06-28 06:19:00 +01:00
|
|
|
</header>
|
|
|
|
|
2024-06-29 17:27:46 +01:00
|
|
|
<Feed />
|
|
|
|
{/if}
|
2024-06-17 21:17:27 +01:00
|
|
|
|
|
|
|
<style>
|
2024-06-29 15:24:33 +01:00
|
|
|
form#login-form {
|
|
|
|
height: 100vh;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2024-06-29 19:52:52 +01:00
|
|
|
text-align: center;
|
2024-06-19 22:13:16 +01:00
|
|
|
}
|
|
|
|
|
2024-06-17 21:17:27 +01:00
|
|
|
a {
|
|
|
|
color: var(--accent);
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
a:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
|
2024-06-28 06:19:00 +01:00
|
|
|
.input-wrapper {
|
|
|
|
width: 360px;
|
|
|
|
margin: 0 auto;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type=text] {
|
|
|
|
width: 100%;
|
|
|
|
padding: 12px;
|
|
|
|
display: block;
|
2024-06-17 21:17:27 +01:00
|
|
|
border-radius: 8px;
|
2024-06-28 06:19:00 +01:00
|
|
|
border: 1px solid var(--accent);
|
|
|
|
background-color: var(--bg-800);
|
|
|
|
|
|
|
|
font-family: inherit;
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: inherit;
|
|
|
|
color: var(--text);
|
|
|
|
|
|
|
|
transition: box-shadow .2s;
|
2024-06-17 21:17:27 +01:00
|
|
|
}
|
|
|
|
|
2024-06-28 06:19:00 +01:00
|
|
|
input[type=text]::placeholder {
|
|
|
|
opacity: .8;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type=text]:focus {
|
|
|
|
outline: none;
|
|
|
|
box-shadow: 0 0 16px color-mix(in srgb, transparent, var(--accent) 25%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.error {
|
|
|
|
margin: 6px;
|
|
|
|
font-style: italic;
|
|
|
|
font-size: .9em;
|
|
|
|
color: red;
|
|
|
|
opacity: .7;
|
|
|
|
}
|
|
|
|
|
|
|
|
button#login {
|
2024-06-29 15:24:33 +01:00
|
|
|
margin: 8px auto;
|
2024-06-28 06:19:00 +01:00
|
|
|
padding: 12px 24px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
font-family: inherit;
|
|
|
|
font-size: 1rem;
|
|
|
|
font-weight: 600;
|
|
|
|
text-align: left;
|
|
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
border-width: 2px;
|
|
|
|
border-style: solid;
|
|
|
|
|
|
|
|
background-color: var(--bg-700);
|
|
|
|
color: var(--text);
|
|
|
|
border-color: transparent;
|
|
|
|
|
|
|
|
transition-property: border-color, background-color, color;
|
|
|
|
transition-timing-function: ease-out;
|
|
|
|
transition-duration: .1s;
|
|
|
|
|
2024-06-17 21:17:27 +01:00
|
|
|
cursor: pointer;
|
2024-06-28 06:19:00 +01:00
|
|
|
text-align: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
button#login:hover {
|
|
|
|
background-color: color-mix(in srgb, var(--bg-700), var(--accent) 10%);
|
|
|
|
border-color: color-mix(in srgb, var(--bg-700), var(--accent) 20%);
|
|
|
|
}
|
|
|
|
|
|
|
|
button#login:active {
|
|
|
|
background-color: color-mix(in srgb, var(--bg-700), var(--bg-800) 50%);
|
|
|
|
border-color: color-mix(in srgb, var(--bg-700), var(--bg-800) 10%);
|
2024-06-17 21:17:27 +01:00
|
|
|
}
|
|
|
|
|
2024-06-28 06:19:00 +01:00
|
|
|
button#login.disabled {
|
|
|
|
opacity: .5;
|
|
|
|
cursor: initial;
|
2024-06-17 21:17:27 +01:00
|
|
|
}
|
|
|
|
|
2024-06-28 06:19:00 +01:00
|
|
|
.form-footer {
|
|
|
|
opacity: .7;
|
2024-06-17 21:17:27 +01:00
|
|
|
}
|
2024-06-29 14:48:34 +01:00
|
|
|
|
|
|
|
.loading {
|
|
|
|
width: 100%;
|
2024-06-29 15:24:33 +01:00
|
|
|
height: 100vh;
|
2024-06-29 14:48:34 +01:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
font-size: 2em;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
2024-06-29 17:27:46 +01:00
|
|
|
header {
|
2024-06-29 14:48:34 +01:00
|
|
|
width: 100%;
|
|
|
|
margin: 16px 0 8px 0;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
}
|
|
|
|
|
2024-06-29 17:27:46 +01:00
|
|
|
header h1 {
|
2024-06-29 14:48:34 +01:00
|
|
|
font-size: 1.5em;
|
|
|
|
}
|
|
|
|
|
2024-06-29 17:27:46 +01:00
|
|
|
header nav {
|
2024-06-29 14:48:34 +01:00
|
|
|
margin-left: auto;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
gap: 8px;
|
|
|
|
}
|
2024-06-29 15:24:33 +01:00
|
|
|
|
|
|
|
.app-icon {
|
|
|
|
width: 320px;
|
|
|
|
margin: 8px;
|
|
|
|
}
|
2024-06-17 21:17:27 +01:00
|
|
|
</style>
|