From 7e79201f12daabd1bbb85cb68b7eab0f3943c867 Mon Sep 17 00:00:00 2001 From: tomholford Date: Thu, 17 Nov 2022 22:11:59 -0800 Subject: [PATCH 1/9] unreads: reuse getFirstUnread hook This hook was originally extracted from the Unread banner and then reused in the Scroller; now pulling it back in to the Banner --- ui/src/chat/ChatUnreadAlerts.tsx | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/ui/src/chat/ChatUnreadAlerts.tsx b/ui/src/chat/ChatUnreadAlerts.tsx index 9270b0339f..55df6ac1bd 100644 --- a/ui/src/chat/ChatUnreadAlerts.tsx +++ b/ui/src/chat/ChatUnreadAlerts.tsx @@ -1,11 +1,9 @@ import React, { useCallback } from 'react'; import { format, isToday } from 'date-fns'; import { useLocation, useNavigate } from 'react-router'; -import bigInt from 'big-integer'; import XIcon from '@/components/icons/XIcon'; -import { ChatBrief } from '@/types/chat'; import { pluralize } from '../logic/utils'; -import { useChatKeys, useChatState } from '../state/chat'; +import { useChatState, useGetFirstUnreadID } from '../state/chat'; import { useChatInfo } from './useChatStore'; interface ChatUnreadAlertsProps { @@ -21,23 +19,13 @@ export default function ChatUnreadAlerts({ whom }: ChatUnreadAlertsProps) { const navigate = useNavigate(); const location = useLocation(); // TODO: how to handle replies? - const chatKeys = useChatKeys({ replying: false }); - const goToFirstUnread = useCallback( - (b: ChatBrief) => { - const { 'read-id': lastRead } = b; - if (!lastRead) { - return; - } - // lastRead is formatted like: ~zod/123.456.789... - const lastReadBN = bigInt(lastRead.split('/')[1].replaceAll('.', '')); - const firstUnread = chatKeys.find((key) => key.gt(lastReadBN)); - if (!firstUnread) { - return; - } - navigate(`${location.pathname}?msg=${firstUnread.toString()}`); - }, - [chatKeys, location.pathname, navigate] - ); + const firstUnreadID = useGetFirstUnreadID(whom); + const goToFirstUnread = useCallback(() => { + if (!firstUnreadID) { + return; + } + navigate(`${location.pathname}?msg=${firstUnreadID.toString()}`); + }, [firstUnreadID, location.pathname, navigate]); if (!chatInfo.unread || chatInfo.unread.seen) { return null; @@ -62,7 +50,7 @@ export default function ChatUnreadAlerts({ whom }: ChatUnreadAlertsProps) {
`; From 98d153b42ef56dec853c059e96cc14be91f17ad2 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Fri, 18 Nov 2022 17:49:42 -0600 Subject: [PATCH 7/9] channel-sort: ripping out incorrect sort --- ui/src/logic/useChannelSort.ts | 52 ---------------------------------- 1 file changed, 52 deletions(-) diff --git a/ui/src/logic/useChannelSort.ts b/ui/src/logic/useChannelSort.ts index cdb207a863..fc76bcdd49 100644 --- a/ui/src/logic/useChannelSort.ts +++ b/ui/src/logic/useChannelSort.ts @@ -1,11 +1,6 @@ import { get } from 'lodash'; -import { useCallback } from 'react'; import { useGroup, useRouteGroup } from '@/state/groups'; import { GroupChannel, Channels, Zone } from '@/types/groups'; -import { useGetLatestChat } from '@/state/chat'; -import { ChatWhom } from '@/types/chat'; -import { useGetLatestNote } from '@/state/diary'; -import { useGetLatestCurio } from '@/state/heap/heap'; import useSidebarSort, { ALPHABETICAL, DEFAULT, @@ -14,56 +9,9 @@ import useSidebarSort, { Sorter, useRecentSort, } from './useSidebarSort'; -import { nestToFlag } from './utils'; const UNZONED = 'default'; -function useGetLatestPost() { - const getLatestChat = useGetLatestChat(); - const getLatestCurio = useGetLatestCurio(); - const getLatestNote = useGetLatestNote(); - - return (flag: string) => { - const [chType, _chFlag] = nestToFlag(flag); - - switch (chType) { - case 'chat': - return (getLatestChat(flag)[0] ?? Number.NEGATIVE_INFINITY).toString(); - - case 'diary': - return (getLatestNote(flag)[0] ?? Number.NEGATIVE_INFINITY).toString(); - - case 'heap': - return (getLatestCurio(flag)[0] ?? Number.NEGATIVE_INFINITY).toString(); - - default: - return Number.NEGATIVE_INFINITY.toString(); - } - }; -} - -function useRecentChannelSort() { - const getLatestPost = useGetLatestPost(); - - const sortRecent = useCallback( - (a: ChatWhom, b: ChatWhom) => { - const aLast = getLatestPost(a); - const bLast = getLatestPost(b); - - if (aLast < bLast) { - return -1; - } - if (aLast > bLast) { - return 1; - } - return 0; - }, - [getLatestPost] - ); - - return sortRecent; -} - export default function useChannelSort() { const groupFlag = useRouteGroup(); const group = useGroup(groupFlag); From ba1efcb8e52705ae4216423b63420c70073791ad Mon Sep 17 00:00:00 2001 From: tomholford Date: Sun, 20 Nov 2022 23:01:48 -0800 Subject: [PATCH 8/9] deps: upgrade react-virtuoso 2.19.0 --> 3.1.4 As luck would have it, an issue that I was struggling with on mobile has been fixed in a recent update: https://github.com/petyosi/react-virtuoso/issues/788 Went through the list of breaking changes and confirmed we are not affected. --- ui/package-lock.json | 22 +++++++++++----------- ui/package.json | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ui/package-lock.json b/ui/package-lock.json index 04073af045..a347b804e9 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -1,12 +1,12 @@ { - "name": "homestead", - "version": "0.0.0", + "name": "landscape-apps", + "version": "0.9.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "homestead", - "version": "0.0.0", + "name": "landscape-apps", + "version": "0.9.1", "hasInstallScript": true, "dependencies": { "@aws-sdk/client-s3": "^3.190.0", @@ -84,7 +84,7 @@ "react-router": "^6.3.0", "react-router-dom": "^6.3.0", "react-select": "^5.3.2", - "react-virtuoso": "^2.19.0", + "react-virtuoso": "^3.1.4", "refractor": "^4.8.0", "tailwindcss-scoped-groups": "^2.0.0", "tippy.js": "^6.3.7", @@ -23281,9 +23281,9 @@ } }, "node_modules/react-virtuoso": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-2.19.0.tgz", - "integrity": "sha512-GeCleV9cmpYGh1Ldfgdu+4gADLzdWJ48qc4tWguFzYz7FvUSAoELe8268rR8zfIb5FcV3tqpsdvFS5i51c8jyA==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-3.1.4.tgz", + "integrity": "sha512-oZt22JrSi/yLkp3HWa8teo0wqUg8zOA3i7y4dhHoM12njr5B8qGbVrq2fKGp3sbiZ9xiwX44KH5EEBo2GN2S4Q==", "dependencies": { "@virtuoso.dev/react-urx": "^0.2.12", "@virtuoso.dev/urx": "^0.2.12" @@ -46440,9 +46440,9 @@ } }, "react-virtuoso": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-2.19.0.tgz", - "integrity": "sha512-GeCleV9cmpYGh1Ldfgdu+4gADLzdWJ48qc4tWguFzYz7FvUSAoELe8268rR8zfIb5FcV3tqpsdvFS5i51c8jyA==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-3.1.4.tgz", + "integrity": "sha512-oZt22JrSi/yLkp3HWa8teo0wqUg8zOA3i7y4dhHoM12njr5B8qGbVrq2fKGp3sbiZ9xiwX44KH5EEBo2GN2S4Q==", "requires": { "@virtuoso.dev/react-urx": "^0.2.12", "@virtuoso.dev/urx": "^0.2.12" diff --git a/ui/package.json b/ui/package.json index 28f57d4368..432b081bbd 100644 --- a/ui/package.json +++ b/ui/package.json @@ -114,7 +114,7 @@ "react-router": "^6.3.0", "react-router-dom": "^6.3.0", "react-select": "^5.3.2", - "react-virtuoso": "^2.19.0", + "react-virtuoso": "^3.1.4", "refractor": "^4.8.0", "tailwindcss-scoped-groups": "^2.0.0", "tippy.js": "^6.3.7", From bb216ad030dae8e9aeaac6f7103725425318735d Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Mon, 21 Nov 2022 14:48:25 -0600 Subject: [PATCH 9/9] chat: changing back fetch size --- ui/src/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/constants.ts b/ui/src/constants.ts index 5f3563f8cb..9e566e73b2 100644 --- a/ui/src/constants.ts +++ b/ui/src/constants.ts @@ -1,7 +1,7 @@ // eslint-disable-next-line import/prefer-default-export export const INITIAL_MESSAGE_FETCH_PAGE_SIZE = 50; -export const STANDARD_MESSAGE_FETCH_PAGE_SIZE = 200; -export const LARGE_MESSAGE_FETCH_PAGE_SIZE = 400; +export const STANDARD_MESSAGE_FETCH_PAGE_SIZE = 100; +export const LARGE_MESSAGE_FETCH_PAGE_SIZE = 200; export const FETCH_BATCH_SIZE = 3; export const MAX_DISPLAYED_OPTIONS = 40;