Skip to content

Commit

Permalink
Tweaked text in coverage placeholder and added button to allow file u…
Browse files Browse the repository at this point in the history
…pload
  • Loading branch information
kudlajz committed Oct 30, 2024
1 parent cfd80b5 commit c4866bf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import styles from './InputPlaceholder.module.scss';
import type { ContentRenderProps } from './Placeholder';

export interface Props extends Omit<BaseProps, 'title' | 'onSubmit'> {
children?: ReactNode;
title: ReactNode | FunctionComponent<ContentRenderProps>;
description: ReactNode | FunctionComponent<ContentRenderProps>;
// Input properties
Expand All @@ -28,6 +29,7 @@ export interface Props extends Omit<BaseProps, 'title' | 'onSubmit'> {
const isEsc = isHotkey('esc');

export function InputPlaceholder({
children,
className,
action,
title,
Expand Down Expand Up @@ -135,6 +137,7 @@ export function InputPlaceholder({
value={value}
/>
</form>
{children}
</Frame>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "styles/variables";

.Action {
margin: $spacing-2 0 0;
}

.Button {
text-decoration: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import React, { type DragEvent, useEffect, useState } from 'react';
import { Transforms } from 'slate';
import { useSelected, useSlateStatic } from 'slate-react';

import { SearchInput } from '#components';
import { PlaceholderCoverage } from '#icons';
import { Button, SearchInput } from '#components';
import { PlaceholderCoverage, Upload } from '#icons';
import { URL_WITH_OPTIONAL_PROTOCOL_REGEXP, useFunction } from '#lib';

import { createCoverage } from '#extensions/coverage';
import { EventsEditor } from '#modules/events';
import { UploadcareEditor } from '#modules/uploadcare';

import { InputPlaceholder } from '../components/InputPlaceholder';
import { withLoadingDots } from '../components/LoadingDots';
Expand All @@ -24,6 +25,8 @@ import { replacePlaceholder } from '../lib';
import type { PlaceholderNode } from '../PlaceholderNode';
import { PlaceholdersManager, usePlaceholderManagement } from '../PlaceholdersManager';

import styles from './CoveragePlaceholderElement.module.scss';

type Url = string;
type CoverageRef = Pick<CoverageNode, 'coverage'>;
type Mode = 'search' | 'create';
Expand All @@ -49,6 +52,22 @@ export function CoveragePlaceholderElement({
PlaceholdersManager.activate(element);
});

const handleUpload = useFunction(async () => {
const files = await UploadcareEditor.upload(editor, { multiple: false });
if (!files) {
return;
}

setMode('search');
const uploading = toProgressPromise(files[0]).then(async (fileInfo: PrezlyFileInfo) => {
const file = UploadcareFile.createFromUploadcareWidgetPayload(fileInfo);
const ref = await onCreateCoverage(file);

return { coverage: { id: ref.coverage.id } };
});
PlaceholdersManager.register(element.type, element.uuid, uploading);
});

const handleDrop = useFunction((event: DragEvent) => {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -133,10 +152,11 @@ export function CoveragePlaceholderElement({
renderFrame={() =>
mode === 'create' ? (
<InputPlaceholder
autoFocus
format="card"
selected={isSelected}
title="Coverage"
description="Type the URL of the new Coverage you want to add"
title="Log new coverage"
description="Paste a coverage URL or upload a coverage file (you can also drop it here)."
placeholder="www.website.com/article"
pattern={URL_WITH_OPTIONAL_PROTOCOL_REGEXP.source}
action="Add coverage"
Expand All @@ -145,7 +165,18 @@ export function CoveragePlaceholderElement({
onEsc={() => PlaceholdersManager.deactivate(element)}
onRemove={handleRemove}
onSubmit={handleSubmitUrl}
/>
>
<div className={styles.Action}>
<Button
className={styles.Button}
icon={Upload}
onClick={handleUpload}
variant="underlined"
>
Upload a coverage file
</Button>
</div>
</InputPlaceholder>
) : undefined
}
inputTitle="Coverage"
Expand Down
3 changes: 3 additions & 0 deletions packages/slate-editor/src/icons/Upload.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/slate-editor/src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export { default as Resize } from './Resize.svg';
export { default as Search } from './Search.svg';
export { default as SocialFacebook } from './Social-Facebook.svg';
export { default as SocialTwitter } from './Social-Twitter.svg';
export { default as Upload } from './Upload.svg';
export { default as User } from './User.svg';
export { default as Video } from './Video.svg';
export { default as WarningCircle } from './Warning-Circle.svg';
Expand Down

0 comments on commit c4866bf

Please sign in to comment.