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",
|
"name": "@yusurko/vigil",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0-dev46",
|
"version": "0.1.0-dev47",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
let { query = $bindable<string>() }: {query?: string} = $props();
|
let { query }: {query?: string} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input value={query} type="search" name="query" class="bigsearch" />
|
<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">
|
<script lang="ts">
|
||||||
|
import { enhance } from "$app/forms";
|
||||||
import Centered from "$lib/Centered.svelte";
|
import Centered from "$lib/Centered.svelte";
|
||||||
import EditPost from "$lib/EditPost.svelte";
|
import EditPost from "$lib/EditPost.svelte";
|
||||||
import { getMe } from "$lib/globals.svelte";
|
import { getMe } from "$lib/globals.svelte";
|
||||||
|
|
@ -12,14 +13,15 @@
|
||||||
let content = $state("");
|
let content = $state("");
|
||||||
let privacy = $state(0);
|
let privacy = $state(0);
|
||||||
let guildName = $state("");
|
let guildName = $state("");
|
||||||
|
//let guildInfo = $state(null);
|
||||||
let enablePost = $derived(!!content && !!guildName && false);
|
|
||||||
|
let enablePost = $derived(!!content && !!guildName);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
{#if me}
|
{#if me}
|
||||||
<SLayout title="New post">
|
<SLayout title="New post">
|
||||||
<form method="POST" class="card">
|
<form method="POST" class="card" use:enhance>
|
||||||
<p>Posting as <strong>@{me.username}</strong></p>
|
<p>Posting as <strong>@{me.username}</strong></p>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ export const actions = {
|
||||||
// login success
|
// login success
|
||||||
const { id: myId } = respData;
|
const { id: myId } = respData;
|
||||||
|
|
||||||
redirect(303, "/user/" + myId);
|
redirect(303, "/@" + myId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} satisfies Actions;
|
} satisfies Actions;
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,9 @@ export const actions = {
|
||||||
event.locals.results = results;
|
event.locals.results = results;
|
||||||
event.locals.query = query;
|
event.locals.query = query;
|
||||||
console.log(event.locals);
|
console.log(event.locals);
|
||||||
|
|
||||||
|
return { results, query };
|
||||||
}
|
}
|
||||||
} satisfies Actions;
|
} satisfies Actions;
|
||||||
|
|
||||||
export function load (event) {
|
|
||||||
const { results, query } = event.locals;
|
|
||||||
|
|
||||||
return { results, query };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,30 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { enhance } from "$app/forms";
|
import { enhance } from "$app/forms";
|
||||||
|
import type { PostEntry } from "$lib/backend";
|
||||||
import BigSearchInput from "$lib/BigSearchInput.svelte";
|
import BigSearchInput from "$lib/BigSearchInput.svelte";
|
||||||
import Feed from "$lib/Feed.svelte";
|
import Feed from "$lib/Feed.svelte";
|
||||||
import { RiSearchLine } from "svelte-remixicon";
|
import { RiSearchLine } from "svelte-remixicon";
|
||||||
import type { PageProps } from "./$types";
|
|
||||||
|
|
||||||
let { data }: PageProps = $props();
|
let { data }: {
|
||||||
console.log(data);
|
data: {
|
||||||
|
query: string,
|
||||||
|
results: PostEntry[]
|
||||||
|
}
|
||||||
|
} = $props();
|
||||||
let { query, results } = $derived(data);
|
let { query, results } = $derived(data);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form method="POST" use:enhance>
|
<form method="POST" use:enhance>
|
||||||
<ul class="row">
|
<ul class="row">
|
||||||
<BigSearchInput bind:query />
|
<BigSearchInput {query} />
|
||||||
<button class="inline"><RiSearchLine /></button>
|
<button type="submit" class="inline"><RiSearchLine /></button>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{#if query}
|
{#if query}
|
||||||
<Feed posts={results} />
|
<Feed posts={results} />
|
||||||
|
{:else}
|
||||||
|
<p>Search function is broken!</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue