All files / core/blong-browser/src/feedback FeedbackSubmitBar.tsx

0% Statements 0/1
0% Branches 0/11
0% Functions 0/1
0% Lines 0/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80                                                                                                                                                               
/**
 * FeedbackSubmitBar.tsx — the mode's whole workflow in three buttons
 * (`@@T-462`, `@@T-490`).
 *
 * It reports how many comments are waiting, opens the crop, and takes the one
 * action that leaves the mode: submit. Discarding keeps the mode open (the draft
 * is only dropped after the confirmation the caller decides on).
 */
 
import {Text} from '../components/Text/Text.js';
import {FEEDBACK_UI_ATTR} from './ids.js';
 
export interface IFeedbackSubmitBarProps {
    count: number;
    busy: boolean;
    /** While cropping, the label asks to finish rather than to start. */
    cropping: boolean;
    /** Whether a region is already chosen, so the button reads as an edit. */
    cropped: boolean;
    onCrop: () => void;
    onSubmit: () => void;
    onDiscard: () => void;
}
 
export function FeedbackSubmitBar({
    count,
    busy,
    cropping,
    cropped,
    onCrop,
    onSubmit,
    onDiscard,
}: IFeedbackSubmitBarProps) {
    return (
        <div
            className="blong-feedback-bar"
            {...{[FEEDBACK_UI_ATTR]: 'bar'}}
        >
            <span className="blong-feedback-bar__count">
                {count === 1 ? (
                    <Text>1 comment</Text>
                ) : (
                    <Text params={{count}}>{'{count} comments'}</Text>
                )}
            </span>
            <button
                type="button"
                className="blong-feedback-bar__button"
                onClick={onCrop}
                disabled={busy}
                aria-pressed={cropping}
            >
                {cropping ? (
                    <Text>Done</Text>
                ) : cropped ? (
                    <Text>Edit picture</Text>
                ) : (
                    <Text>Crop</Text>
                )}
            </button>
            <button
                type="button"
                className="blong-feedback-bar__button"
                onClick={onDiscard}
                disabled={busy}
            >
                <Text>Discard</Text>
            </button>
            <button
                type="button"
                className="blong-feedback-bar__button blong-feedback-bar__button--primary"
                onClick={onSubmit}
                disabled={busy || count === 0 || cropping}
            >
                {busy ? <i className="pi pi-spin pi-spinner" /> : <Text>Submit</Text>}
            </button>
        </div>
    );
}