try to fix search to no avail, add submit form to /create
This commit is contained in:
parent
9fd5be2815
commit
3cf9e024c0
7 changed files with 65 additions and 16 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@yusurko/vigil",
|
||||
"private": true,
|
||||
"version": "0.1.0-dev46",
|
||||
"version": "0.1.0-dev47",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
|
||||
let { query = $bindable<string>() }: {query?: string} = $props();
|
||||
let { query }: {query?: string} = $props();
|
||||
</script>
|
||||
|
||||
<input value={query} type="search" name="query" class="bigsearch" />
|
||||
|
|
|
|||
43
src/routes/create/+page.server.ts
Normal file
43
src/routes/create/+page.server.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { backend } from '$lib/backend.js';
|
||||
import { redirect } from 'sveltekit-flash-message/server';
|
||||
|
||||
export const actions = {
|
||||
|
||||
async default (event) {
|
||||
const { request }= event;
|
||||
|
||||
const data = await request.formData();
|
||||
const guildName = ''+data.get('to');
|
||||
const title = data.get('title');
|
||||
const content = data.get('content');
|
||||
const privacy = +(data.get('privacy') || 0);
|
||||
|
||||
const backend2 = await backend.withEvent(event).oath();
|
||||
const resp = await backend2.submitJson(`guild/@${encodeURIComponent(guildName)}`, {
|
||||
title, content, privacy
|
||||
})
|
||||
|
||||
const { status } = resp;
|
||||
const respData = await resp.json();
|
||||
|
||||
if ([200, 204].indexOf(status) < 0) {
|
||||
// error
|
||||
console.log(`/create: status ${status}`);
|
||||
switch(status) {
|
||||
case 403:
|
||||
case 404:
|
||||
redirect({
|
||||
message: respData.error
|
||||
}, event);
|
||||
break;
|
||||
default:
|
||||
redirect({message: `Unknown error (HTTP ${status})`}, event);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
const { id: myId } = respData;
|
||||
|
||||
redirect(303, "/=" + myId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from "$app/forms";
|
||||
import Centered from "$lib/Centered.svelte";
|
||||
import EditPost from "$lib/EditPost.svelte";
|
||||
import { getMe } from "$lib/globals.svelte";
|
||||
|
|
@ -12,14 +13,15 @@
|
|||
let content = $state("");
|
||||
let privacy = $state(0);
|
||||
let guildName = $state("");
|
||||
//let guildInfo = $state(null);
|
||||
|
||||
let enablePost = $derived(!!content && !!guildName && false);
|
||||
let enablePost = $derived(!!content && !!guildName);
|
||||
</script>
|
||||
|
||||
|
||||
{#if me}
|
||||
<SLayout title="New post">
|
||||
<form method="POST" class="card">
|
||||
<form method="POST" class="card" use:enhance>
|
||||
<p>Posting as <strong>@{me.username}</strong></p>
|
||||
|
||||
<label>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export const actions = {
|
|||
// login success
|
||||
const { id: myId } = respData;
|
||||
|
||||
redirect(303, "/user/" + myId);
|
||||
redirect(303, "/@" + myId);
|
||||
}
|
||||
}
|
||||
} satisfies Actions;
|
||||
|
|
|
|||
|
|
@ -32,12 +32,9 @@ export const actions = {
|
|||
event.locals.results = results;
|
||||
event.locals.query = query;
|
||||
console.log(event.locals);
|
||||
|
||||
return { results, query };
|
||||
}
|
||||
} satisfies Actions;
|
||||
|
||||
export function load (event) {
|
||||
const { results, query } = event.locals;
|
||||
|
||||
return { results, query };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,30 @@
|
|||
<script lang="ts">
|
||||
import { enhance } from "$app/forms";
|
||||
import type { PostEntry } from "$lib/backend";
|
||||
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();
|
||||
console.log(data);
|
||||
let { data }: {
|
||||
data: {
|
||||
query: string,
|
||||
results: PostEntry[]
|
||||
}
|
||||
} = $props();
|
||||
let { query, results } = $derived(data);
|
||||
</script>
|
||||
|
||||
<form method="POST" use:enhance>
|
||||
<ul class="row">
|
||||
<BigSearchInput bind:query />
|
||||
<button class="inline"><RiSearchLine /></button>
|
||||
<BigSearchInput {query} />
|
||||
<button type="submit" class="inline"><RiSearchLine /></button>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
{#if query}
|
||||
<Feed posts={results} />
|
||||
{:else}
|
||||
<p>Search function is broken!</p>
|
||||
{/if}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue