signal-desktop/ts/state/ducks/expiration.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

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