Create text stories

This commit is contained in:
Josh Perez 2022-06-16 20:48:57 -04:00 committed by GitHub
parent 973b2264fe
commit d970d427f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 2433 additions and 1106 deletions

View file

@ -1,23 +1,34 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ThunkAction } from 'redux-thunk';
import type { NoopActionType } from './noop';
import type { StateType as RootStateType } from '../reducer';
import type { LinkPreviewType } from '../../types/message/LinkPreviews';
import type { LinkPreviewSourceType } from '../../types/LinkPreview';
import { assignWithNoUnnecessaryAllocation } from '../../util/assignWithNoUnnecessaryAllocation';
import { maybeGrabLinkPreview } from '../../services/LinkPreview';
import { useBoundActions } from '../../hooks/useBoundActions';
// State
export type LinkPreviewsStateType = {
readonly linkPreview?: LinkPreviewType;
readonly source?: LinkPreviewSourceType;
};
// Actions
const ADD_PREVIEW = 'linkPreviews/ADD_PREVIEW';
export const ADD_PREVIEW = 'linkPreviews/ADD_PREVIEW';
export const REMOVE_PREVIEW = 'linkPreviews/REMOVE_PREVIEW';
type AddLinkPreviewActionType = {
export type AddLinkPreviewActionType = {
type: 'linkPreviews/ADD_PREVIEW';
payload: LinkPreviewType;
payload: {
linkPreview: LinkPreviewType;
source: LinkPreviewSourceType;
};
};
export type RemoveLinkPreviewActionType = {
@ -30,15 +41,30 @@ type LinkPreviewsActionType =
// Action Creators
export const actions = {
addLinkPreview,
removeLinkPreview,
};
function debouncedMaybeGrabLinkPreview(
message: string,
source: LinkPreviewSourceType
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
return dispatch => {
maybeGrabLinkPreview(message, source);
function addLinkPreview(payload: LinkPreviewType): AddLinkPreviewActionType {
dispatch({
type: 'NOOP',
payload: null,
});
};
}
function addLinkPreview(
linkPreview: LinkPreviewType,
source: LinkPreviewSourceType
): AddLinkPreviewActionType {
return {
type: ADD_PREVIEW,
payload,
payload: {
linkPreview,
source,
},
};
}
@ -48,6 +74,15 @@ function removeLinkPreview(): RemoveLinkPreviewActionType {
};
}
export const actions = {
addLinkPreview,
debouncedMaybeGrabLinkPreview,
removeLinkPreview,
};
export const useLinkPreviewActions = (): typeof actions =>
useBoundActions(actions);
// Reducer
export function getEmptyState(): LinkPreviewsStateType {
@ -64,13 +99,15 @@ export function reducer(
const { payload } = action;
return {
linkPreview: payload,
linkPreview: payload.linkPreview,
source: payload.source,
};
}
if (action.type === REMOVE_PREVIEW) {
return assignWithNoUnnecessaryAllocation(state, {
linkPreview: undefined,
source: undefined,
});
}