finish URL rewrite, remove redundant logged_in state

This commit is contained in:
ari melody 2024-07-07 14:58:59 +01:00
parent a3fdd0007c
commit 4d771d8ebd
Signed by: ari
GPG key ID: CF99829C92678188
9 changed files with 20 additions and 27 deletions

View file

@ -1,4 +1,3 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
export let account = writable(false); export let account = writable(false);
export let logged_in = writable(false);

View file

@ -1,6 +1,6 @@
<script> <script>
import * as api from '$lib/api.js'; import * as api from '$lib/api.js';
import { account, logged_in } from '$lib/stores/account.js'; import { account } from '$lib/stores/account.js';
import { server } from '$lib/client/server.js'; import { server } from '$lib/client/server.js';
import { app } from '$lib/client/app.js'; import { app } from '$lib/client/app.js';
import { play_sound } from '$lib/sound.js'; import { play_sound } from '$lib/sound.js';
@ -8,7 +8,6 @@
import { getNotifications } from '$lib/notifications.js'; import { getNotifications } from '$lib/notifications.js';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { get } from 'svelte/store';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import { unread_notif_count } from '$lib/notifications.js'; import { unread_notif_count } from '$lib/notifications.js';
@ -32,7 +31,7 @@
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
function handle_btn(name) { function handle_btn(name) {
if (!get(logged_in)) return; if (!$account) return;
let route; let route;
switch (name) { switch (name) {
case "timeline": case "timeline":
@ -63,16 +62,15 @@
if (!confirm("This will log you out. Are you sure?")) return; if (!confirm("This will log you out. Are you sure?")) return;
const res = await api.revokeToken( const res = await api.revokeToken(
get(server).host, $server.host,
get(app).id, $app.id,
get(app).secret, $app.secret,
get(app).token $app.token
); );
if (!res.ok) if (!res.ok)
console.warn("Token revocation failed! Dumping data anyways"); console.warn("Token revocation failed! Dumping data anyways");
logged_in.set(false);
account.set(false); account.set(false);
app.set(false); app.set(false);
server.set(false); server.set(false);

View file

@ -1,12 +1,12 @@
<script> <script>
import * as api from '$lib/api.js'; import { server } from '$lib/client/server';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import ReplyIcon from '$lib/../img/icons/reply.svg'; import ReplyIcon from '$lib/../img/icons/reply.svg';
import RepostIcon from '$lib/../img/icons/repost.svg'; import RepostIcon from '$lib/../img/icons/repost.svg';
import FavouriteIcon from '$lib/../img/icons/like.svg'; import FavouriteIcon from '$lib/../img/icons/like.svg';
import ReactIcon from '$lib/../img/icons/react.svg'; import ReactIcon from '$lib/../img/icons/react.svg';
import QuoteIcon from '$lib/../img/icons/quote.svg'; // import QuoteIcon from '$lib/../img/icons/quote.svg';
import ReactionBar from '$lib/ui/post/ReactionBar.svelte'; import ReactionBar from '$lib/ui/post/ReactionBar.svelte';
import ActionBar from '$lib/ui/post/ActionBar.svelte'; import ActionBar from '$lib/ui/post/ActionBar.svelte';
@ -54,7 +54,7 @@
event.ctrlKey)) return; event.ctrlKey)) return;
if (event.key && event.key !== "Enter") return; if (event.key && event.key !== "Enter") return;
} }
goto(`/post/${data.status.id}`); goto(`/${$server.host}/${data.status.account.mention}/${data.status.id}`);
} }
let aria_label = function (data) { let aria_label = function (data) {

View file

@ -1,9 +1,9 @@
<script> <script>
import { server } from '$lib/client/server';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import PostHeader from './PostHeader.svelte'; import PostHeader from './PostHeader.svelte';
import Body from './Body.svelte'; import Body from './Body.svelte';
import Post from './Post.svelte';
import ActionBar from './ActionBar.svelte'; import ActionBar from './ActionBar.svelte';
import ReactionBar from './ReactionBar.svelte'; import ReactionBar from './ReactionBar.svelte';
@ -22,7 +22,7 @@
event.ctrlKey)) return; event.ctrlKey)) return;
if (event.key && event.key !== "Enter") return; if (event.key && event.key !== "Enter") return;
} }
goto(`/post/${post.id}`); goto(`/${$server.host}/${post.account.mention}/${post.id}`);
} }
</script> </script>

View file

@ -3,7 +3,7 @@
import * as api from '$lib/api.js'; import * as api from '$lib/api.js';
import { server } from '$lib/client/server.js'; import { server } from '$lib/client/server.js';
import { app } from '$lib/client/app.js'; import { app } from '$lib/client/app.js';
import { account, logged_in } from '$lib/stores/account.js'; import { account } from '$lib/stores/account.js';
import { parseAccount } from '$lib/account.js'; import { parseAccount } from '$lib/account.js';
import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js'; import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js';
@ -17,7 +17,6 @@
async function init() { async function init() {
if (!$app || !$app.token) { if (!$app || !$app.token) {
account.set(false); account.set(false);
logged_in.set(false);
return; return;
} }
@ -26,7 +25,6 @@
if (!data) return; if (!data) return;
account.set(parseAccount(data)); account.set(parseAccount(data));
logged_in.set(true);
console.log(`Logged in as @${$account.username}@${$account.host}`); console.log(`Logged in as @${$account.username}@${$account.host}`);
// spin up async task to fetch notifications // spin up async task to fetch notifications

View file

@ -1,6 +1,5 @@
<script> <script>
import { page } from '$app/stores'; import { page } from '$app/stores';
import { get } from 'svelte/store';
import { account } from '$lib/stores/account.js'; import { account } from '$lib/stores/account.js';
import { timeline, getTimeline } from '$lib/timeline.js'; import { timeline, getTimeline } from '$lib/timeline.js';
@ -13,7 +12,7 @@
}); });
document.addEventListener("scroll", () => { document.addEventListener("scroll", () => {
if (get(logged_in) && get(page).url.pathname !== "/") return; if ($account && $page.url.pathname !== "/") return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) { if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) {
getTimeline(); getTimeline();
} }

View file

@ -4,7 +4,7 @@
import { app } from '$lib/client/app.js'; import { app } from '$lib/client/app.js';
import { parsePost } from '$lib/post.js'; import { parsePost } from '$lib/post.js';
import { goto, afterNavigate } from '$app/navigation'; import { goto, afterNavigate } from '$app/navigation';
import { base as previous_page } from '$app/paths' import { base } from '$app/paths'
import Post from '$lib/ui/post/Post.svelte'; import Post from '$lib/ui/post/Post.svelte';
import Button from '$lib/ui/Button.svelte'; import Button from '$lib/ui/Button.svelte';
@ -13,6 +13,7 @@
let post; let post;
let error = false; let error = false;
let previous_page = base;
if (($server && $server.host === data.server_host) && $app) { if (($server && $server.host === data.server_host) && $app) {
post = fetchPost(data.post_id, $app.token); post = fetchPost(data.post_id, $app.token);

View file

@ -7,7 +7,7 @@
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js'; import { unread_notif_count, last_read_notif_id } from '$lib/notifications.js';
import { logged_in, account } from '$lib/stores/account.js'; import { account } from '$lib/stores/account.js';
export let data; export let data;
@ -30,7 +30,6 @@
if (!data) return goto("/"); if (!data) return goto("/");
account.set(parseAccount(data)); account.set(parseAccount(data));
logged_in.set(true);
console.log(`Logged in as @${get(account).username}@${get(account).host}`); console.log(`Logged in as @${get(account).username}@${get(account).host}`);
// spin up async task to fetch notifications // spin up async task to fetch notifications

View file

@ -1,16 +1,15 @@
<script> <script>
import { notifications, getNotifications } from '$lib/notifications.js'; import { notifications, getNotifications } from '$lib/notifications.js';
import { logged_in } from '$lib/stores/account.js'; import { account } from '$lib/stores/account.js';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { get } from 'svelte/store';
import Notification from '$lib/ui/Notification.svelte'; import Notification from '$lib/ui/Notification.svelte';
if (!get(logged_in)) goto("/"); if (!$account) goto("/");
getNotifications(); getNotifications();
document.addEventListener("scroll", event => { document.addEventListener("scroll", () => {
if (get(logged_in) && get(page).url.pathname !== "/notifications") return; if ($account && $page.url.pathname !== "/notifications") return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) { if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 2048) {
getNotifications(); getNotifications();
} }