Skip to content

Commit

Permalink
Load audio sticker images from CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Jul 1, 2024
1 parent 72c54ad commit 2e6aab8
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 32 deletions.
14 changes: 7 additions & 7 deletions packages/element-library/src/audioSticker/display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import type {
* Internal dependencies
*/
import { elementFillContent } from '../shared';
import {
AUDIO_STICKERS,
AUDIO_STICKER_STYLES,
AUDIO_STICKER_LABELS,
} from '../constants';
import { AUDIO_STICKER_STYLES, AUDIO_STICKER_LABELS } from '../constants';

interface ElementProps {
stickerStyle: keyof typeof AUDIO_STICKER_STYLES;
Expand All @@ -42,7 +38,10 @@ const Element = styled.img<ElementProps>`
${({ stickerStyle }) => AUDIO_STICKER_STYLES[stickerStyle]}
`;

function AudioStickerDisplay({ element }: DisplayProps<AudioStickerElement>) {
function AudioStickerDisplay({
element,
cdnUrl,
}: DisplayProps<AudioStickerElement>) {
const {
width: elementWidth,
height: elementHeight,
Expand All @@ -52,7 +51,8 @@ function AudioStickerDisplay({ element }: DisplayProps<AudioStickerElement>) {

return (
<Element
src={AUDIO_STICKERS[sticker]}
src={`${cdnUrl}images/audio-sticker/${sticker}-pretap.png`}
crossOrigin="anonymous"
stickerStyle={style}
height={elementHeight}
width={elementWidth}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 0 additions & 17 deletions packages/element-library/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@
*/
import { __ } from '@googleforcreators/i18n';

/**
* Internal dependencies
*/
import headphoneCat from './audioSticker/images/headphone-cat/headphone-cat-pretap.png';
import tapePlayer from './audioSticker/images/tape-player/tape-player-pretap.png';
import loudSpeaker from './audioSticker/images/loud-speaker/loud-speaker-posttap.png';
import audioCloud from './audioSticker/images/audio-cloud/audio-cloud-posttap.png';

// TODO: Move to audioSticker folder once TypeScript conversion is complete.
// See https://github.com/GoogleForCreators/web-stories-wp/pull/13503.
export const AUDIO_STICKERS: Record<string, string> = {
'headphone-cat': headphoneCat,
'tape-player': tapePlayer,
'loud-speaker': loudSpeaker,
'audio-cloud': audioCloud,
} as const;

export const AUDIO_STICKER_STYLES = {
none: '',
outline: 'border: 4px solid white; border-radius: 20px',
Expand Down
1 change: 1 addition & 0 deletions packages/elements/src/types/elementDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface DisplayProps<E extends Element> {
blurHash?: string;
baseColor?: string;
}) => void;
cdnUrl: string;
}

export type Direction = [0 | 1, 0 | 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
*/
import { StoryPropTypes } from '../../propTypes';
import useCORSProxy from '../../utils/useCORSProxy';
import { useLocalMedia, useFont } from '../../app';
import { useLocalMedia, useFont, useConfig } from '../../app';
import renderResourcePlaceholder from './renderResourcePlaceholder';

// Using attributes to avoid creation of hundreds of classes by styled components for previewMode.
Expand Down Expand Up @@ -116,6 +116,7 @@ function DisplayElement({
dataToEditorX: state.actions.dataToEditorX,
}));
const { getProxiedUrl } = useCORSProxy();
const { cdnURL } = useConfig();
const {
actions: { maybeEnqueueFontStyle },
} = useFont();
Expand Down Expand Up @@ -267,6 +268,7 @@ function DisplayElement({
maybeEnqueueFontStyle={maybeEnqueueFontStyle}
siblingCount={siblingCount}
renderResourcePlaceholder={renderResourcePlaceholder}
cdnUrl={cdnURL}
/>
</WithMask>
{!previewMode && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
Expand All @@ -21,14 +22,14 @@ import PropTypes from 'prop-types';
import { useCallback } from '@googleforcreators/react';
import { __, sprintf } from '@googleforcreators/i18n';
import {
AUDIO_STICKERS,
AUDIO_STICKER_STYLES,
AUDIO_STICKER_LABELS,
} from '@googleforcreators/element-library';

/**
* Internal dependencies
*/
import { useConfig } from '../../../../app/config';
import { Row, FilterToggle } from '../../../form';
import { SimplePanel } from '../../panel';
import { states, useHighlights } from '../../../../app/highlights';
Expand All @@ -52,6 +53,8 @@ const StickerImage = styled.img`
`;

function StickerStyle({ selectedElements, pushUpdate }) {
const { cdnURL } = useConfig();

const stickerObj = selectedElements[0];
const style = stickerObj.style;
const type = stickerObj.sticker;
Expand Down Expand Up @@ -102,7 +105,8 @@ function StickerStyle({ selectedElements, pushUpdate }) {
)}
>
<StickerImage
src={AUDIO_STICKERS[type]}
src={`${cdnURL}images/audio-sticker/${type}-pretap.png`}
crossOrigin="anonymous"
alt={AUDIO_STICKER_LABELS[type].label}
stickerStyle={stickerStyle}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { useCallback } from '@googleforcreators/react';
import { __, sprintf } from '@googleforcreators/i18n';
import {
AUDIO_STICKERS,
AUDIO_STICKER_LABELS,
} from '@googleforcreators/element-library';
import { AUDIO_STICKER_LABELS } from '@googleforcreators/element-library';

/**
* Internal dependencies
*/
import { useConfig } from '../../../../app/config';
import { Row, FilterToggle } from '../../../form';
import { SimplePanel } from '../../panel';
import { states, useHighlights } from '../../../../app/highlights';
Expand All @@ -53,6 +52,8 @@ const StickerImage = styled.img`
`;

function StickerType({ selectedElements, pushUpdate }) {
const { cdnURL } = useConfig();

const stickerObj = selectedElements[0];

const { highlight, resetHighlight } = useHighlights((state) => ({
Expand Down Expand Up @@ -101,7 +102,8 @@ function StickerType({ selectedElements, pushUpdate }) {
)}
>
<StickerImage
src={AUDIO_STICKERS[type]}
src={`${cdnURL}images/audio-sticker/${type}-pretap.png`}
crossOrigin="anonymous"
alt={AUDIO_STICKER_LABELS[type].label}
/>
</FilterToggle>
Expand Down

0 comments on commit 2e6aab8

Please sign in to comment.