Added a sort for trending posts
This commit is contained in:
parent
2bb1c9725d
commit
e2a3f560c1
3 changed files with 15 additions and 8 deletions
|
@ -7,8 +7,9 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','rating')}}>Sort by rating</Button>
|
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','hot')}}>Hot</Button>
|
||||||
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','time')}}>Sort by time</Button>
|
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','rating')}}>Top</Button>
|
||||||
|
<Button clickFunc={() => { window.location.search = setLocation(window.location,'sort','time')}}>Recent</Button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{#if data && data.postJson && data.postJson.data}
|
{#if data && data.postJson && data.postJson.data}
|
||||||
|
|
|
@ -9,10 +9,11 @@ const AUTH_ACTIONS = [
|
||||||
'follow'
|
'follow'
|
||||||
];
|
];
|
||||||
|
|
||||||
const LEGAL_SORTS = [
|
const LEGAL_SORTS = {
|
||||||
'time',
|
'time': 'time',
|
||||||
'rating'
|
'rating': 'rating',
|
||||||
]
|
'hot': `rating / (%d - time + 24000)`
|
||||||
|
}
|
||||||
|
|
||||||
const FILE_SIZE_LIMIT = 1024*1024*16;
|
const FILE_SIZE_LIMIT = 1024*1024*16;
|
||||||
|
|
||||||
|
@ -226,7 +227,12 @@ backend.postBulk = async ({page, id, user, cookies, sort, type}) => {
|
||||||
|
|
||||||
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[sort]) || 'rating';
|
||||||
|
|
||||||
|
if (sort + '' != sort) sort = 'rating';
|
||||||
|
|
||||||
|
sort = sort.replaceAll('%d',Math.floor(new Date() * 1000));
|
||||||
|
|
||||||
|
|
||||||
if (type == 'all') {
|
if (type == 'all') {
|
||||||
posts = await db.all('SELECT * from post ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
posts = await db.all('SELECT * from post ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
||||||
|
|
|
@ -4,7 +4,7 @@ export async function load({ fetch, params, url }) {
|
||||||
|
|
||||||
var id = search.get('page') * 1;
|
var id = search.get('page') * 1;
|
||||||
|
|
||||||
var sort = search.get('sort') || 'rating';
|
var sort = search.get('sort') || 'hot';
|
||||||
|
|
||||||
var type = search.get('type') || 'all';
|
var type = search.get('type') || 'all';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue