Skip to content

Commit

Permalink
[MM-58563] Load profiles on sidebar load irrespective of the current …
Browse files Browse the repository at this point in the history
…channel (mattermost#27992)

* [MM-58563] Load profiles on sidebar load irrespective of the current channel

* Remove await

---------

Co-authored-by: Mattermost Build <[email protected]>
  • Loading branch information
devinbinnie and mattermost-build authored Aug 26, 2024
1 parent efbb70f commit eafe056
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 39 deletions.
48 changes: 10 additions & 38 deletions webapp/channels/src/components/data_prefetch/data_prefetch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,25 @@ describe('/components/data_prefetch', () => {
expect(instance.prefetchPosts).toHaveBeenCalledWith('currentChannelId');
});

test('should fetch profiles for sidebar on first channel load', async () => {
const props = defaultProps;
test('should fetch profiles for sidebar on sidebar load', async () => {
const props = {
...defaultProps,
sidebarLoaded: false,
};
const wrapper = shallow<DataPrefetch>(
<DataPrefetch {...props}/>,
);

expect(loadProfilesForSidebar).not.toHaveBeenCalled();

// Change channels
wrapper.setProps({currentChannelId: 'currentChannelId'});
// Finish loading the sidebar
wrapper.setProps({sidebarLoaded: true});
await Promise.resolve(true);

expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1);

// Change channels again
wrapper.setProps({currentChannelId: 'anotherChannelId'});
// Reload the sidebar
wrapper.setProps({sidebarLoaded: true});
await Promise.resolve(true);

expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -345,7 +348,7 @@ describe('/components/data_prefetch', () => {
expect(props.actions.prefetchChannelPosts).toHaveBeenCalledWith('mentionChannel', undefined);
});

test('should load profiles once the current channel and sidebar are both loaded', () => {
test('should load profiles once the sidebar is loaded irrespective of the current channel', () => {
const props = {
...defaultProps,
currentChannelId: '',
Expand Down Expand Up @@ -374,36 +377,5 @@ describe('/components/data_prefetch', () => {
});

expect(loadProfilesForSidebar).toHaveBeenCalled();

jest.clearAllMocks();

// With sidebar loaded first
wrapper = shallow<DataPrefetch>(
<DataPrefetch {...props}/>,
);
wrapper.setProps({
sidebarLoaded: true,
});

expect(loadProfilesForSidebar).not.toHaveBeenCalled();

wrapper.setProps({
currentChannelId: 'channel',
});

expect(loadProfilesForSidebar).toHaveBeenCalled();

jest.clearAllMocks();

// With both loaded at once
wrapper = shallow<DataPrefetch>(
<DataPrefetch {...props}/>,
);
wrapper.setProps({
currentChannelId: 'channel',
sidebarLoaded: true,
});

expect(loadProfilesForSidebar).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export default class DataPrefetch extends React.PureComponent<Props> {

async componentDidUpdate(prevProps: Props) {
const {currentChannelId, prefetchQueueObj, sidebarLoaded} = this.props;
if (sidebarLoaded && !prevProps.sidebarLoaded) {
loadProfilesForSidebar();
}

if (currentChannelId && sidebarLoaded && (!prevProps.currentChannelId || !prevProps.sidebarLoaded)) {
queue.add(async () => this.prefetchPosts(currentChannelId));
await loadProfilesForSidebar();
this.prefetchData();
} else if (prevProps.prefetchQueueObj !== prefetchQueueObj) {
clearTimeout(this.prefetchTimeout);
Expand Down

0 comments on commit eafe056

Please sign in to comment.