mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-25 18:55:44 +03:00
One more logic for auto-collapsing
This commit is contained in:
parent
b8d7e18371
commit
6fcbc9dfa4
1 changed files with 19 additions and 2 deletions
|
@ -42,6 +42,7 @@ import useTitle from '../utils/useTitle';
|
||||||
import getInstanceStatusURL from './../utils/get-instance-status-url';
|
import getInstanceStatusURL from './../utils/get-instance-status-url';
|
||||||
|
|
||||||
const LIMIT = 40;
|
const LIMIT = 40;
|
||||||
|
const SUBCOMMENTS_OPEN_ALL_LIMIT = 10;
|
||||||
const MAX_WEIGHT = 5;
|
const MAX_WEIGHT = 5;
|
||||||
|
|
||||||
let cachedRepliesToggle = {};
|
let cachedRepliesToggle = {};
|
||||||
|
@ -162,6 +163,7 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
|
||||||
const [uiState, setUIState] = useState('default');
|
const [uiState, setUIState] = useState('default');
|
||||||
const heroStatusRef = useRef();
|
const heroStatusRef = useRef();
|
||||||
const sKey = statusKey(id, instance);
|
const sKey = statusKey(id, instance);
|
||||||
|
const totalDescendants = useRef(0);
|
||||||
|
|
||||||
const scrollableRef = useRef();
|
const scrollableRef = useRef();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -244,6 +246,8 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
|
||||||
const context = await contextFetch;
|
const context = await contextFetch;
|
||||||
const { ancestors, descendants } = context;
|
const { ancestors, descendants } = context;
|
||||||
|
|
||||||
|
totalDescendants.current = descendants?.length || 0;
|
||||||
|
|
||||||
ancestors.forEach((status) => {
|
ancestors.forEach((status) => {
|
||||||
saveStatus(status, instance, {
|
saveStatus(status, instance, {
|
||||||
skipThreading: true,
|
skipThreading: true,
|
||||||
|
@ -910,6 +914,9 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
|
||||||
hasParentThread={thread}
|
hasParentThread={thread}
|
||||||
level={1}
|
level={1}
|
||||||
accWeight={weight}
|
accWeight={weight}
|
||||||
|
openAll={
|
||||||
|
totalDescendants.current < SUBCOMMENTS_OPEN_ALL_LIMIT
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{uiState === 'loading' &&
|
{uiState === 'loading' &&
|
||||||
|
@ -988,7 +995,14 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SubComments({ replies, instance, hasParentThread, level, accWeight }) {
|
function SubComments({
|
||||||
|
replies,
|
||||||
|
instance,
|
||||||
|
hasParentThread,
|
||||||
|
level,
|
||||||
|
accWeight,
|
||||||
|
openAll,
|
||||||
|
}) {
|
||||||
const [searchParams, setSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
|
||||||
// Total comments count, including sub-replies
|
// Total comments count, including sub-replies
|
||||||
|
@ -1015,7 +1029,9 @@ function SubComments({ replies, instance, hasParentThread, level, accWeight }) {
|
||||||
}, [accWeight, replies?.length]);
|
}, [accWeight, replies?.length]);
|
||||||
|
|
||||||
let open = false;
|
let open = false;
|
||||||
if (totalWeight <= MAX_WEIGHT) {
|
if (openAll) {
|
||||||
|
open = true;
|
||||||
|
} else if (totalWeight <= MAX_WEIGHT) {
|
||||||
open = true;
|
open = true;
|
||||||
} else if (!hasParentThread && totalComments === 1) {
|
} else if (!hasParentThread && totalComments === 1) {
|
||||||
const shortReply = calcStatusWeight(replies[0]) < 2;
|
const shortReply = calcStatusWeight(replies[0]) < 2;
|
||||||
|
@ -1122,6 +1138,7 @@ function SubComments({ replies, instance, hasParentThread, level, accWeight }) {
|
||||||
replies={r.replies}
|
replies={r.replies}
|
||||||
level={level + 1}
|
level={level + 1}
|
||||||
accWeight={!open ? r.weight : totalWeight}
|
accWeight={!open ? r.weight : totalWeight}
|
||||||
|
openAll={openAll}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in a new issue