mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-29 04:38:55 +03:00
Sort by density
This commit is contained in:
parent
0ceb6ffd06
commit
346dba9ed7
1 changed files with 37 additions and 6 deletions
|
@ -22,6 +22,7 @@ import db from '../utils/db';
|
||||||
import emojifyText from '../utils/emojify-text';
|
import emojifyText from '../utils/emojify-text';
|
||||||
import { isFiltered } from '../utils/filters';
|
import { isFiltered } from '../utils/filters';
|
||||||
import getHTMLText from '../utils/getHTMLText';
|
import getHTMLText from '../utils/getHTMLText';
|
||||||
|
import htmlContentLength from '../utils/html-content-length';
|
||||||
import niceDateTime from '../utils/nice-date-time';
|
import niceDateTime from '../utils/nice-date-time';
|
||||||
import shortenNumber from '../utils/shorten-number';
|
import shortenNumber from '../utils/shorten-number';
|
||||||
import showToast from '../utils/show-toast';
|
import showToast from '../utils/show-toast';
|
||||||
|
@ -423,10 +424,19 @@ function Catchup() {
|
||||||
if (sortBy !== 'createdAt') {
|
if (sortBy !== 'createdAt') {
|
||||||
a = a.reblog || a;
|
a = a.reblog || a;
|
||||||
b = b.reblog || b;
|
b = b.reblog || b;
|
||||||
if (a[sortBy] === b[sortBy]) {
|
if (sortBy !== 'density' && a[sortBy] === b[sortBy]) {
|
||||||
return a.createdAt > b.createdAt ? 1 : -1;
|
return a.createdAt > b.createdAt ? 1 : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sortBy === 'density') {
|
||||||
|
const aDensity = postDensity(a);
|
||||||
|
const bDensity = postDensity(b);
|
||||||
|
if (sortOrder === 'asc') {
|
||||||
|
return aDensity > bDensity ? 1 : -1;
|
||||||
|
} else {
|
||||||
|
return bDensity > aDensity ? 1 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (sortOrder === 'asc') {
|
if (sortOrder === 'asc') {
|
||||||
return a[sortBy] > b[sortBy] ? 1 : -1;
|
return a[sortBy] > b[sortBy] ? 1 : -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -489,6 +499,7 @@ function Catchup() {
|
||||||
repliesCount: ['fewest replies', 'most replies'],
|
repliesCount: ['fewest replies', 'most replies'],
|
||||||
favouritesCount: ['fewest likes', 'most likes'],
|
favouritesCount: ['fewest likes', 'most likes'],
|
||||||
reblogsCount: ['fewest boosts', 'most boosts'],
|
reblogsCount: ['fewest boosts', 'most boosts'],
|
||||||
|
density: ['least dense', 'most dense'],
|
||||||
};
|
};
|
||||||
const groupByText = {
|
const groupByText = {
|
||||||
account: 'authors',
|
account: 'authors',
|
||||||
|
@ -994,6 +1005,7 @@ function Catchup() {
|
||||||
'repliesCount',
|
'repliesCount',
|
||||||
'favouritesCount',
|
'favouritesCount',
|
||||||
'reblogsCount',
|
'reblogsCount',
|
||||||
|
'density',
|
||||||
// 'account',
|
// 'account',
|
||||||
].map((key) => (
|
].map((key) => (
|
||||||
<label class="filter-sort" key={key}>
|
<label class="filter-sort" key={key}>
|
||||||
|
@ -1003,9 +1015,8 @@ function Catchup() {
|
||||||
checked={sortBy === key}
|
checked={sortBy === key}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
setSortBy(key);
|
setSortBy(key);
|
||||||
const order = /(replies|favourites|reblogs)/.test(
|
const order =
|
||||||
key,
|
/(replies|favourites|reblogs|density)/.test(key)
|
||||||
)
|
|
||||||
? 'desc'
|
? 'desc'
|
||||||
: 'asc';
|
: 'asc';
|
||||||
setSortOrder(order);
|
setSortOrder(order);
|
||||||
|
@ -1018,6 +1029,7 @@ function Catchup() {
|
||||||
repliesCount: 'Replies',
|
repliesCount: 'Replies',
|
||||||
favouritesCount: 'Likes',
|
favouritesCount: 'Likes',
|
||||||
reblogsCount: 'Boosts',
|
reblogsCount: 'Boosts',
|
||||||
|
density: 'Density',
|
||||||
}[key]
|
}[key]
|
||||||
}
|
}
|
||||||
</label>
|
</label>
|
||||||
|
@ -1241,6 +1253,25 @@ const IntersectionPostLine = ({ root, ...props }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A media speak a thousand words
|
||||||
|
const MEDIA_DENSITY = 8;
|
||||||
|
const CARD_DENSITY = 8;
|
||||||
|
function postDensity(post) {
|
||||||
|
const { spoilerText, content, poll, mediaAttachments, card } = post;
|
||||||
|
const pollContent = poll?.options?.length
|
||||||
|
? poll.options.reduce((acc, cur) => acc + cur.title, '')
|
||||||
|
: '';
|
||||||
|
const density =
|
||||||
|
(spoilerText.length + htmlContentLength(content) + pollContent.length) /
|
||||||
|
140 +
|
||||||
|
(mediaAttachments?.length
|
||||||
|
? MEDIA_DENSITY * mediaAttachments.length
|
||||||
|
: card?.image
|
||||||
|
? CARD_DENSITY
|
||||||
|
: 0);
|
||||||
|
return density;
|
||||||
|
}
|
||||||
|
|
||||||
const MEDIA_SIZE = 48;
|
const MEDIA_SIZE = 48;
|
||||||
|
|
||||||
function PostPeek({ post, filterInfo }) {
|
function PostPeek({ post, filterInfo }) {
|
||||||
|
|
Loading…
Reference in a new issue