diff --git a/src/lib/db/db.js b/src/lib/db/db.js
index 61d93f7..5c99bdd 100644
--- a/src/lib/db/db.js
+++ b/src/lib/db/db.js
@@ -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 => {
diff --git a/src/routes/+page.js b/src/routes/+page.js
index 3c26ebb..a391fe7 100644
--- a/src/routes/+page.js
+++ b/src/routes/+page.js
@@ -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 };
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index d065fc8..4971b8a 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -1,8 +1,22 @@
-
+ + +
+ ++ {#if data.id > 0} + + {/if} + +
\ No newline at end of file diff --git a/src/routes/post/[post]/+page.js b/src/routes/post/[post]/+page.js index 4de9b03..803ed80 100644 --- a/src/routes/post/[post]/+page.js +++ b/src/routes/post/[post]/+page.js @@ -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}; diff --git a/src/routes/users/[user]/+page.js b/src/routes/users/[user]/+page.js index f580b3a..8eed58b 100644 --- a/src/routes/users/[user]/+page.js +++ b/src/routes/users/[user]/+page.js @@ -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}`);