sanifae/src/routes/users/[user]/+page.svelte

159 lines
4 KiB
Svelte
Raw Normal View History

2023-02-05 09:47:26 -05:00
<script>
2023-02-12 01:53:13 -05:00
import Button from '$lib/components/Button.svelte'
2023-02-05 09:47:26 -05:00
import Area from '$lib/components/Area.svelte';
2023-02-12 01:53:13 -05:00
import PostList from '$lib/components/PostList.svelte';
2023-03-06 16:15:27 -05:00
import FileUpload from '$lib/components/FileUpload.svelte';
2023-02-05 09:47:26 -05:00
/** @type {import('./$types').PageData} */
export let data;
2023-03-06 16:15:27 -05:00
let uploadForm = {};
2023-02-05 09:47:26 -05:00
let userData = data.postJsonUser.data;
2023-03-06 02:26:57 -05:00
let following = data.postJsonUser.following;
let followers = data.postJsonUser.followers;
function follow() {
let fData = (new FormData());
fData.append('target',userData.username);
fetch('/api/follow', {
method: 'POST',
body: fData
}).then(async x => {
let xJson = (await x.json()).data;
following = xJson.following;
followers = xJson.followers;
})
}
2023-02-05 09:47:26 -05:00
</script>
2023-03-06 02:34:40 -05:00
<style>
.follower {
margin-right: 1.5rem;
}
2023-03-06 16:15:27 -05:00
.pfp {
2023-03-09 19:12:17 -05:00
width: 100px;
height: 100px;
border-radius: 100%;
}
.pfp-small {
width: 45px;
height: 45px;
border-radius: 100%;
2023-03-06 16:15:27 -05:00
}
#header {
display: flex;
2023-03-09 19:12:17 -05:00
justify-content: space-between;
width: 100%;
}
.sections {
display: grid;
grid-template-columns: 1fr 1fr;
}
.sections div {
text-align: right;
2023-03-10 18:28:33 -05:00
max-height: 300px;
overflow-y: auto;
2023-03-09 19:12:17 -05:00
}
.sections div:nth-child(1) {
text-align: left;
}
.profile {
2023-03-06 16:55:16 -05:00
align-items: center;
2023-03-09 19:12:17 -05:00
flex-direction: column;
display: flex;
2023-03-06 16:15:27 -05:00
}
2023-03-06 02:34:40 -05:00
</style>
2023-03-08 19:53:20 -05:00
{#if userData}
2023-02-11 19:42:10 -05:00
<Area>
2023-03-06 16:15:27 -05:00
<span slot="header" id='header'>
2023-03-09 19:12:17 -05:00
<div class='profile'>
<img class='pfp' src='/img/pfp/{userData.username}.png'/>
<a href='/users/{userData.username}'>
{userData.username}
</a>
</div>
<div>
<Button clickFunc={follow}>
Follow
</Button>
</div>
2023-02-11 19:42:10 -05:00
</span>
<span slot="main">
2023-03-09 19:12:17 -05:00
<p class='data'>
<span class='follower'>
<b>{userData.reputation}</b> Reputation
</span>
<span class='follower'>
<b>{userData.upvotes}</b> Upvotes
</span>
<span class='follower'>
<b>{userData.downvotes}</b> Downvotes
</span>
2023-02-11 19:42:10 -05:00
</p>
2023-03-09 19:12:17 -05:00
{#if userData.rolesArr}
<p>
{#each userData.rolesArr as role}
<b class='follower'>{role}</b>
2023-03-08 19:53:20 -05:00
{/each}
2023-03-09 19:12:17 -05:00
</p>
{/if}
2023-03-06 02:26:57 -05:00
2023-03-09 19:12:17 -05:00
<div class='sections'>
<div>
2023-03-10 18:28:33 -05:00
<h2>{following.length} following</h2>
2023-03-09 19:12:17 -05:00
{#each following as user}
2023-03-10 18:28:33 -05:00
<a href='/users/{user.following}'>
2023-03-09 19:12:17 -05:00
<img class='pfp-small' src='/img/pfp/{user.following}.png'/>
</a>
{/each}
</div>
<div>
2023-03-10 18:28:33 -05:00
<h2>{followers.length} followers</h2>
2023-03-09 19:12:17 -05:00
{#each followers as user}
2023-03-10 18:28:33 -05:00
<a href='/users/{user.username}'>
2023-03-09 19:12:17 -05:00
<img class='pfp-small' src='/img/pfp/{user.username}.png'/>
</a>
{/each}
</div>
</div>
2023-03-06 02:26:57 -05:00
2023-03-06 16:15:27 -05:00
{#if data.resAcc.data == userData.username}
<h2>Set PFP</h2>
<FileUpload bind:form={uploadForm} type='small' apiUrl={'/api/pfp'}/>
{/if}
2023-02-11 19:42:10 -05:00
</span>
<span slot="footer">
2023-03-09 19:12:17 -05:00
2023-02-11 19:42:10 -05:00
</span>
</Area>
{:else}
<Area>
<span slot="header">
2023-02-12 01:53:13 -05:00
<a href='/users/{data.user}'>
{data.user}
</a>
2023-02-11 19:42:10 -05:00
</span>
<span slot="main">
</span>
<span slot="footer">
2023-02-12 01:53:13 -05:00
This user does not have any statistics available.
2023-02-11 19:42:10 -05:00
</span>
</Area>
{/if}
2023-02-05 09:47:26 -05:00
2023-02-12 01:53:13 -05:00
<PostList data={data} />