Skip to content

Commit

Permalink
Resolved a saga error which was calling out to /mine when a user was …
Browse files Browse the repository at this point in the history
…not authenticated
  • Loading branch information
AdamDotCom committed Mar 20, 2023
1 parent feba0be commit 4bd41c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/platform-apps/channels/container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ describe('ChannelsContainer', () => {
user: {
data: null,
},
context: {
isAuthenticated: true,
},
...props,
};

Expand All @@ -55,7 +58,7 @@ describe('ChannelsContainer', () => {
expect(fetchChannels).toHaveBeenCalledWith(domainId);
});

it('set receiveUnreadCount channels on mount', () => {
it('set receiveUnreadCount channels on mount when authenticated', () => {
const domainId = '0x000000000000000000000000000000000000000A';
const fetchChannels = jest.fn();
const receiveUnreadCount = jest.fn();
Expand All @@ -65,6 +68,15 @@ describe('ChannelsContainer', () => {
expect(receiveUnreadCount).toHaveBeenCalledWith(domainId);
});

it('do not set receiveUnreadCount channels on mount when anonymous', () => {
const fetchChannels = jest.fn();
const receiveUnreadCount = jest.fn();

subject({ fetchChannels, receiveUnreadCount, context: { isAuthenticated: false } });

expect(receiveUnreadCount).not.toHaveBeenCalledWith();
});

it('wraps ChannelList in AppContextPanel', () => {
const wrapper = subject();

Expand Down
32 changes: 26 additions & 6 deletions src/platform-apps/channels/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { AppLayout, AppContextPanel, AppContent } from '@zer0-os/zos-component-l
import './styles.scss';
import { AuthenticationState } from '../../store/authentication/types';
import { ChatViewContainer } from '../../components/chat-view-container/chat-view-container';
import { withContext as withAuthenticationContext } from '../../components/authentication/context';

interface PublicProperties {
store: Store<RootState>;
Expand All @@ -33,6 +34,9 @@ export interface Properties extends PublicProperties {
receiveUnreadCount: (domainId: string) => void;
stopSyncChannels: () => void;
user: AuthenticationState['user'];
context: {
isAuthenticated: boolean;
};
}

export class Container extends React.Component<Properties> {
Expand All @@ -59,14 +63,30 @@ export class Container extends React.Component<Properties> {
}

componentDidMount() {
this.props.fetchChannels(this.props.domainId);
this.props.receiveUnreadCount(this.props.domainId);
const {
context: { isAuthenticated },
domainId,
} = this.props;

this.props.fetchChannels(domainId);

if (isAuthenticated) {
this.props.receiveUnreadCount(domainId);
}
}

componentDidUpdate(prevProps: Properties) {
if (prevProps.user.data !== this.props.user.data) {
this.props.fetchChannels(this.props.domainId);
this.props.receiveUnreadCount(this.props.domainId);
const {
context: { isAuthenticated },
user,
domainId,
} = this.props;

if (isAuthenticated) {
if (prevProps.user.data !== user.data) {
this.props.fetchChannels(domainId);
this.props.receiveUnreadCount(domainId);
}
}
}

Expand Down Expand Up @@ -104,4 +124,4 @@ export class Container extends React.Component<Properties> {
}
}

export const ChannelsContainer = connectContainer<PublicProperties>(Container);
export const ChannelsContainer = withAuthenticationContext<{}>(connectContainer<PublicProperties>(Container));

0 comments on commit 4bd41c8

Please sign in to comment.