Added "followers only" filter
This commit is contained in:
parent
3448277220
commit
5eb2a25591
5 changed files with 34 additions and 10 deletions
|
@ -221,19 +221,19 @@ backend.userBio = async ({user}) => {
|
|||
return {data: posts[0]};
|
||||
}
|
||||
|
||||
backend.postBulk = async ({page, id, user, cookies, sort}) => {
|
||||
backend.postBulk = async ({page, id, user, cookies, sort, type}) => {
|
||||
var posts;
|
||||
|
||||
var userAuth = (await backend.token({cookies})).data;
|
||||
var userAuth = (await backend.token({cookies})).data || '';
|
||||
|
||||
sort = (LEGAL_SORTS.indexOf(sort) == -1) ? 'rating' : sort;
|
||||
sort = (LEGAL_SORTS.indexOf(sort + '') == -1) ? 'rating' : sort;
|
||||
|
||||
if (!user && !id) {
|
||||
if (type == 'all') {
|
||||
posts = await db.all('SELECT * from post ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
||||
page*ROW_COUNT,
|
||||
ROW_COUNT
|
||||
])
|
||||
} else if (id) {
|
||||
} else if (type == 'post') {
|
||||
posts = await db.all('SELECT * from post WHERE id = ?', [
|
||||
id
|
||||
]);
|
||||
|
@ -246,12 +246,20 @@ backend.postBulk = async ({page, id, user, cookies, sort}) => {
|
|||
ROW_COUNT
|
||||
])))
|
||||
|
||||
} else {
|
||||
} else if (type == 'user') {
|
||||
posts = await db.all('SELECT * from post WHERE username = ? ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
||||
user,
|
||||
page*ROW_COUNT,
|
||||
ROW_COUNT
|
||||
])
|
||||
} else if (type == 'follow') {
|
||||
posts = await db.all('SELECT * from post WHERE username IN (SELECT username from follow WHERE username = ?) ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
||||
userAuth,
|
||||
page*ROW_COUNT,
|
||||
ROW_COUNT
|
||||
])
|
||||
|
||||
console.log(posts);
|
||||
}
|
||||
|
||||
posts = posts.map(post => {
|
||||
|
|
|
@ -6,9 +6,11 @@ export async function load({ fetch, params, url }) {
|
|||
|
||||
var sort = search.get('sort') || 'rating';
|
||||
|
||||
var type = search.get('type') || 'all';
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
const res = await fetch(`/api/postBulk?page=${id}&sort=${sort}`);
|
||||
const res = await fetch(`/api/postBulk?page=${id}&sort=${sort}&type=${type}`);
|
||||
const postJson = await res.json();
|
||||
|
||||
return { postJson, id };
|
||||
|
|
|
@ -1,8 +1,22 @@
|
|||
<script>
|
||||
import PostList from '$lib/components/PostList.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import {setLocation} from '$lib/util.js';
|
||||
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<p>
|
||||
<Button clickFunc={() => { window.location.search = setLocation(window.location,'type',('all')) }}>All users</Button>
|
||||
<Button clickFunc={() => { window.location.search = setLocation(window.location,'type',('follow')) }}>Followers only</Button>
|
||||
</p>
|
||||
|
||||
<PostList data={data} />
|
||||
|
||||
<p>
|
||||
{#if data.id > 0}
|
||||
<Button clickFunc={() => { window.location.search = setLocation(window.location,'page',((data.id)-1)) }}>Previous page</Button>
|
||||
{/if}
|
||||
<Button clickFunc={() => { window.location.search = setLocation(window.location,'page',((data.id)+1)) }}>Next page</Button>
|
||||
</p>
|
|
@ -9,7 +9,7 @@ export async function load({ fetch, params, url }) {
|
|||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
const res = await fetch(`/api/postBulk?id=${id}&page=${page}&sort=${sort}`);
|
||||
const res = await fetch(`/api/postBulk?id=${id}&page=${page}&sort=${sort}&type=post`);
|
||||
const postJson = (await res.json());
|
||||
|
||||
return {postJson, id: page};
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function load({ fetch, params, url }) {
|
|||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
const res = await fetch(`/api/postBulk?user=${user}&page=${id}&sort=${sort}`);
|
||||
const res = await fetch(`/api/postBulk?user=${user}&page=${id}&sort=${sort}&type=user`);
|
||||
const postJson = await res.json();
|
||||
|
||||
const resUser = await fetch(`/api/userGet?user=${user}`);
|
||||
|
|
Loading…
Reference in a new issue