feat(frontend): show closed reports button, add some alerts for auth
This commit is contained in:
parent
30146556f5
commit
0c6e3bf38f
7 changed files with 23 additions and 7 deletions
|
@ -321,6 +321,7 @@
|
||||||
"required": "Required"
|
"required": "Required"
|
||||||
},
|
},
|
||||||
"alert": {
|
"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."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,5 +19,5 @@ export const load = async ({ url, fetch, cookies }) => {
|
||||||
fetch,
|
fetch,
|
||||||
cookies,
|
cookies,
|
||||||
});
|
});
|
||||||
return { reports, url: url.toString(), byReporter, byTarget, before, after };
|
return { reports, url: url.toString(), includeClosed, byReporter, byTarget, before, after };
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,14 @@
|
||||||
return url.toString();
|
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 addTarget = (id: string | null) => {
|
||||||
const url = new URL(data.url);
|
const url = new URL(data.url);
|
||||||
if (id) url.searchParams.set("by-target", id);
|
if (id) url.searchParams.set("by-target", id);
|
||||||
|
@ -56,6 +64,11 @@
|
||||||
{#if data.byReporter}
|
{#if data.byReporter}
|
||||||
<li>Filtering by reporter (<a href={addReporter(null)}>clear</a>)</li>
|
<li>Filtering by reporter (<a href={addReporter(null)}>clear</a>)</li>
|
||||||
{/if}
|
{/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>
|
</ul>
|
||||||
|
|
||||||
{#if data.before}
|
{#if data.before}
|
||||||
|
|
|
@ -2,15 +2,15 @@ import { isRedirect, redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
import { apiRequest } from "$api";
|
import { apiRequest } from "$api";
|
||||||
import type { AuthResponse, AuthUrls } from "$api/models/auth";
|
import type { AuthResponse, AuthUrls } from "$api/models/auth";
|
||||||
import { setToken } from "$lib";
|
import { alertKey, setToken } from "$lib";
|
||||||
import ApiError, { ErrorCode } from "$api/error";
|
import ApiError, { ErrorCode } from "$api/error";
|
||||||
|
|
||||||
export const load = async ({ fetch, parent }) => {
|
export const load = async ({ fetch, parent, url }) => {
|
||||||
const parentData = await parent();
|
const parentData = await parent();
|
||||||
if (parentData.meUser) redirect(303, `/@${parentData.meUser.username}`);
|
if (parentData.meUser) redirect(303, `/@${parentData.meUser.username}`);
|
||||||
|
|
||||||
const urls = await apiRequest<AuthUrls>("POST", "/auth/urls", { fetch, isInternal: true });
|
const urls = await apiRequest<AuthUrls>("POST", "/auth/urls", { fetch, isInternal: true });
|
||||||
return { urls };
|
return { urls, alertKey: alertKey(url) };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import { t } from "$lib/i18n";
|
import { t } from "$lib/i18n";
|
||||||
import { enhance } from "$app/forms";
|
import { enhance } from "$app/forms";
|
||||||
import ErrorAlert from "$components/ErrorAlert.svelte";
|
import ErrorAlert from "$components/ErrorAlert.svelte";
|
||||||
|
import UrlAlert from "$components/URLAlert.svelte";
|
||||||
|
|
||||||
type Props = { data: PageData; form: ActionData };
|
type Props = { data: PageData; form: ActionData };
|
||||||
let { data, form }: Props = $props();
|
let { data, form }: Props = $props();
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<UrlAlert {data} />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{#if form?.error}
|
{#if form?.error}
|
||||||
<ErrorAlert error={form.error} />
|
<ErrorAlert error={form.error} />
|
||||||
|
|
|
@ -2,5 +2,5 @@ import { redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load = async ({ parent }) => {
|
export const load = async ({ parent }) => {
|
||||||
const { meUser } = await parent();
|
const { meUser } = await parent();
|
||||||
if (!meUser) redirect(303, "/auth/log-in");
|
if (!meUser) redirect(303, "/auth/log-in?alert=auth-required");
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load = async ({ parent }) => {
|
export const load = async ({ parent }) => {
|
||||||
const data = await 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! };
|
return { user: data.meUser!, token: data.token! };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue