Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed bugs #566

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useContext } from 'react';
import React, { useEffect, useState, useContext, useRef } from 'react';
import styled from 'styled-components';

import { MinimisedModalHeader } from './MinimisedModalHeader';
Expand Down Expand Up @@ -45,9 +45,11 @@ export const ChatAndNotification = () => {
requestsFeed,
chatsFeed,
selectedChatId,
setFinishedFetchingChats,
setFinishedFetchingRequests,
setChats
} = useContext<ChatMainStateContextType>(ChatMainStateContext);
const { setInboxNotifsFeed, setSpamNotifsFeed } = useContext<any>(
const { setInboxNotifsFeed, setSpamNotifsFeed,setFinishedFetchingInbox,setFinishedFetchingSpam } = useContext<any>(
NotificationMainStateContext
);
const {
Expand All @@ -63,6 +65,7 @@ export const ChatAndNotification = () => {
const { fetchRequests } = useFetchRequests();
const { fetchChats } = useFetchChats();
const { fetchChat } = useFetchChat();
const modalRef = useRef<HTMLDivElement>(null);
const { fetchUserSubscriptions } = useFetchUserSubscriptions();
useChatNotificationSocket({});

Expand All @@ -73,6 +76,10 @@ export const ChatAndNotification = () => {
setRequestsFeed({});
setInboxNotifsFeed({});
setSpamNotifsFeed({});
setFinishedFetchingInbox(false);
setFinishedFetchingSpam(false);
setFinishedFetchingChats(false);
setFinishedFetchingRequests(false);
// set active tab if present
if (activeChosenTab) {
setActiveTab(activeChosenTab);
Expand Down Expand Up @@ -182,12 +189,30 @@ export const ChatAndNotification = () => {
setModalOpen(!modalOpen);
};

const toggleOverflow = (val: string) => {
if (typeof window != 'undefined' && window.document) {
document.body.style.overflowY = val;
}
};


useEffect(() => {
const modalElement = modalRef.current;
if (!modalElement) return;

const handleScroll = (event: WheelEvent) => {
const { scrollTop, scrollHeight, clientHeight } = modalElement;
const isScrolledToBottom = scrollTop + clientHeight >= scrollHeight;

// If scrolled to the bottom of the modal, prevent further scrolling
if (isScrolledToBottom && event.deltaY > 0) {
// event.preventDefault();
event.stopPropagation();
}
};

modalElement.addEventListener('wheel', handleScroll);

// Cleanup the event listener when the component unmounts
return () => {
modalElement.removeEventListener('wheel', handleScroll);
};
}, []);


return (
Expand All @@ -199,7 +224,9 @@ export const ChatAndNotification = () => {
background="#fff"
right="12px"
bottom="18px"
className='modal'
overflow="hidden"
ref={modalRef}

// onMouseEnter={() => toggleOverflow('hidden')}
// onMouseLeave={() => toggleOverflow('auto')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SidebarPlaceholder } from '../SidebarPlaceholder';
import type { ChatMainStateContextType } from '../../../../../context/chatAndNotification/chat/chatMainStateContext';

export const ChatsFeedList = () => {
const { chatsFeed, setChatsFeed } =
const { chatsFeed, setChatsFeed,finishedFetchingChats,setFinishedFetchingChats } =
useContext<ChatMainStateContextType>(ChatMainStateContext);
const pageRef = useRef<HTMLDivElement>(null);
const [page, setPage] = useState<number>(1);
Expand Down Expand Up @@ -46,7 +46,7 @@ export const ChatsFeedList = () => {
useEffect(() => {
if (
!isInViewport1 ||
loading
loading || finishedFetchingChats
// ||
// Object.keys(chatsFeed).length < chatLimit
) {
Expand All @@ -66,6 +66,7 @@ export const ChatsFeedList = () => {
try {
setPaginateLoading(true);
const feeds = await fetchChats({ page, chatLimit });
if(!Object.keys(feeds || {}).length) setFinishedFetchingChats(true);
const newFeed: ChatFeedsType = { ...chatsFeed, ...feeds };
setChatsFeed(newFeed);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useIsInViewport } from '../../../../../hooks';
import type { ChatMainStateContextType } from '../../../../../context/chatAndNotification/chat/chatMainStateContext';

export const RequestsFeedList = () => {
const { requestsFeed, setRequestsFeed } = useContext<ChatMainStateContextType>(ChatMainStateContext);
const { requestsFeed, setRequestsFeed,finishedFetchingRequests,setFinishedFetchingRequests } = useContext<ChatMainStateContextType>(ChatMainStateContext);
const pageRef = useRef<HTMLDivElement>(null);
const [page, setPage] = useState<number>(1);
const [paginateLoading, setPaginateLoading] = useState<boolean>(false);
Expand All @@ -38,7 +38,7 @@ export const RequestsFeedList = () => {
useEffect(() => {
if (
!isInViewport1 ||
loading
loading || finishedFetchingRequests
// ||
// Object.keys(requestsFeed).length < requestLimit
) {
Expand All @@ -58,6 +58,7 @@ export const RequestsFeedList = () => {
try {
setPaginateLoading(true);
const feeds = await fetchRequests({ page, requestLimit });
if(!Object.keys(feeds || {}).length) setFinishedFetchingRequests(true);
const newFeed: ChatFeedsType = { ...requestsFeed, ...feeds };
setRequestsFeed(newFeed);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const InboxNotificationFeedList = () => {
setAllInboxNotifsFeed,
setSpamNotifsFeed,
spamNotifsFeed,
finishedFetchingInbox,
setFinishedFetchingInbox,
} = useContext<any>(NotificationMainStateContext);
const pageRef = useRef<HTMLDivElement>(null);
const { account, env } = useContext<any>(ChatAndNotificationPropsContext);
Expand Down Expand Up @@ -93,7 +95,7 @@ export const InboxNotificationFeedList = () => {

if (
!isInViewport1 ||
loading
loading || finishedFetchingInbox
||
Object.keys(inboxNotifsFeed).length < notificationLimit
) {
Expand All @@ -112,7 +114,8 @@ export const InboxNotificationFeedList = () => {
}
try {
setPaginateLoading(true);
const feeds = await fetchNotification({ page, limit: notificationLimit });
const feeds = await fetchNotification({ page, limit: notificationLimit });
if(!Object.keys(feeds || {}).length) setFinishedFetchingInbox(true);
const newFeed:NotificationFeedsType = {...inboxNotifsFeed,...feeds};

setInboxNotifsFeed(newFeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { NotificationFeedsType } from '../../../../../types';
import useFetchNotification from '../../../../../hooks/notifications/useFetchNotification';

export const SpamNotificationFeedList = () => {
const { spamNotifsFeed, setSpamNotifsFeed } = useContext<any>(
const { spamNotifsFeed, setSpamNotifsFeed,finishedFetchingSpam,setFinishedFetchingSpam } = useContext<any>(
NotificationMainStateContext
);
const pageRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -48,7 +48,7 @@ export const SpamNotificationFeedList = () => {
useEffect(() => {
if (
!isInViewport1 ||
loading ||
loading || finishedFetchingSpam||
Object.keys(spamNotifsFeed).length < notificationLimit
) {
return;
Expand All @@ -72,6 +72,7 @@ export const SpamNotificationFeedList = () => {
limit: notificationLimit,
spam: true,
});
if(!Object.keys(feeds || {}).length) setFinishedFetchingSpam(true);
const newFeed: NotificationFeedsType = { ...spamNotifsFeed, ...feeds };


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export type ChatMainStateContextType = {
setConnectedProfile: (connectedProfile: IUser) => void;
searchedChats: ChatFeedsType | null;
setSearchedChats: (chats:ChatFeedsType | null) => void;
finishedFetchingChats:boolean;
finishedFetchingRequests:boolean;
setFinishedFetchingChats: (flag: boolean) => void;
setFinishedFetchingRequests: (flag: boolean) => void;
}

export const ChatMainStateContext = createContext<ChatMainStateContextType>({} as ChatMainStateContextType);
Expand All @@ -38,6 +42,9 @@ const [requestsFeed,setRequestsFeed] =useState<ChatFeedsType>({} as ChatFeedsTyp
const [chats,setChats] = useState<Map<string, ChatMessagetype> >(new Map());
const [selectedChatId,setSelectedChatId] = useState<string|null>(null);
const [searchedChats,setSearchedChats] = useState<ChatFeedsType | null>(null);
const [finishedFetchingChats,setFinishedFetchingChats] = useState<boolean>(false);
const [finishedFetchingRequests,setFinishedFetchingRequests] = useState<boolean>(false);




Expand Down Expand Up @@ -92,6 +99,10 @@ const [searchedChats,setSearchedChats] = useState<ChatFeedsType | null>(null);
web3NameList,
setWeb3NameList,
setWeb3Name,
finishedFetchingChats,
finishedFetchingRequests,
setFinishedFetchingChats,
setFinishedFetchingRequests
}}>

{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export type NotificationMainStateContextType = {
subscriptionStatus: Map<string, boolean>;
setSubscriptionStatus: (subscriptionStatus: Map<string, boolean>) => void;
setChannelSubscriptionStatus: (id: string, status: boolean) => void;
finishedFetchingInbox:boolean;
finishedFetchingSpam:boolean;
setFinishedFetchingInbox: (flag: boolean) => void;
setFinishedFetchingSpam: (flag: boolean) => void;
};

export const NotificationMainStateContext =
Expand All @@ -47,6 +51,8 @@ const NotificationMainStateContextProvider = ({
const [subscriptionStatus, setSubscriptionStatus] = useState<Map<string, boolean>>(new Map());
const [searchedNotifications, setSearchedNotifications] =
useState<NotificationFeedsType | null>(null);
const [finishedFetchingInbox,setFinishedFetchingInbox] = useState<boolean>(false);
const [finishedFetchingSpam,setFinishedFetchingSpam] = useState<boolean>(false);

const setInboxNotifFeed = (
id: string,
Expand Down Expand Up @@ -89,6 +95,10 @@ const NotificationMainStateContextProvider = ({
subscriptionStatus,
setChannelSubscriptionStatus,
setSubscriptionStatus,
finishedFetchingInbox,
finishedFetchingSpam,
setFinishedFetchingInbox,
setFinishedFetchingSpam
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const useChatNotificationSocket = ({
}
let chainId = 1;
(async () => {
chainId = await signer.getChainId();
chainId = await signer?.getChainId();
})();
// this is auto-connect on instantiation
const connectionObject = createSocketConnection({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const useFetchUserSubscriptions = () => {
const fetchUserSubscriptions = useCallback(async () => {
setLoading(true);
try {
const chainId = await signer.getChainId();
const chainId = await signer?.getChainId();
const results = await PushAPI.user.getSubscriptions({
user: convertAddressToAddrCaip(account, chainId), // user address in CAIP
env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useOnSubscribeToChannel = () => {

if (!address) return;
console.log(signer)
const chainId = await signer.getChainId();
const chainId = await signer?.getChainId();

await PushAPI.channels.subscribe({
signer: signer,
Expand Down
Loading