diff --git a/src/app.jsx b/src/app.jsx index 391e2e45..00039913 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -36,6 +36,7 @@ import Home from './pages/home'; import List from './pages/list'; import Lists from './pages/lists'; import Login from './pages/login'; +import Mentions from './pages/mentions'; import Notifications from './pages/notifications'; import Public from './pages/public'; import Search from './pages/search'; @@ -223,6 +224,7 @@ function App() { {isLoggedIn && ( } /> )} + {isLoggedIn && } />} {isLoggedIn && } />} {isLoggedIn && } />} {isLoggedIn && } />} diff --git a/src/components/menu.jsx b/src/components/menu.jsx index 363e5219..ca69f463 100644 --- a/src/components/menu.jsx +++ b/src/components/menu.jsx @@ -103,6 +103,9 @@ function NavMenu(props) { Following )} + + Mentions + Notifications {snapStates.notificationsShowNew && ( diff --git a/src/components/shortcuts-settings.jsx b/src/components/shortcuts-settings.jsx index 15a1bf6d..ed9e189a 100644 --- a/src/components/shortcuts-settings.jsx +++ b/src/components/shortcuts-settings.jsx @@ -18,16 +18,17 @@ const SHORTCUTS_LIMIT = 9; const TYPES = [ 'following', + 'mentions', 'notifications', 'list', 'public', + 'trending', // NOTE: Hide for now // 'search', // Search on Mastodon ain't great // 'account-statuses', // Need @acct search first + 'hashtag', 'bookmarks', 'favourites', - 'hashtag', - 'trending', ]; const TYPE_TEXT = { following: 'Home / Following', @@ -40,6 +41,7 @@ const TYPE_TEXT = { favourites: 'Favourites', hashtag: 'Hashtag', trending: 'Trending', + mentions: 'Mentions', }; const TYPE_PARAMS = { list: [ @@ -101,6 +103,12 @@ export const SHORTCUTS_META = { path: '/', icon: 'home', }, + mentions: { + id: 'mentions', + title: 'Mentions', + path: '/mentions', + icon: 'at', + }, notifications: { id: 'notifications', title: 'Notifications', diff --git a/src/pages/mentions.jsx b/src/pages/mentions.jsx new file mode 100644 index 00000000..7bde5099 --- /dev/null +++ b/src/pages/mentions.jsx @@ -0,0 +1,76 @@ +import { useRef } from 'preact/hooks'; + +import Timeline from '../components/timeline'; +import { api } from '../utils/api'; +import { saveStatus } from '../utils/states'; +import useTitle from '../utils/useTitle'; + +const LIMIT = 20; + +function Mentions() { + useTitle('Mentions', '/mentions'); + const { masto, instance } = api(); + const mentionsIterator = useRef(); + const latestItem = useRef(); + + async function fetchMentions(firstLoad) { + if (firstLoad || !mentionsIterator.current) { + mentionsIterator.current = masto.v1.notifications.list({ + limit: LIMIT, + types: ['mention'], + }); + } + const results = await mentionsIterator.current.next(); + let { value } = results; + if (value?.length) { + if (firstLoad) { + latestItem.current = value[0].id; + console.log('First load', latestItem.current); + } + + value.forEach(({ status: item }) => { + saveStatus(item, instance); + }); + } + return { + ...results, + value: value.map((item) => item.status), + }; + } + + async function checkForUpdates() { + try { + const results = await masto.v1.notifications + .list({ + limit: 1, + types: ['mention'], + since_id: latestItem.current, + }) + .next(); + let { value } = results; + console.log('checkForUpdates', latestItem.current, value); + if (value?.length) { + latestItem.current = value[0].id; + return true; + } + return false; + } catch (e) { + return false; + } + } + + return ( + + ); +} + +export default Mentions; diff --git a/src/pages/notifications.jsx b/src/pages/notifications.jsx index ad82177a..7b4dda1c 100644 --- a/src/pages/notifications.jsx +++ b/src/pages/notifications.jsx @@ -167,7 +167,7 @@ function Notifications() {
- +

Notifications