2021-08-11 16:23:42 -07:00
|
|
|
import { getSettings, changeSetting } from 'soapbox/actions/settings';
|
|
|
|
|
2022-06-18 02:51:02 -07:00
|
|
|
import type { OrderedSet as ImmutableOrderedSet } from 'immutable';
|
2022-06-15 13:11:36 -07:00
|
|
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
|
|
|
|
|
|
|
const getPinnedHosts = (state: RootState) => {
|
2021-08-11 16:23:42 -07:00
|
|
|
const settings = getSettings(state);
|
2022-06-18 02:51:02 -07:00
|
|
|
return settings.getIn(['remote_timeline', 'pinnedHosts']) as ImmutableOrderedSet<string>;
|
2021-08-11 16:23:42 -07:00
|
|
|
};
|
|
|
|
|
2022-06-15 13:11:36 -07:00
|
|
|
const pinHost = (host: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-08-11 16:23:42 -07:00
|
|
|
const state = getState();
|
2021-08-11 17:38:25 -07:00
|
|
|
const pinnedHosts = getPinnedHosts(state);
|
2021-08-11 16:23:42 -07:00
|
|
|
|
2022-06-18 02:51:02 -07:00
|
|
|
return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.add(host)));
|
2021-08-11 16:23:42 -07:00
|
|
|
};
|
|
|
|
|
2022-06-18 02:51:02 -07:00
|
|
|
const unpinHost = (host: string) =>
|
2022-06-15 13:11:36 -07:00
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-08-11 16:23:42 -07:00
|
|
|
const state = getState();
|
2021-08-11 17:38:25 -07:00
|
|
|
const pinnedHosts = getPinnedHosts(state);
|
2021-08-11 16:23:42 -07:00
|
|
|
|
2022-06-18 02:51:02 -07:00
|
|
|
return dispatch(changeSetting(['remote_timeline', 'pinnedHosts'], pinnedHosts.remove(host)));
|
2021-08-11 16:23:42 -07:00
|
|
|
};
|
2022-06-15 13:11:36 -07:00
|
|
|
|
|
|
|
export {
|
|
|
|
pinHost,
|
|
|
|
unpinHost,
|
|
|
|
};
|