Skip to content

Commit

Permalink
Update hasLock when request succeeds
Browse files Browse the repository at this point in the history
See also: #13
  • Loading branch information
BECATRUE committed Dec 7, 2024
1 parent 1ef6f39 commit 04d3870
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions wlm-ui/src/MainPage/Channel/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';

import { AppDispatch } from '../../store';
import {
fetchList, postInUse, postExposure, postPeriod, selectChannelList,
fetchList, postInUse, postExposure, postPeriod, tryLock, releaseLock, selectChannelList,
} from '../../store/slices/channel/channel';
import Channel from './Channel';
import './ChannelList.scss';
Expand Down Expand Up @@ -33,11 +33,11 @@ const ChannelList = () => {
};

const onClickTryLock = (channel: number) => {

dispatch(tryLock({ channel: channel }));
};

const onClickReleaseLock = (channel: number) => {

dispatch(releaseLock({ channel: channel }));
};

return (
Expand Down
26 changes: 26 additions & 0 deletions wlm-ui/src/store/slices/channel/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ export const postPeriod = createAsyncThunk(
},
);

export const tryLock = createAsyncThunk(
'channel/tryLock',
async (payload: Pick<ChannelType, 'channel'>) => {
const { channel } = payload;
await axios.post(`/lock/${channel}/try/`);
return { channel: channel };
},
);

export const releaseLock = createAsyncThunk(
'channel/releaseLock',
async (payload: Pick<ChannelType, 'channel'>) => {
const { channel } = payload;
await axios.put(`/lock/${channel}/release/`);
return { channel: channel };
},
);

export const channelListSlice = createSlice({
name: 'channelList',
initialState,
Expand Down Expand Up @@ -152,6 +170,14 @@ export const channelListSlice = createSlice({
const info = getChannelInfoWithException(state, action.payload.channel);
info.inUse = action.payload.inUse;
})
.addCase(tryLock.fulfilled, (state, action) => {
const info = getChannelInfoWithException(state, action.payload.channel);
info.hasLock = true;
})
.addCase(releaseLock.fulfilled, (state, action) => {
const info = getChannelInfoWithException(state, action.payload.channel);
info.hasLock = false;
})
},
});

Expand Down

0 comments on commit 04d3870

Please sign in to comment.