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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 7x 7x 48x 1x 1x 48x 1x 1x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x | import { useRef } from 'react';
import { BaseVariant } from '@/types';
import { combineClasses } from '@shared/utils';
import { formatFeedbackDate } from '@/utils';
import { useKeyboardInset } from '@/hooks';
import { MenuFeedback } from '@/components/MenuFeedback';
import type { FeedbackDraft, FeedbackDisplay } from '@/utils/feedbackFlow';
// Styles
import './styles/menu-feedback-overlay.css';
const variantTheme = {
[BaseVariant.PRIMARY]: {
overlay: 'menu-feedback-overlay',
container: 'menu-feedback-overlay-container',
imageWrapper: 'menu-feedback-overlay-image-wrapper',
image: 'menu-feedback-overlay-image',
contentWrapper: 'menu-feedback-overlay-content-wrapper',
overlayEnter: 'menu-feedback-overlay-enter',
overlayExit: 'menu-feedback-overlay-exit',
imageEnter: 'image-slide-in',
imageExit: 'image-slide-out',
contentEnter: 'menu-feedback-overlay-content-enter',
contentExit: 'menu-feedback-overlay-content-exit',
},
};
export interface MenuFeedbackOverlayProps {
name: string;
avatar: string;
date: string;
mealImage: string;
mealItems: string;
draft: FeedbackDraft;
display: FeedbackDisplay;
isLoading: boolean;
isClosing: boolean;
hasChanges: boolean;
contentRef: React.RefObject<HTMLDivElement | null>;
textareaRef?: React.RefObject<HTMLTextAreaElement | null>;
onCommentChange: (comment: string) => void;
onEmojiClick: (emoji: string) => void;
onToggleAnonymous: () => void;
onSubmit: () => void;
onClose: () => void;
onAnimationEnd?: () => void;
isEditMode: boolean;
variant?: BaseVariant;
className?: string;
}
export const MenuFeedbackOverlay = ({
name,
avatar,
date,
mealImage,
mealItems,
draft,
display,
isLoading,
isClosing,
hasChanges,
contentRef,
textareaRef,
onCommentChange,
onEmojiClick,
onToggleAnonymous,
onSubmit,
onClose,
onAnimationEnd,
isEditMode,
variant = BaseVariant.PRIMARY,
className = '',
}: MenuFeedbackOverlayProps) => {
const theme = variantTheme[variant];
const isSubmitDisabled = isLoading || (isEditMode && !hasChanges);
const containerRef = useRef<HTMLDivElement>(null);
// Keep the menu visible above the mobile keyboard once it opens
useKeyboardInset(containerRef, contentRef, !isClosing);
const handleCommentChange = (comment: string): void => {
onCommentChange(comment);
};
const handleEmojiClick = (emoji: string): void => {
onEmojiClick(emoji);
};
const handleToggleAnonymous = (): void => {
onToggleAnonymous();
};
return (
<div
data-variant={variant}
className={combineClasses(
theme.overlay,
className,
isClosing ? theme.overlayExit : theme.overlayEnter,
)}
onAnimationEnd={onAnimationEnd}
>
<div ref={containerRef} className={theme.container}>
{/* Mobile-only: Image that slides up from bottom */}
<div className={theme.imageWrapper}>
<img
src={mealImage}
alt={mealItems}
className={combineClasses(
theme.image,
isClosing ? theme.imageExit : theme.imageEnter,
)}
/>
</div>
<div
ref={contentRef}
className={combineClasses(
theme.contentWrapper,
isClosing ? theme.contentExit : theme.contentEnter,
)}
>
<MenuFeedback
ref={textareaRef}
name={name}
avatar={avatar}
date={formatFeedbackDate(date)}
mealImage={mealImage}
mealItems={mealItems}
comment={draft.comment}
isAnonymous={draft.isAnonymous}
isSubmitDisabled={isSubmitDisabled}
onCommentChange={handleCommentChange}
onEmojiClick={handleEmojiClick}
onToggleAnonymous={handleToggleAnonymous}
onSubmit={onSubmit}
onClose={onClose}
/>
</div>
</div>
</div>
);
};
|