Skip to content

Commit 21884b6

Browse files
author
Dara Hayes
committed
fix: minor fixes
1 parent 96da6dd commit 21884b6

File tree

7 files changed

+20
-5
lines changed

7 files changed

+20
-5
lines changed

client/src/App.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ import { withAuth } from './services/auth.service';
1414
import { ApolloOfflineClient } from 'offix-client';
1515
import { ApolloProvider } from 'react-apollo-hooks'
1616
import { useOffixClient } from 'react-offix-hooks';
17-
import { useCacheService } from './services/cache.service'
1817

1918
const Router: React.FC = () => {
20-
console.log('renderApp')
21-
useCacheService()
2219
return (
2320
<BrowserRouter>
2421
<AnimatedSwitch>

client/src/components/ChatRoomScreen/MessagesList.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useRef } from 'react';
44
import styled, { css } from 'styled-components';
55
import { useInfiniteScroll } from '../../hooks/use-infinite-scroll';
66
import { useAdjustedScroll } from '../../hooks/use-adjusted-scroll';
7+
import { useUseMessageAddedSubscription } from '../../services/cache.service';
78

89
const Container = styled.div`
910
position: relative;
@@ -109,6 +110,8 @@ const MessagesList: React.FC<MessagesListProps> = ({
109110
});
110111
const adjustScroll = useAdjustedScroll(selfRef);
111112

113+
useUseMessageAddedSubscription()
114+
112115
useEffect(() => {
113116
if (!selfRef.current) return;
114117

client/src/components/ChatRoomScreen/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const ChatRoom: React.FC<ChatRoomScreenParams> = ({ history, chatId }) => {
112112
const { after, limit, setAfter } = usePagination();
113113
const { data, loading, fetchMore } = useGetChatQuery({
114114
variables: { chatId, after, limit },
115+
fetchPolicy: 'cache-and-network'
115116
});
116117

117118
const [addMessage] = useOfflineMutation(addMessageMutation);

client/src/components/ChatsListScreen/ChatsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const ChatsList: React.FC<ChatsListProps> = ({ history }) => {
9393
);
9494
const prefetchChat = useGetChatPrefetch();
9595

96-
const { data } = useChatsQuery();
96+
const { data } = useChatsQuery({ fetchPolicy: 'cache-and-network' });
9797

9898
if (data === undefined || data.chats === undefined) {
9999
return null;

client/src/components/UsersList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface ChildComponentProps {
5555
}
5656

5757
const UsersList: React.FC<ChildComponentProps> = ({ dispatch, selectedUsers }) => {
58-
const { data, loading: loadingUsers } = useUsersListQuery();
58+
const { data, loading: loadingUsers } = useUsersListQuery({ fetchPolicy: 'cache-and-network' });
5959

6060
if (data === undefined) return null;
6161
const users = data.users;

client/src/services/auth.service.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useContext, useCallback } from 'react';
33
import { useApolloClient } from 'react-apollo-hooks';
44
import { Redirect } from 'react-router-dom';
55
import { useMeQuery, User, useSignInMutation, useSignUpMutation } from '../graphql/types';
6+
import { useCacheService } from '../services/cache.service';
67

78
const MyContext = React.createContext<User | null>(null);
89

@@ -25,6 +26,8 @@ export const withAuth = <P extends object>(
2526
const signOut = useSignOut();
2627
const { data, error, loading } = useMeQuery();
2728

29+
useCacheService();
30+
2831
if (loading) return null;
2932

3033
if (data === undefined) return null;

client/src/services/cache.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ import {
1313

1414
type Client = ApolloClient<any> | DataProxy;
1515

16+
export const useUseMessageAddedSubscription = () => {
17+
useMessageAddedSubscription({
18+
onSubscriptionData: ({ client, subscriptionData: { data } }) => {
19+
if (data) {
20+
writeMessage(client, data.messageAdded);
21+
}
22+
},
23+
});
24+
}
25+
1626
export const useCacheService = () => {
27+
1728
useMessageAddedSubscription({
1829
onSubscriptionData: ({ client, subscriptionData: { data } }) => {
1930
if (data) {

0 commit comments

Comments
 (0)