Skip to content

Commit

Permalink
Fix smooth scrolling + add scroll on reply click
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Apr 4, 2023
1 parent 0638708 commit decda33
Show file tree
Hide file tree
Showing 46 changed files with 351 additions and 4,460 deletions.
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"react-hotkeys-hook": "^3.4.7",
"react-spaces": "^0.3.2",
"react-spinners": "^0.13.4",
"react-virtuoso": "^4.2.0",
"socket.io-client": "^4.5.4",
"styled-components": "^5.3.3",
"styled-system": "^5.1.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMemo } from 'react';
import { Virtuoso } from 'react-virtuoso';
import { Flex, Text } from 'renderer/components';
import { Notification } from './Notification';
import { useTrayApps } from 'renderer/apps/store';
import { WindowedList } from '@holium/design-system';
import { NotificationModelType } from 'os/services/spaces/models/beacon';
import { observer } from 'mobx-react';

Expand Down Expand Up @@ -42,10 +42,12 @@ const NotificationListPresenter = ({ unseen, seen }: INotificationList) => {
flexDirection="column"
height={dimensions.height}
>
<WindowedList
width={370}
<Virtuoso
style={{
width: 370,
}}
data={listData}
rowRenderer={(item, index) => {
itemContent={(index, item) => {
if (item.type === 'title') {
const title = item.data as string;
return (
Expand Down
10 changes: 6 additions & 4 deletions app/src/renderer/apps/Account/components/NotificationList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMemo } from 'react';
import { Virtuoso } from 'react-virtuoso';
import { Flex, Text } from 'renderer/components';
import { Notification } from './Notification';
import { useTrayApps } from 'renderer/apps/store';
import { WindowedList } from '@holium/design-system';
import { NotificationModelType } from 'os/services/spaces/models/beacon';
import { observer } from 'mobx-react';

Expand Down Expand Up @@ -42,10 +42,12 @@ const NotificationListPresenter = ({ unseen, seen }: INotificationList) => {
flexDirection="column"
height={dimensions.height}
>
<WindowedList
width={370}
<Virtuoso
style={{
width: 370,
}}
data={listData}
rowRenderer={(item, index) => {
itemContent={(index, item) => {
if (item.type === 'title') {
const title = item.data as string;
return (
Expand Down
8 changes: 4 additions & 4 deletions app/src/renderer/apps/Courier/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ChatMessageProps = {
ourColor: string;
isPrevGrouped: boolean;
isNextGrouped: boolean;
measure: () => void;
onReplyClick?: (msgId: string) => void;
};

export const ChatMessagePresenter = ({
Expand All @@ -26,7 +26,7 @@ export const ChatMessagePresenter = ({
ourColor,
isPrevGrouped,
isNextGrouped,
measure,
onReplyClick,
}: ChatMessageProps) => {
const { ship, friends, theme } = useServices();
const { selectedChat } = useChatStore();
Expand Down Expand Up @@ -195,7 +195,7 @@ export const ChatMessagePresenter = ({

return (
<Bubble
ref={messageRef}
innerRef={messageRef}
id={messageRowId}
isPrevGrouped={isPrevGrouped}
isNextGrouped={isNextGrouped}
Expand All @@ -213,9 +213,9 @@ export const ChatMessagePresenter = ({
authorColor={authorColor}
message={mergedContents}
sentAt={sentAt}
onMeasure={measure}
reactions={reactionList}
onReaction={canReact ? onReaction : undefined}
onReplyClick={onReplyClick}
/>
);
};
Expand Down
36 changes: 26 additions & 10 deletions app/src/renderer/apps/Courier/views/ChatLog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useMemo, useEffect, useState } from 'react';
import { useMemo, useEffect, useState, useRef } from 'react';
import { observer } from 'mobx-react';
import styled from 'styled-components';
import { AnimatePresence } from 'framer-motion';
import { Virtuoso } from 'react-virtuoso';
import {
Box,
Flex,
WindowedList,
Text,
Reply,
measureImage,
Expand Down Expand Up @@ -42,6 +42,7 @@ export const ChatLogPresenter = ({ storage }: ChatLogProps) => {
const accountStore = useAccountStore();
const { ship, friends } = useServices();
const [showAttachments, setShowAttachments] = useState(false);
const listRef = useRef<any>(null);

const { color: ourColor } = useMemo(() => {
if (!ship) return { color: '#000' };
Expand Down Expand Up @@ -198,14 +199,16 @@ export const ChatLogPresenter = ({ storage }: ChatLogProps) => {
/>
</FullWidthAnimatePresence>
)}
<WindowedList
key={`${path}-${selectedChat.lastFetch}-${messages.length}`}
startAtBottom
hideScrollbar
width={containerWidth}
height={height}
<Virtuoso
ref={listRef}
style={{
height,
width: containerWidth,
}}
data={messages}
rowRenderer={(row, index, measure) => {
initialTopMostItemIndex={messages.length - 1}
followOutput="auto"
itemContent={(index, row) => {
const isLast = selectedChat
? index === messages.length - 1
: false;
Expand Down Expand Up @@ -253,7 +256,20 @@ export const ChatLogPresenter = ({ storage }: ChatLogProps) => {
containerWidth={containerWidth}
message={row as ChatMessageType}
ourColor={ourColor}
measure={measure}
onReplyClick={(replyId) => {
const replyIndex = messages.findIndex(
(msg) => msg.id === replyId
);
if (replyIndex === -1) return;

console.log('reply index', replyIndex);

listRef.current?.scrollToIndex({
index: replyIndex,
align: 'start',
behavior: 'smooth',
});
}}
/>
</Box>
);
Expand Down
16 changes: 8 additions & 8 deletions app/src/renderer/apps/Messages/DMs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useState } from 'react';
import { observer } from 'mobx-react';
import { Virtuoso } from 'react-virtuoso';
import {
Icon,
Text,
Expand All @@ -9,7 +10,6 @@ import {
TextInput,
Skeleton,
Spinner,
WindowedList,
} from '@holium/design-system';
import { ContactRow } from './components/ContactRow';
import { ThemeModelType } from 'os/services/theme.model';
Expand Down Expand Up @@ -107,14 +107,14 @@ const DMsPresenter = (props: IProps) => {
}

return (
<WindowedList
<Virtuoso
key={lastTimeSent}
width={364}
height={544}
rowHeight={57}
data={previews}
filter={searchFilter}
rowRenderer={(dm, index) => (
style={{
width: 364,
height: 544,
}}
data={previews.filter(searchFilter)}
itemContent={(index, dm) => (
<Box
display="block"
key={`dm-${index}-${dm.lastTimeSent}-${dm.pending}`}
Expand Down
14 changes: 8 additions & 6 deletions app/src/renderer/apps/Messages/components/ChatLogView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import { Flex, WindowedList } from '@holium/design-system';
import { Virtuoso } from 'react-virtuoso';
import { Flex } from '@holium/design-system';
import { ShipModelType } from 'os/services/ship/models/ship';
import { GraphDMType } from 'os/services/ship/models/courier';
import { ThemeModelType } from 'os/services/theme.model';
Expand Down Expand Up @@ -31,10 +32,13 @@ export const ChatLogView = ({
flexDirection="column-reverse"
pb={44}
>
<WindowedList
width={364}
<Virtuoso
style={{
width: 364,
}}
data={messages}
rowRenderer={(message, index, measure) => (
initialTopMostItemIndex={messages.length - 1}
itemContent={(index, message) => (
<ChatMessage
isSending={message.pending}
// Only show author if it's a group
Expand All @@ -56,10 +60,8 @@ export const ChatLogView = ({
ourColor={ship.color || '#569BE2'}
contents={message.contents}
timeSent={message.timeSent}
onImageLoad={measure}
/>
)}
startAtBottom
/>
</Flex>
),
Expand Down
4 changes: 0 additions & 4 deletions app/src/renderer/apps/Messages/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface IProps {
ourColor: string;
contents: GraphDMType['contents'];
timeSent: number;
onImageLoad?: () => void;
}

export const ChatMessage = ({
Expand All @@ -29,7 +28,6 @@ export const ChatMessage = ({
isSending,
primaryBubble,
timeSent,
onImageLoad,
}: IProps) => {
const messageTypes = useMemo(
() =>
Expand Down Expand Up @@ -111,7 +109,6 @@ export const ChatMessage = ({
textColor={theme.textColor}
bgColor={referenceColor}
content={content}
onImageLoad={onImageLoad}
/>
);
})}
Expand All @@ -135,7 +132,6 @@ export const ChatMessage = ({
contents,
isMention,
isSending,
onImageLoad,
ourColor,
primaryBubble,
referenceColor,
Expand Down
14 changes: 7 additions & 7 deletions app/src/renderer/apps/Rooms/Room/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useRef, useMemo, useCallback } from 'react';
import { Flex, Text, Input, IconButton, Icons } from 'renderer/components';
import { createField, createForm } from 'mobx-easy-form';
import { observer } from 'mobx-react';
import { Virtuoso } from 'react-virtuoso';
import { useTrayApps } from 'renderer/apps/store';
import { useServices } from 'renderer/logic/store';
import { WindowedList } from '@holium/design-system';
import { RoomChatMessage } from './RoomChatMessage';
import { useRooms } from '../useRooms';

Expand Down Expand Up @@ -75,12 +75,13 @@ const RoomChatPresenter = () => {
}

return (
<WindowedList
width={354}
<Virtuoso
style={{
width: 354,
}}
height={listHeight}
data={chats}
sort={(a, b) => a.timeReceived - b.timeReceived}
rowRenderer={(chat, index) => (
data={chats.sort((a, b) => a.timeReceived - b.timeReceived)}
itemContent={(index, chat) => (
<RoomChatMessage
key={chat.index}
chat={chat}
Expand All @@ -93,7 +94,6 @@ const RoomChatPresenter = () => {
}
/>
)}
startAtBottom
/>
);
}, [chats]);
Expand Down
12 changes: 8 additions & 4 deletions app/src/renderer/apps/Spaces/FeaturedList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useState } from 'react';
import { observer } from 'mobx-react';
import { Virtuoso } from 'react-virtuoso';
import { Text, TextButton } from 'renderer/components';
import { Row } from 'renderer/components/NewRow';
import { useServices } from 'renderer/logic/store';
import { Flex, Spinner, WindowedList } from '@holium/design-system';
import { Flex, Spinner } from '@holium/design-system';
import { EmptyGroup } from './SpaceRow';
import { SpacesActions } from 'renderer/logic/actions/spaces';

Expand Down Expand Up @@ -35,11 +36,13 @@ const FeaturedListPresenter = () => {
}
return (
<Flex flex={1} width="100%">
<WindowedList
<Virtuoso
key={`featured-spaces-${listData.length}`}
width={354}
style={{
width: 354,
}}
data={listData}
rowRenderer={(data: any) => {
itemContent={(_, data) => {
const onJoin = async () => {
setJoining(true);
SpacesActions.joinSpace(data.path.substring(1))
Expand Down Expand Up @@ -75,6 +78,7 @@ const FeaturedListPresenter = () => {
height="32px"
width="32px"
src={data.picture}
alt={data.name}
/>
) : (
<EmptyGroup color={data.color || '#000000'} />
Expand Down
12 changes: 6 additions & 6 deletions app/src/renderer/apps/Spaces/SpacesList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useMemo } from 'react';
import { observer } from 'mobx-react';
import { Virtuoso } from 'react-virtuoso';
import { SpaceModelType } from 'os/services/spaces/models/spaces';

import { Flex, Text, ActionButton, Icons } from 'renderer/components';
import { SpaceRow } from './SpaceRow';
import { ShellActions } from 'renderer/logic/actions/shell';
import { useServices } from 'renderer/logic/store';
import { VisaRow } from './components/VisaRow';
import { rgba } from 'polished';
import { WindowedList } from '@holium/design-system';

export interface Space {
color?: string;
Expand Down Expand Up @@ -107,12 +106,13 @@ const SpacesListPresenter = ({

return (
<Flex flex={1} width="100%">
<WindowedList
rowHeight={56}
<Virtuoso
key={`${spaces.length}-${incoming.length}`}
width={354}
style={{
width: 354,
}}
data={rows}
rowRenderer={({ space, visa }) => {
itemContent={(_, { space, visa }) => {
if (space) {
return (
<SpaceRow
Expand Down
Loading

0 comments on commit decda33

Please sign in to comment.