added voting

e
This commit is contained in:
Xodrium 2023-02-05 09:47:26 -05:00
parent d8670ecf81
commit e211b2cc50
13 changed files with 92 additions and 201 deletions

View file

@ -74,7 +74,7 @@
<img src='/logo_sanifae.svg' alt='Sanifae Logo'>
</a>
{#if data.username && data.username != 'false'}
<a href='/users/{data.username}'>
<a href='/user/{data.username}'>
{data.username}
</a>
<a href='/logout'>

View file

@ -1,5 +1,5 @@
<script>
import Post from '$lib/Post.svelte';
import Post from '$lib/components/Post.svelte';
/** @type {import('./$types').PageData} */
export let data;

View file

@ -1,5 +1,5 @@
<script>
import Area from '$lib/Area.svelte';
import Area from '$lib/components/Area.svelte';
import { handleSubmit } from '$lib/util.js';
export let form = {};

View file

@ -1,4 +1,4 @@
import { backend } from '../../../lib/db.js';
import { backend } from '../../../lib/db/db.js';
/** @type {import('./$types').RequestHandler} */
export async function GET({ url, cookies, params }) {

View file

@ -1,4 +1,4 @@
import { backend } from '../../lib/db.js';
import { backend } from '../../lib/db/db.js';
import { checkLength, checkRegex } from '../../lib/util.js';
/** @type {import('./$types').Actions} */

View file

@ -1,5 +1,5 @@
<script>
import Area from '$lib/Area.svelte';
import Area from '$lib/components/Area.svelte';
import { handleSubmit } from '$lib/util.js';

View file

@ -1,5 +1,5 @@
<script>
import Post from '$lib/Post.svelte';
import Post from '$lib/components/Post.svelte';
/** @type {import('./$types').PageData} */
export let data;

View file

@ -0,0 +1,20 @@
/** @type {import('./$types').PageLoad} */
export async function load({ fetch, params, url }) {
var search = url.searchParams;
var voteType = search.get('vote');
var id = search.get('page') * 1;
var user = params.user + '';
await new Promise(resolve => setTimeout(resolve, 100));
const res = await fetch(`/api/postBulk?user=${user}&page=${id}`);
const postJson = await res.json();
const resUser = await fetch(`/api/userGet?user=${user}`);
const postJsonUser = await resUser.json();
return { postJson, id, postJsonUser };
}

View file

@ -0,0 +1,49 @@
<script>
import Post from '$lib/components/Post.svelte';
import Area from '$lib/components/Area.svelte';
/** @type {import('./$types').PageData} */
export let data;
let userData = data.postJsonUser.data;
</script>
<Area>
<span slot="header">
<a href='/users/{userData.username}'>
{userData.username}
</a>
</span>
<span slot="main">
<p>
<b>Reputation:</b> {userData.reputation}
</p>
<p>
<b>Upvotes:</b> {userData.upvotes}
</p>
<p>
<b>Downvotes:</b> {userData.downvotes}
</p>
</span>
<span slot="footer">
</span>
</Area>
<h2>Posts</h2>
{#each data.postJson.data as post}
<Post
success={post.success}
username={post.username}
content={post.content}
upvotes={post.upvotes}
downvotes={post.downvotes}
id={post.id}
></Post>
{/each}
<p>
<a data-sveltekit-reload href='?page={data.id+1}'>Next page</a>
</p>
<p></p>