Skip to content

Commit

Permalink
refactor: simplify channelsApi
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitCode committed Nov 2, 2024
1 parent 20356f9 commit b4f08a0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions frontend/src/api/channelsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ export const channelsApi = createApi({
baseUrl: getApiPath(CHANNELS_PATH),
prepareHeaders,
}),
tagTypes: ['Channels'],
tagTypes: ['Channels', 'Messages'],
endpoints: (builder) => ({
getChannels: builder.query({
query: () => '',
providesTags: (result) => (result
? [...result.map(({ id }) => ({ type: 'Channels', id })), { type: 'Channels', id: 'LIST' }]
: [{ type: 'Channels', id: 'LIST' }]),
providesTags: ['Channels'],
}),

addChannel: builder.mutation({
Expand All @@ -29,7 +27,7 @@ export const channelsApi = createApi({
method: 'DELETE',
url: id,
}),
invalidatesTags: (id) => [{ type: 'Channels', id }],
invalidatesTags: ['Channels', 'Messages'],
}),

editChannel: builder.mutation({
Expand All @@ -38,7 +36,6 @@ export const channelsApi = createApi({
url: channel.id,
body: channel,
}),
invalidatesTags: ({ id }) => [{ type: 'Channels', id }],
}),
}),
});
Expand Down

0 comments on commit b4f08a0

Please sign in to comment.