feat(frontend): show closed reports button, add some alerts for auth

This commit is contained in:
sam 2025-02-23 20:02:40 +01:00
parent 30146556f5
commit 0c6e3bf38f
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
7 changed files with 23 additions and 7 deletions

View file

@ -321,6 +321,7 @@
"required": "Required"
},
"alert": {
"auth-method-remove-success": "Successfully unlinked account!"
"auth-method-remove-success": "Successfully unlinked account!",
"auth-required": "You must log in to access this page."
}
}

View file

@ -19,5 +19,5 @@ export const load = async ({ url, fetch, cookies }) => {
fetch,
cookies,
});
return { reports, url: url.toString(), byReporter, byTarget, before, after };
return { reports, url: url.toString(), includeClosed, byReporter, byTarget, before, after };
};

View file

@ -18,6 +18,14 @@
return url.toString();
};
const addClosed = () => {
const url = new URL(data.url);
if (!data.includeClosed) url.searchParams.set("include-closed", "true");
else url.searchParams.delete("include-closed");
return url.toString();
};
const addTarget = (id: string | null) => {
const url = new URL(data.url);
if (id) url.searchParams.set("by-target", id);
@ -56,6 +64,11 @@
{#if data.byReporter}
<li>Filtering by reporter (<a href={addReporter(null)}>clear</a>)</li>
{/if}
{#if data.includeClosed}
<li>Showing all reports (<a href={addClosed()}>only show open reports</a>)</li>
{:else}
<li>Showing open reports (<a href={addClosed()}>show all reports</a>)</li>
{/if}
</ul>
{#if data.before}

View file

@ -2,15 +2,15 @@ import { isRedirect, redirect } from "@sveltejs/kit";
import { apiRequest } from "$api";
import type { AuthResponse, AuthUrls } from "$api/models/auth";
import { setToken } from "$lib";
import { alertKey, setToken } from "$lib";
import ApiError, { ErrorCode } from "$api/error";
export const load = async ({ fetch, parent }) => {
export const load = async ({ fetch, parent, url }) => {
const parentData = await parent();
if (parentData.meUser) redirect(303, `/@${parentData.meUser.username}`);
const urls = await apiRequest<AuthUrls>("POST", "/auth/urls", { fetch, isInternal: true });
return { urls };
return { urls, alertKey: alertKey(url) };
};
export const actions = {

View file

@ -3,6 +3,7 @@
import { t } from "$lib/i18n";
import { enhance } from "$app/forms";
import ErrorAlert from "$components/ErrorAlert.svelte";
import UrlAlert from "$components/URLAlert.svelte";
type Props = { data: PageData; form: ActionData };
let { data, form }: Props = $props();
@ -13,6 +14,7 @@
</svelte:head>
<div class="container">
<UrlAlert {data} />
<div class="row">
{#if form?.error}
<ErrorAlert error={form.error} />

View file

@ -2,5 +2,5 @@ import { redirect } from "@sveltejs/kit";
export const load = async ({ parent }) => {
const { meUser } = await parent();
if (!meUser) redirect(303, "/auth/log-in");
if (!meUser) redirect(303, "/auth/log-in?alert=auth-required");
};

View file

@ -2,7 +2,7 @@ import { redirect } from "@sveltejs/kit";
export const load = async ({ parent }) => {
const data = await parent();
if (!data.meUser) redirect(303, "/auth/log-in");
if (!data.meUser) redirect(303, "/auth/log-in?alert=auth-required");
return { user: data.meUser!, token: data.token! };
};