Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
olafsulich committed Dec 11, 2024
1 parent 30b78c8 commit dc8a82c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 54 deletions.
21 changes: 12 additions & 9 deletions src/script/components/AppNotification/AppNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import {useEffect, useRef} from 'react';
import {createRoot, Root} from 'react-dom/client';
import {toast, Toaster} from 'sonner';

import * as Icon from 'Components/Icon';
import {CloseIcon} from 'Components/Icon';

interface AppNotificationOptions {
message?: string;
activeWindow?: Window;
leadingIcon?: React.ElementType<any>;
icon?: React.ElementType<any>;
withCloseButton?: boolean;
autoClose?: boolean;
}
Expand All @@ -49,7 +49,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => {
useEffect(() => {
setTimeout(() => {
clearRoots();
});
}, 1);
}, [activeWindow]);

return {
Expand All @@ -61,7 +61,7 @@ export const useAppNotification = (props?: AppNotificationOptions) => {
toastId => (
<AppNotification
message={options?.message || props?.message || ''}
leadingIcon={props?.leadingIcon}
icon={props?.icon}
withCloseButton={props?.withCloseButton}
onClose={() => toast.dismiss(toastId)}
/>
Expand All @@ -77,7 +77,10 @@ export const useAppNotification = (props?: AppNotificationOptions) => {
},
);
notificationId.current = id;
});
// Small delay to ensure rendering is complete.
// In some cases (switching between windows) the notification is not displayed without this delay.
// It's caused by the rendering behavior of the toast library (injecting the <Toaster/> into the DOM node).
}, 1);
},
close: () => {
if (!notificationId.current) {
Expand Down Expand Up @@ -120,18 +123,18 @@ const clearRoots = () => {
roots = {};
};

interface AppNotificationProps extends Pick<AppNotificationOptions, 'message' | 'leadingIcon' | 'withCloseButton'> {
interface AppNotificationProps extends Pick<AppNotificationOptions, 'message' | 'icon' | 'withCloseButton'> {
onClose?: () => void;
}

const AppNotification = ({message, leadingIcon: LeadingIcon, withCloseButton, onClose}: AppNotificationProps) => {
const AppNotification = ({message, icon: Icon, withCloseButton, onClose}: AppNotificationProps) => {
return (
<div className="app-notification">
{LeadingIcon && <LeadingIcon className="app-notification__icon" />}
{Icon && <Icon className="app-notification__icon" />}
<div className="app-notification__content">{message}</div>
{withCloseButton && (
<button className="app-notification__button" onClick={onClose}>
<Icon.CloseIcon className="app-notification__icon" />
<CloseIcon className="app-notification__icon" />
</button>
)}
</div>
Expand Down
41 changes: 0 additions & 41 deletions src/script/components/calling/FullscreenVideoCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,35 +450,6 @@ const FullscreenVideoCall = ({

const isModerator = selfUser && roles[selfUser.id] === DefaultConversationRoleName.WIRE_ADMIN;

const noti = useAppNotification({
activeWindow: viewMode === CallingViewMode.DETACHED_WINDOW ? detachedWindow! : window,
withCloseButton: true,
leadingIcon: Icon.MicOnIcon,
});

const handleOpen = () => {
noti?.show({
message: 'Microphone temporarily on',
});
};

const handleClose = () => {
noti?.close();
};

const noti2 = useAppNotification({
message: 'Second one',
activeWindow: viewMode === CallingViewMode.DETACHED_WINDOW ? detachedWindow! : window,
});

const handleOpen2 = () => {
noti2?.show();
};

const handleClose2 = () => {
noti2?.close();
};

return (
<div
className={cx('video-calling-wrapper', {
Expand Down Expand Up @@ -656,18 +627,6 @@ const FullscreenVideoCall = ({
</li>
)}
<div className="video-controls__centered-items">
<li>
<button onClick={handleOpen}>open 1</button>
</li>
<li>
<button onClick={handleClose}>close 1</button>
</li>
<li>
<button onClick={handleOpen2}>open 2</button>
</li>
<li>
<button onClick={handleClose2}>close 2</button>
</li>
<li className="video-controls__item">
<button
className="video-controls__button"
Expand Down
9 changes: 5 additions & 4 deletions src/script/view_model/CallingViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ export class CallingViewModel {
this.callingRepository.rejectCall(conversation.qualifiedId);
},
startAudio: async (conversationEntity: Conversation) => {
// if (conversationEntity.isGroup() && !this.teamState.isConferenceCallingEnabled()) {
// this.showRestrictedConferenceCallingModal();
// } else {
await handleCallAction(conversationEntity, CALL_TYPE.NORMAL);
if (conversationEntity.isGroup() && !this.teamState.isConferenceCallingEnabled()) {
this.showRestrictedConferenceCallingModal();
} else {
await handleCallAction(conversationEntity, CALL_TYPE.NORMAL);
}
},
startVideo: async (conversationEntity: Conversation) => {
if (conversationEntity.isGroup() && !this.teamState.isConferenceCallingEnabled()) {
Expand Down

0 comments on commit dc8a82c

Please sign in to comment.