bigbuffet-rw/app/soapbox/reducers/meta.ts

30 lines
900 B
TypeScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
'use strict';
import { Record as ImmutableRecord } from 'immutable';
import { fetchInstance } from 'soapbox/actions/instance';
import { SW_UPDATING } from 'soapbox/actions/sw';
2020-03-27 13:59:38 -07:00
2022-04-24 12:28:07 -07:00
import type { AnyAction } from 'redux';
const ReducerRecord = ImmutableRecord({
/** Whether /api/v1/instance 404'd (and we should display the external auth form). */
instance_fetch_failed: false,
/** Whether the ServiceWorker is currently updating (and we should display a loading screen). */
swUpdating: false,
});
2020-03-27 13:59:38 -07:00
2022-04-24 12:28:07 -07:00
export default function meta(state = ReducerRecord(), action: AnyAction) {
switch (action.type) {
2022-05-11 14:06:35 -07:00
case fetchInstance.rejected.type:
if (action.payload.response?.status === 404) {
return state.set('instance_fetch_failed', true);
}
return state;
case SW_UPDATING:
return state.set('swUpdating', action.isUpdating);
2022-05-11 14:06:35 -07:00
default:
return state;
2020-03-27 13:59:38 -07:00
}
2021-08-03 12:22:51 -07:00
}