add search, improve SLayout
This commit is contained in:
parent
ddb07a651e
commit
1dc5768640
11 changed files with 153 additions and 15 deletions
|
|
@ -37,7 +37,7 @@ async function loadMe(event: LoadEvent, me?: string): Promise<UserEntry | null>
|
|||
}
|
||||
|
||||
|
||||
export async function load(event): Promise<{site: ServerHealth | null, me: UserEntry | null} > {
|
||||
export async function load(event) {
|
||||
let site = await loadSite(event);
|
||||
let me = await loadMe (event, site?.me || void 0);
|
||||
return { site, me };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { backend } from '$lib/backend.js';
|
||||
import { backend } from '$lib/backend';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export async function load(event) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export async function load (event) {
|
|||
redirect(303, next);
|
||||
}
|
||||
|
||||
// cookies managed by backend
|
||||
const resp = await backend.withEvent(event).fetch("logout", {method: 'POST'});
|
||||
|
||||
if ([200, 204].indexOf(resp.status) >= 0) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
import { backend } from '$lib/backend';
|
||||
import type { Action, Actions } from '@sveltejs/kit';
|
||||
|
||||
|
||||
|
||||
export const actions = {
|
||||
default: async (event) => {
|
||||
const { request } = event;
|
||||
const data = await request.formData()
|
||||
|
||||
const query = data.get("query");
|
||||
if ("string" !== typeof query) {
|
||||
console.log("query is", query);
|
||||
return;
|
||||
}
|
||||
|
||||
const client = await backend.withEvent(event).oath();
|
||||
const resp = await client.submitJson('search/top', { query });
|
||||
|
||||
const { status } = resp;
|
||||
const respData = await resp.json();
|
||||
|
||||
if (status !== 200) {
|
||||
event.locals.results = [];
|
||||
event.locals.query = query;
|
||||
console.log({ query, status })
|
||||
return;
|
||||
}
|
||||
|
||||
const { has: results } = respData;
|
||||
|
||||
event.locals.results = results;
|
||||
event.locals.query = query;
|
||||
console.log(event.locals);
|
||||
return
|
||||
}
|
||||
} satisfies Actions;
|
||||
|
||||
export async function load (event) {
|
||||
const { results, query } = event.locals;
|
||||
|
||||
console.log({ results, query });
|
||||
return { results, query };
|
||||
}
|
||||
|
||||
22
src/routes/search/+page.svelte
Normal file
22
src/routes/search/+page.svelte
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from "$app/forms";
|
||||
import BigSearchInput from "$lib/BigSearchInput.svelte";
|
||||
import Feed from "$lib/Feed.svelte";
|
||||
import { RiSearchLine } from "svelte-remixicon";
|
||||
import type { PageProps } from "./$types";
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
let { query, results } = $derived(data);
|
||||
</script>
|
||||
|
||||
<form method="POST" use:enhance>
|
||||
<ul class="row">
|
||||
<BigSearchInput bind:query />
|
||||
<button class="inline"><RiSearchLine /></button>
|
||||
</ul>
|
||||
</form>
|
||||
{#if query}
|
||||
<Feed posts={results} />
|
||||
{/if}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue