Skip to content

Commit

Permalink
💄(frontend) fix minor bugs and enhance DocTitle and DocShareModal
Browse files Browse the repository at this point in the history
- Fixed minor bugs in the frontend codebase for improved stability.
- Enhanced DocTitle component to update title display dynamically using
useEffect.
- Refactored DocShareModal to improve modal content height calculation
for better responsiveness.
  • Loading branch information
PanchoutNathan committed Jan 10, 2025
1 parent 7b0e190 commit 1e849c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to
- ✨(frontend) add favorite feature #515
- ✨(frontend) many ui fixes #524
- 💄(frontend) fix the ux of the new ui #539
- 💄(frontend) fix minor bugs #546

## Changed
- 💄(frontend) add filtering from left panel #475
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
VariantType,
useToastProvider,
} from '@openfun/cunningham-react';
import React, { useCallback, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { css } from 'styled-components';

Expand Down Expand Up @@ -100,6 +100,10 @@ const DocTitleInput = ({ doc }: DocTitleProps) => {
}
};

useEffect(() => {
setTitleDisplay(doc.title);
}, [doc]);

return (
<>
<Tooltip content={t('Rename')} placement="top">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ type Props = {
doc: Doc;
onClose: () => void;
};

export const DocShareModal = ({ doc, onClose }: Props) => {
const { t } = useTranslation();
const selectedUsersRef = useRef<HTMLDivElement>(null);

const { isDesktop } = useResponsiveStore();

const modalContentHeight = isDesktop
? 'min(690px, calc(100dvh - 2em - 12px - 34px))' // 100dvh - 2em - 12px is the max cunningham modal height. 690px is the height of the content in desktop ad 34px is the height of the modal title in mobile
: `calc(100dvh - 34px)`;
const [selectedUsers, setSelectedUsers] = useState<User[]>([]);
const [userQuery, setUserQuery] = useState('');
const [inputValue, setInputValue] = useState('');
Expand Down Expand Up @@ -164,13 +168,11 @@ export const DocShareModal = ({ doc, onClose }: Props) => {
};

const handleRef = (node: HTMLDivElement) => {
const contentHeight = isDesktop ? '690px' : '100dvh - 34px'; // 690px is the height of the content in desktop ad 34px is the height of the modal title in mobile
const inputHeight = canShare ? 70 : 0;
const marginTop = 11;
const footerHeight = node?.clientHeight ?? 0;
const selectedUsersHeight = selectedUsersRef.current?.clientHeight ?? 0;

const height = `calc(${contentHeight} - ${footerHeight}px - ${selectedUsersHeight}px - ${inputHeight}px - ${marginTop}px)`;
const height = `calc(${modalContentHeight} - ${footerHeight}px - ${selectedUsersHeight}px - ${inputHeight}px - ${marginTop}px)`;

setListHeight(height);
};
Expand All @@ -189,7 +191,7 @@ export const DocShareModal = ({ doc, onClose }: Props) => {
<ShareModalStyle />
<Box
aria-label={t('Share modal')}
$height={isDesktop ? '690px' : `calc(100dvh - 34px)`}
$height={modalContentHeight}
$overflow="hidden"
$justify="space-between"
>
Expand Down

0 comments on commit 1e849c6

Please sign in to comment.