2023-01-07 09:45:04 +03:00
|
|
|
import { memo } from 'preact/compat';
|
2022-12-10 12:14:48 +03:00
|
|
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
2022-12-31 04:52:31 +03:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
2023-01-30 15:51:06 +03:00
|
|
|
import { useDebouncedCallback } from 'use-debounce';
|
2022-12-10 12:14:48 +03:00
|
|
|
import { useSnapshot } from 'valtio';
|
|
|
|
|
|
|
|
import Icon from '../components/icon';
|
2023-01-20 19:23:59 +03:00
|
|
|
import Link from '../components/link';
|
2022-12-10 12:14:48 +03:00
|
|
|
import Loader from '../components/loader';
|
|
|
|
import Status from '../components/status';
|
2023-02-05 19:17:19 +03:00
|
|
|
import { api } from '../utils/api';
|
2023-01-13 10:30:09 +03:00
|
|
|
import db from '../utils/db';
|
2023-01-09 14:11:34 +03:00
|
|
|
import states, { saveStatus } from '../utils/states';
|
2023-01-13 10:30:09 +03:00
|
|
|
import { getCurrentAccountNS } from '../utils/store-utils';
|
2023-01-02 16:36:24 +03:00
|
|
|
import useScroll from '../utils/useScroll';
|
2023-01-29 10:19:26 +03:00
|
|
|
import useTitle from '../utils/useTitle';
|
2022-12-10 12:14:48 +03:00
|
|
|
|
|
|
|
const LIMIT = 20;
|
|
|
|
|
2022-12-16 08:27:04 +03:00
|
|
|
function Home({ hidden }) {
|
2023-01-29 10:19:26 +03:00
|
|
|
useTitle('Home', '/');
|
2023-02-06 11:35:03 +03:00
|
|
|
const { masto, instance } = api();
|
2022-12-10 12:14:48 +03:00
|
|
|
const snapStates = useSnapshot(states);
|
|
|
|
const [uiState, setUIState] = useState('default');
|
|
|
|
const [showMore, setShowMore] = useState(false);
|
|
|
|
|
2023-01-07 15:26:23 +03:00
|
|
|
console.debug('RENDER Home');
|
|
|
|
|
2023-01-27 06:47:30 +03:00
|
|
|
const homeIterator = useRef();
|
2022-12-10 12:14:48 +03:00
|
|
|
async function fetchStatuses(firstLoad) {
|
2022-12-25 18:28:55 +03:00
|
|
|
if (firstLoad) {
|
|
|
|
// Reset iterator
|
|
|
|
homeIterator.current = masto.v1.timelines.listHome({
|
|
|
|
limit: LIMIT,
|
|
|
|
});
|
2023-01-02 19:27:47 +03:00
|
|
|
states.homeNew = [];
|
2022-12-25 18:28:55 +03:00
|
|
|
}
|
|
|
|
const allStatuses = await homeIterator.current.next();
|
2023-01-20 19:23:59 +03:00
|
|
|
if (allStatuses.value?.length) {
|
2023-01-30 15:30:45 +03:00
|
|
|
// ENFORCE sort by datetime (Latest first)
|
|
|
|
allStatuses.value.sort((a, b) => {
|
|
|
|
const aDate = new Date(a.createdAt);
|
|
|
|
const bDate = new Date(b.createdAt);
|
|
|
|
return bDate - aDate;
|
|
|
|
});
|
2023-01-20 19:23:59 +03:00
|
|
|
const homeValues = allStatuses.value.map((status) => {
|
2023-02-06 11:35:03 +03:00
|
|
|
saveStatus(status, instance);
|
2023-01-20 19:23:59 +03:00
|
|
|
return {
|
|
|
|
id: status.id,
|
|
|
|
reblog: status.reblog?.id,
|
|
|
|
reply: !!status.inReplyToAccountId,
|
|
|
|
};
|
|
|
|
});
|
2023-01-14 14:42:04 +03:00
|
|
|
|
2023-01-20 19:23:59 +03:00
|
|
|
// BOOSTS CAROUSEL
|
|
|
|
if (snapStates.settings.boostsCarousel) {
|
|
|
|
let specialHome = [];
|
|
|
|
let boostStash = [];
|
|
|
|
let serialBoosts = 0;
|
|
|
|
for (let i = 0; i < homeValues.length; i++) {
|
|
|
|
const status = homeValues[i];
|
|
|
|
if (status.reblog) {
|
|
|
|
boostStash.push(status);
|
|
|
|
serialBoosts++;
|
|
|
|
} else {
|
|
|
|
specialHome.push(status);
|
|
|
|
if (serialBoosts < 3) {
|
|
|
|
serialBoosts = 0;
|
|
|
|
}
|
2023-01-16 15:50:03 +03:00
|
|
|
}
|
2023-01-14 14:42:04 +03:00
|
|
|
}
|
2023-01-20 19:23:59 +03:00
|
|
|
// if boostStash is more than quarter of homeValues
|
|
|
|
// or if there are 3 or more boosts in a row
|
|
|
|
if (boostStash.length > homeValues.length / 4 || serialBoosts >= 3) {
|
|
|
|
// if boostStash is more than 3 quarter of homeValues
|
|
|
|
const boostStashID = boostStash.map((status) => status.id);
|
|
|
|
if (boostStash.length > (homeValues.length * 3) / 4) {
|
|
|
|
// insert boost array at the end of specialHome list
|
|
|
|
specialHome = [
|
|
|
|
...specialHome,
|
|
|
|
{ id: boostStashID, boosts: boostStash },
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// insert boosts array in the middle of specialHome list
|
|
|
|
const half = Math.floor(specialHome.length / 2);
|
|
|
|
specialHome = [
|
|
|
|
...specialHome.slice(0, half),
|
|
|
|
{
|
|
|
|
id: boostStashID,
|
|
|
|
boosts: boostStash,
|
|
|
|
},
|
|
|
|
...specialHome.slice(half),
|
|
|
|
];
|
|
|
|
}
|
2023-01-14 14:42:04 +03:00
|
|
|
} else {
|
2023-01-20 19:23:59 +03:00
|
|
|
// Untouched, this is fine
|
|
|
|
specialHome = homeValues;
|
|
|
|
}
|
|
|
|
console.log({
|
|
|
|
specialHome,
|
|
|
|
});
|
|
|
|
if (firstLoad) {
|
2023-01-27 06:47:30 +03:00
|
|
|
states.homeLast = specialHome[0];
|
2023-01-20 19:23:59 +03:00
|
|
|
states.home = specialHome;
|
|
|
|
} else {
|
|
|
|
states.home.push(...specialHome);
|
2023-01-14 14:42:04 +03:00
|
|
|
}
|
|
|
|
} else {
|
2023-01-20 19:23:59 +03:00
|
|
|
if (firstLoad) {
|
2023-01-27 06:47:30 +03:00
|
|
|
states.homeLast = homeValues[0];
|
2023-01-20 19:23:59 +03:00
|
|
|
states.home = homeValues;
|
|
|
|
} else {
|
|
|
|
states.home.push(...homeValues);
|
|
|
|
}
|
2023-01-16 15:32:30 +03:00
|
|
|
}
|
2022-12-10 12:14:48 +03:00
|
|
|
}
|
2023-01-16 15:32:30 +03:00
|
|
|
|
2022-12-10 12:14:48 +03:00
|
|
|
states.homeLastFetchTime = Date.now();
|
2023-01-20 19:23:59 +03:00
|
|
|
return allStatuses;
|
2022-12-10 12:14:48 +03:00
|
|
|
}
|
|
|
|
|
2023-02-03 16:08:08 +03:00
|
|
|
const loadStatuses = useDebouncedCallback(
|
|
|
|
(firstLoad) => {
|
|
|
|
if (uiState === 'loading') return;
|
|
|
|
setUIState('loading');
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
const { done } = await fetchStatuses(firstLoad);
|
|
|
|
setShowMore(!done);
|
|
|
|
setUIState('default');
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
setUIState('error');
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
},
|
|
|
|
1500,
|
|
|
|
{
|
|
|
|
leading: true,
|
|
|
|
trailing: false,
|
|
|
|
},
|
|
|
|
);
|
2022-12-10 12:14:48 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loadStatuses(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const scrollableRef = useRef();
|
|
|
|
|
2023-02-06 18:47:58 +03:00
|
|
|
const jRef = useHotkeys('j, shift+j', (_, handler) => {
|
|
|
|
// focus on next status after active status
|
|
|
|
// Traverses .timeline li .status-link, focus on .status-link
|
|
|
|
const activeStatus = document.activeElement.closest(
|
|
|
|
'.status-link, .status-boost-link',
|
|
|
|
);
|
|
|
|
const activeStatusRect = activeStatus?.getBoundingClientRect();
|
|
|
|
const allStatusLinks = Array.from(
|
|
|
|
scrollableRef.current.querySelectorAll(
|
2023-01-14 14:42:04 +03:00
|
|
|
'.status-link, .status-boost-link',
|
2023-02-06 18:47:58 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
activeStatus &&
|
|
|
|
activeStatusRect.top < scrollableRef.current.clientHeight &&
|
|
|
|
activeStatusRect.bottom > 0
|
|
|
|
) {
|
|
|
|
const activeStatusIndex = allStatusLinks.indexOf(activeStatus);
|
|
|
|
let nextStatus = allStatusLinks[activeStatusIndex + 1];
|
|
|
|
if (handler.shift) {
|
|
|
|
// get next status that's not .status-boost-link
|
|
|
|
nextStatus = allStatusLinks.find(
|
|
|
|
(statusLink, index) =>
|
|
|
|
index > activeStatusIndex &&
|
|
|
|
!statusLink.classList.contains('status-boost-link'),
|
|
|
|
);
|
2022-12-31 04:52:31 +03:00
|
|
|
}
|
2023-02-06 18:47:58 +03:00
|
|
|
if (nextStatus) {
|
|
|
|
nextStatus.focus();
|
|
|
|
nextStatus.scrollIntoViewIfNeeded?.();
|
2022-12-31 04:52:31 +03:00
|
|
|
}
|
2023-02-06 18:47:58 +03:00
|
|
|
} else {
|
|
|
|
// If active status is not in viewport, get the topmost status-link in viewport
|
|
|
|
const topmostStatusLink = allStatusLinks.find((statusLink) => {
|
|
|
|
const statusLinkRect = statusLink.getBoundingClientRect();
|
|
|
|
return statusLinkRect.top >= 44 && statusLinkRect.left >= 0; // 44 is the magic number for header height, not real
|
|
|
|
});
|
|
|
|
if (topmostStatusLink) {
|
|
|
|
topmostStatusLink.focus();
|
|
|
|
topmostStatusLink.scrollIntoViewIfNeeded?.();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-12-31 04:52:31 +03:00
|
|
|
|
2023-02-06 18:47:58 +03:00
|
|
|
const kRef = useHotkeys('k, shift+k', (_, handler) => {
|
|
|
|
// focus on previous status after active status
|
|
|
|
// Traverses .timeline li .status-link, focus on .status-link
|
|
|
|
const activeStatus = document.activeElement.closest(
|
|
|
|
'.status-link, .status-boost-link',
|
|
|
|
);
|
|
|
|
const activeStatusRect = activeStatus?.getBoundingClientRect();
|
|
|
|
const allStatusLinks = Array.from(
|
|
|
|
scrollableRef.current.querySelectorAll(
|
2023-01-27 15:54:18 +03:00
|
|
|
'.status-link, .status-boost-link',
|
2023-02-06 18:47:58 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
activeStatus &&
|
|
|
|
activeStatusRect.top < scrollableRef.current.clientHeight &&
|
|
|
|
activeStatusRect.bottom > 0
|
|
|
|
) {
|
|
|
|
const activeStatusIndex = allStatusLinks.indexOf(activeStatus);
|
|
|
|
let prevStatus = allStatusLinks[activeStatusIndex - 1];
|
|
|
|
if (handler.shift) {
|
|
|
|
// get prev status that's not .status-boost-link
|
|
|
|
prevStatus = allStatusLinks.findLast(
|
|
|
|
(statusLink, index) =>
|
|
|
|
index < activeStatusIndex &&
|
|
|
|
!statusLink.classList.contains('status-boost-link'),
|
|
|
|
);
|
2023-01-27 15:54:18 +03:00
|
|
|
}
|
2023-02-06 18:47:58 +03:00
|
|
|
if (prevStatus) {
|
|
|
|
prevStatus.focus();
|
|
|
|
prevStatus.scrollIntoViewIfNeeded?.();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If active status is not in viewport, get the topmost status-link in viewport
|
|
|
|
const topmostStatusLink = allStatusLinks.find((statusLink) => {
|
|
|
|
const statusLinkRect = statusLink.getBoundingClientRect();
|
|
|
|
return statusLinkRect.top >= 44 && statusLinkRect.left >= 0; // 44 is the magic number for header height, not real
|
|
|
|
});
|
|
|
|
if (topmostStatusLink) {
|
|
|
|
topmostStatusLink.focus();
|
|
|
|
topmostStatusLink.scrollIntoViewIfNeeded?.();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const oRef = useHotkeys(['enter', 'o'], () => {
|
|
|
|
// open active status
|
|
|
|
const activeStatus = document.activeElement.closest(
|
|
|
|
'.status-link, .status-boost-link',
|
|
|
|
);
|
|
|
|
if (activeStatus) {
|
|
|
|
activeStatus.click();
|
|
|
|
}
|
|
|
|
});
|
2022-12-31 04:52:31 +03:00
|
|
|
|
2023-01-16 15:32:30 +03:00
|
|
|
const {
|
|
|
|
scrollDirection,
|
|
|
|
reachStart,
|
|
|
|
nearReachStart,
|
|
|
|
nearReachEnd,
|
|
|
|
reachEnd,
|
|
|
|
} = useScroll({
|
|
|
|
scrollableElement: scrollableRef.current,
|
|
|
|
distanceFromEnd: 3,
|
|
|
|
scrollThresholdStart: 44,
|
|
|
|
});
|
2023-01-02 16:36:24 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-16 15:32:30 +03:00
|
|
|
if (nearReachEnd || (reachEnd && showMore)) {
|
2023-01-02 16:36:24 +03:00
|
|
|
loadStatuses();
|
|
|
|
}
|
2023-01-16 15:32:30 +03:00
|
|
|
}, [nearReachEnd, reachEnd]);
|
2023-01-02 16:36:24 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-01-14 14:42:04 +03:00
|
|
|
if (reachStart) {
|
2023-02-03 16:08:08 +03:00
|
|
|
loadStatuses(true);
|
2023-01-02 16:36:24 +03:00
|
|
|
}
|
2023-01-14 14:42:04 +03:00
|
|
|
}, [reachStart]);
|
2023-01-02 16:36:24 +03:00
|
|
|
|
2023-01-13 10:30:09 +03:00
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const keys = await db.drafts.keys();
|
|
|
|
if (keys.length) {
|
|
|
|
const ns = getCurrentAccountNS();
|
|
|
|
const ownKeys = keys.filter((key) => key.startsWith(ns));
|
|
|
|
if (ownKeys.length) {
|
|
|
|
states.showDrafts = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
2023-01-27 06:47:30 +03:00
|
|
|
// const showUpdatesButton = snapStates.homeNew.length > 0 && reachStart;
|
|
|
|
const [showUpdatesButton, setShowUpdatesButton] = useState(false);
|
|
|
|
useEffect(() => {
|
|
|
|
const isNewAndTop = snapStates.homeNew.length > 0 && reachStart;
|
2023-02-06 18:47:58 +03:00
|
|
|
console.log(
|
|
|
|
'isNewAndTop',
|
|
|
|
isNewAndTop,
|
|
|
|
snapStates.homeNew.length,
|
|
|
|
reachStart,
|
|
|
|
);
|
2023-01-27 06:47:30 +03:00
|
|
|
setShowUpdatesButton(isNewAndTop);
|
2023-02-07 19:31:46 +03:00
|
|
|
}, [snapStates.homeNew.length, reachStart]);
|
2023-01-27 06:47:30 +03:00
|
|
|
|
2022-12-10 12:14:48 +03:00
|
|
|
return (
|
2023-01-20 19:23:59 +03:00
|
|
|
<>
|
|
|
|
<div
|
|
|
|
id="home-page"
|
|
|
|
class="deck-container"
|
|
|
|
hidden={hidden}
|
2023-02-06 18:47:58 +03:00
|
|
|
ref={(node) => {
|
|
|
|
scrollableRef.current = node;
|
|
|
|
jRef.current = node;
|
|
|
|
kRef.current = node;
|
|
|
|
oRef.current = node;
|
|
|
|
}}
|
2023-01-20 19:23:59 +03:00
|
|
|
tabIndex="-1"
|
2023-01-02 16:36:24 +03:00
|
|
|
>
|
2023-01-20 19:23:59 +03:00
|
|
|
<div class="timeline-deck deck">
|
|
|
|
<header
|
|
|
|
hidden={scrollDirection === 'end' && !nearReachStart}
|
|
|
|
onClick={() => {
|
|
|
|
scrollableRef.current?.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
|
}}
|
|
|
|
onDblClick={() => {
|
2023-02-03 16:08:08 +03:00
|
|
|
loadStatuses(true);
|
2023-01-20 19:23:59 +03:00
|
|
|
}}
|
|
|
|
>
|
2023-02-08 14:11:33 +03:00
|
|
|
<div class="header-grid">
|
|
|
|
<div class="header-side">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="plain"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
states.showSettings = true;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="gear" size="l" alt="Settings" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<h1>Home</h1>
|
|
|
|
<div class="header-side">
|
|
|
|
<Loader hidden={uiState !== 'loading'} />{' '}
|
|
|
|
<Link
|
|
|
|
to="/notifications"
|
|
|
|
class={`button plain ${
|
|
|
|
snapStates.notificationsNew.length > 0 ? 'has-badge' : ''
|
|
|
|
}`}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="notification" size="l" alt="Notifications" />
|
|
|
|
</Link>
|
|
|
|
</div>
|
2023-01-20 19:23:59 +03:00
|
|
|
</div>
|
2023-02-08 14:11:33 +03:00
|
|
|
{snapStates.homeNew.length > 0 &&
|
|
|
|
uiState !== 'loading' &&
|
|
|
|
((scrollDirection === 'start' &&
|
|
|
|
!nearReachStart &&
|
|
|
|
!nearReachEnd) ||
|
|
|
|
showUpdatesButton) && (
|
|
|
|
<button
|
|
|
|
class="updates-button"
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
if (!snapStates.settings.boostsCarousel) {
|
|
|
|
const uniqueHomeNew = snapStates.homeNew.filter(
|
|
|
|
(status) =>
|
|
|
|
!states.home.some((s) => s.id === status.id),
|
|
|
|
);
|
|
|
|
states.home.unshift(...uniqueHomeNew);
|
|
|
|
}
|
|
|
|
loadStatuses(true);
|
|
|
|
states.homeNew = [];
|
2023-01-01 14:24:08 +03:00
|
|
|
|
2023-02-08 14:11:33 +03:00
|
|
|
scrollableRef.current?.scrollTo({
|
|
|
|
top: 0,
|
|
|
|
behavior: 'smooth',
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="arrow-up" /> New posts
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</header>
|
2023-01-20 19:23:59 +03:00
|
|
|
{snapStates.home.length ? (
|
|
|
|
<>
|
|
|
|
<ul class="timeline">
|
|
|
|
{snapStates.home.map(({ id: statusID, reblog, boosts }) => {
|
|
|
|
const actualStatusID = reblog || statusID;
|
|
|
|
if (boosts) {
|
|
|
|
return (
|
|
|
|
<li key={statusID}>
|
|
|
|
<BoostsCarousel boosts={boosts} />
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
2023-01-14 14:42:04 +03:00
|
|
|
return (
|
|
|
|
<li key={statusID}>
|
2023-01-20 19:23:59 +03:00
|
|
|
<Link class="status-link" to={`/s/${actualStatusID}`}>
|
|
|
|
<Status statusID={statusID} />
|
|
|
|
</Link>
|
2023-01-14 14:42:04 +03:00
|
|
|
</li>
|
|
|
|
);
|
2023-01-20 19:23:59 +03:00
|
|
|
})}
|
2023-02-03 16:08:08 +03:00
|
|
|
{showMore && uiState === 'loading' && (
|
2023-01-20 19:23:59 +03:00
|
|
|
<>
|
|
|
|
<li
|
|
|
|
style={{
|
|
|
|
height: '20vh',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Status skeleton />
|
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
style={{
|
|
|
|
height: '25vh',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Status skeleton />
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</ul>
|
2023-02-03 16:08:08 +03:00
|
|
|
{uiState === 'default' &&
|
|
|
|
(showMore ? (
|
2023-01-20 19:23:59 +03:00
|
|
|
<button
|
|
|
|
type="button"
|
2023-02-03 16:08:08 +03:00
|
|
|
class="plain block"
|
|
|
|
onClick={() => loadStatuses()}
|
|
|
|
style={{ marginBlockEnd: '6em' }}
|
2022-12-10 12:14:48 +03:00
|
|
|
>
|
2023-02-03 16:08:08 +03:00
|
|
|
Show more…
|
2023-01-20 19:23:59 +03:00
|
|
|
</button>
|
2023-02-03 16:08:08 +03:00
|
|
|
) : (
|
|
|
|
<p class="ui-state insignificant">The end.</p>
|
|
|
|
))}
|
2023-01-20 19:23:59 +03:00
|
|
|
</>
|
2023-02-03 16:08:08 +03:00
|
|
|
) : uiState === 'loading' ? (
|
|
|
|
<ul class="timeline">
|
|
|
|
{Array.from({ length: 5 }).map((_, i) => (
|
|
|
|
<li key={i}>
|
|
|
|
<Status skeleton />
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
) : (
|
|
|
|
uiState !== 'error' && <p class="ui-state">Nothing to see here.</p>
|
|
|
|
)}
|
|
|
|
{uiState === 'error' && (
|
|
|
|
<p class="ui-state">
|
|
|
|
Unable to load statuses
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
loadStatuses(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Try again
|
|
|
|
</button>
|
|
|
|
</p>
|
2023-01-20 19:23:59 +03:00
|
|
|
)}
|
|
|
|
</div>
|
2022-12-10 12:14:48 +03:00
|
|
|
</div>
|
2023-01-20 19:23:59 +03:00
|
|
|
<button
|
|
|
|
hidden={scrollDirection === 'end' && !nearReachStart}
|
|
|
|
type="button"
|
|
|
|
id="compose-button"
|
|
|
|
onClick={(e) => {
|
|
|
|
if (e.shiftKey) {
|
|
|
|
const newWin = openCompose();
|
|
|
|
if (!newWin) {
|
|
|
|
alert('Looks like your browser is blocking popups.');
|
|
|
|
states.showCompose = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
states.showCompose = true;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="quill" size="xxl" alt="Compose" />
|
|
|
|
</button>
|
|
|
|
</>
|
2022-12-10 12:14:48 +03:00
|
|
|
);
|
2022-12-16 08:27:04 +03:00
|
|
|
}
|
|
|
|
|
2023-01-14 14:42:04 +03:00
|
|
|
function BoostsCarousel({ boosts }) {
|
|
|
|
const carouselRef = useRef();
|
2023-01-16 15:32:30 +03:00
|
|
|
const { reachStart, reachEnd, init } = useScroll({
|
2023-01-14 14:42:04 +03:00
|
|
|
scrollableElement: carouselRef.current,
|
|
|
|
direction: 'horizontal',
|
|
|
|
});
|
2023-01-16 15:32:30 +03:00
|
|
|
useEffect(() => {
|
|
|
|
init?.();
|
|
|
|
}, []);
|
|
|
|
|
2023-01-14 14:42:04 +03:00
|
|
|
return (
|
|
|
|
<div class="boost-carousel">
|
|
|
|
<header>
|
|
|
|
<h3>{boosts.length} Boosts</h3>
|
|
|
|
<span>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="small plain2"
|
|
|
|
disabled={reachStart}
|
|
|
|
onClick={() => {
|
|
|
|
carouselRef.current?.scrollBy({
|
|
|
|
left: -Math.min(320, carouselRef.current?.offsetWidth),
|
|
|
|
behavior: 'smooth',
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="chevron-left" />
|
|
|
|
</button>{' '}
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="small plain2"
|
|
|
|
disabled={reachEnd}
|
|
|
|
onClick={() => {
|
|
|
|
carouselRef.current?.scrollBy({
|
|
|
|
left: Math.min(320, carouselRef.current?.offsetWidth),
|
|
|
|
behavior: 'smooth',
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon icon="chevron-right" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</header>
|
|
|
|
<ul ref={carouselRef}>
|
|
|
|
{boosts.map((boost) => {
|
|
|
|
const { id: statusID, reblog } = boost;
|
|
|
|
const actualStatusID = reblog || statusID;
|
|
|
|
return (
|
2023-01-24 15:55:04 +03:00
|
|
|
<li key={statusID}>
|
2023-01-20 19:23:59 +03:00
|
|
|
<Link class="status-boost-link" to={`/s/${actualStatusID}`}>
|
2023-01-14 14:42:04 +03:00
|
|
|
<Status statusID={statusID} size="s" />
|
2023-01-20 19:23:59 +03:00
|
|
|
</Link>
|
2023-01-14 14:42:04 +03:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-07 09:45:04 +03:00
|
|
|
export default memo(Home);
|