Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
@@ -19,10 +19,10 @@ import {
|
|||||||
getOwnerAttendee,
|
getOwnerAttendee,
|
||||||
getTitleStyle,
|
getTitleStyle,
|
||||||
IconDisplayConfig,
|
IconDisplayConfig,
|
||||||
|
useCompactMode,
|
||||||
} from "./EventChipUtils";
|
} from "./EventChipUtils";
|
||||||
import { SimpleEventChip } from "./SimpleEventChip";
|
import { SimpleEventChip } from "./SimpleEventChip";
|
||||||
|
|
||||||
const COMPACT_WIDTH_THRESHOLD = 100;
|
|
||||||
const PRIVATE_CLASSIFICATIONS = ["PRIVATE", "CONFIDENTIAL"];
|
const PRIVATE_CLASSIFICATIONS = ["PRIVATE", "CONFIDENTIAL"];
|
||||||
|
|
||||||
export const EVENT_DURATION = {
|
export const EVENT_DURATION = {
|
||||||
@@ -31,34 +31,6 @@ export const EVENT_DURATION = {
|
|||||||
LONG: 60,
|
LONG: 60,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
function useCompactMode(
|
|
||||||
cardRef: React.RefObject<HTMLDivElement | null>
|
|
||||||
): boolean {
|
|
||||||
const [showCompact, setShowCompact] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const checkWidth = () => {
|
|
||||||
if (cardRef.current) {
|
|
||||||
const width = cardRef.current.offsetWidth;
|
|
||||||
setShowCompact(width < COMPACT_WIDTH_THRESHOLD);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
checkWidth();
|
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(checkWidth);
|
|
||||||
if (cardRef.current) {
|
|
||||||
resizeObserver.observe(cardRef.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
resizeObserver.disconnect();
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return showCompact;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function EventChip({
|
export function EventChip({
|
||||||
arg,
|
arg,
|
||||||
calendars,
|
calendars,
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
|
|||||||
import LockOutlineIcon from "@mui/icons-material/LockOutline";
|
import LockOutlineIcon from "@mui/icons-material/LockOutline";
|
||||||
import { Box, getContrastRatio } from "@mui/material";
|
import { Box, getContrastRatio } from "@mui/material";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import React from "react";
|
import React, { useLayoutEffect, useState } from "react";
|
||||||
import { Calendars } from "../../../features/Calendars/CalendarTypes";
|
import { Calendars } from "../../../features/Calendars/CalendarTypes";
|
||||||
import { userAttendee } from "../../../features/User/userDataTypes";
|
import { userAttendee } from "../../../features/User/userDataTypes";
|
||||||
import { EventErrorHandler } from "../../Error/EventErrorHandler";
|
import { EventErrorHandler } from "../../Error/EventErrorHandler";
|
||||||
import { EVENT_DURATION } from "./EventChip";
|
import { EVENT_DURATION } from "./EventChip";
|
||||||
|
|
||||||
|
const COMPACT_WIDTH_THRESHOLD = 100;
|
||||||
|
|
||||||
export interface EventChipProps {
|
export interface EventChipProps {
|
||||||
arg: any;
|
arg: any;
|
||||||
calendars: Record<string, Calendars>;
|
calendars: Record<string, Calendars>;
|
||||||
@@ -180,3 +182,32 @@ export function DisplayedIcons(IconDisplayed: IconDisplayConfig) {
|
|||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useCompactMode(
|
||||||
|
cardRef: React.RefObject<HTMLDivElement | null>
|
||||||
|
): boolean {
|
||||||
|
const [showCompact, setShowCompact] = useState(false);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (!cardRef.current) return;
|
||||||
|
|
||||||
|
const checkWidth = () => {
|
||||||
|
const width = cardRef.current?.offsetWidth ?? 0;
|
||||||
|
const newCompact = width < COMPACT_WIDTH_THRESHOLD;
|
||||||
|
|
||||||
|
setShowCompact((prev) => (prev !== newCompact ? newCompact : prev));
|
||||||
|
};
|
||||||
|
|
||||||
|
checkWidth();
|
||||||
|
|
||||||
|
const resizeObserver = new ResizeObserver(() => {
|
||||||
|
requestAnimationFrame(checkWidth);
|
||||||
|
});
|
||||||
|
|
||||||
|
resizeObserver.observe(cardRef.current);
|
||||||
|
|
||||||
|
return () => resizeObserver.disconnect();
|
||||||
|
}, [cardRef]);
|
||||||
|
|
||||||
|
return showCompact;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user