2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
// State
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ExpirationStateType = ReadonlyDeep<{
|
2023-01-18 23:31:10 +00:00
|
|
|
buildExpiration: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-02-12 21:30:58 +00:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
const HYDRATE_EXPIRATION_STATUS = 'expiration/HYDRATE_EXPIRATION_STATUS';
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type HyrdateExpirationStatusActionType = ReadonlyDeep<{
|
2020-02-12 21:30:58 +00:00
|
|
|
type: 'expiration/HYDRATE_EXPIRATION_STATUS';
|
2023-01-18 23:31:10 +00:00
|
|
|
payload: { buildExpiration: number };
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ExpirationActionType =
|
|
|
|
ReadonlyDeep<HyrdateExpirationStatusActionType>;
|
2020-02-12 21:30:58 +00:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
2023-01-18 23:31:10 +00:00
|
|
|
function hydrateExpirationStatus(
|
|
|
|
buildExpiration: number
|
|
|
|
): ExpirationActionType {
|
2020-02-12 21:30:58 +00:00
|
|
|
return {
|
|
|
|
type: HYDRATE_EXPIRATION_STATUS,
|
2023-01-18 23:31:10 +00:00
|
|
|
payload: { buildExpiration },
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
hydrateExpirationStatus,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Reducer
|
|
|
|
|
2022-02-23 18:48:40 +00:00
|
|
|
export function getEmptyState(): ExpirationStateType {
|
2020-02-12 21:30:58 +00:00
|
|
|
return {
|
2023-01-18 23:31:10 +00:00
|
|
|
buildExpiration: 0,
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
2020-12-14 19:47:21 +00:00
|
|
|
state: Readonly<ExpirationStateType> = getEmptyState(),
|
|
|
|
action: Readonly<ExpirationActionType>
|
2020-02-12 21:30:58 +00:00
|
|
|
): ExpirationStateType {
|
|
|
|
if (action.type === HYDRATE_EXPIRATION_STATUS) {
|
|
|
|
return {
|
2023-01-18 23:31:10 +00:00
|
|
|
buildExpiration: action.payload.buildExpiration,
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|