Show trending hashtags
Very minimal UI for now
This commit is contained in:
parent
fe713edee9
commit
730fba7ad9
1 changed files with 36 additions and 1 deletions
|
@ -1,9 +1,10 @@
|
||||||
import { Menu, MenuItem } from '@szhsin/react-menu';
|
import { Menu, MenuItem } from '@szhsin/react-menu';
|
||||||
import { useRef } from 'preact/hooks';
|
import { useMemo, useRef, useState } from 'preact/hooks';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
|
||||||
import Icon from '../components/icon';
|
import Icon from '../components/icon';
|
||||||
|
import Link from '../components/link';
|
||||||
import Menu2 from '../components/menu2';
|
import Menu2 from '../components/menu2';
|
||||||
import Timeline from '../components/timeline';
|
import Timeline from '../components/timeline';
|
||||||
import { api } from '../utils/api';
|
import { api } from '../utils/api';
|
||||||
|
@ -25,12 +26,23 @@ function Trending(props) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const latestItem = useRef();
|
const latestItem = useRef();
|
||||||
|
|
||||||
|
const [hashtags, setHashtags] = useState([]);
|
||||||
const trendIterator = useRef();
|
const trendIterator = useRef();
|
||||||
async function fetchTrend(firstLoad) {
|
async function fetchTrend(firstLoad) {
|
||||||
if (firstLoad || !trendIterator.current) {
|
if (firstLoad || !trendIterator.current) {
|
||||||
trendIterator.current = masto.v1.trends.listStatuses({
|
trendIterator.current = masto.v1.trends.listStatuses({
|
||||||
limit: LIMIT,
|
limit: LIMIT,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get hashtags
|
||||||
|
try {
|
||||||
|
const iterator = masto.v1.trends.listTags();
|
||||||
|
const { value: tags } = await iterator.next();
|
||||||
|
console.log(tags);
|
||||||
|
setHashtags(tags);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const results = await trendIterator.current.next();
|
const results = await trendIterator.current.next();
|
||||||
let { value } = results;
|
let { value } = results;
|
||||||
|
@ -71,6 +83,28 @@ function Trending(props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TimelineStart = useMemo(() => {
|
||||||
|
if (!hashtags.length) return null;
|
||||||
|
return (
|
||||||
|
<div class="filter-bar">
|
||||||
|
<Icon icon="chart" class="insignificant" size="l" />
|
||||||
|
{hashtags.map((tag, i) => {
|
||||||
|
const { name, history } = tag;
|
||||||
|
const total = history.reduce((acc, cur) => acc + +cur.uses, 0);
|
||||||
|
return (
|
||||||
|
<Link to={`/${instance}/t/${name}`}>
|
||||||
|
<span>
|
||||||
|
<span class="more-insignificant">#</span>
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
<span class="filter-count">{total.toLocaleString()}</span>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}, [hashtags]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Timeline
|
<Timeline
|
||||||
key={instance}
|
key={instance}
|
||||||
|
@ -92,6 +126,7 @@ function Trending(props) {
|
||||||
headerStart={<></>}
|
headerStart={<></>}
|
||||||
boostsCarousel={snapStates.settings.boostsCarousel}
|
boostsCarousel={snapStates.settings.boostsCarousel}
|
||||||
allowFilters
|
allowFilters
|
||||||
|
timelineStart={TimelineStart}
|
||||||
headerEnd={
|
headerEnd={
|
||||||
<Menu2
|
<Menu2
|
||||||
portal
|
portal
|
||||||
|
|
Loading…
Add table
Reference in a new issue