Skip to content

Commit

Permalink
Rename 'popup' references to 'popUp' across components.
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Oct 17, 2024
1 parent 38cafbd commit 189be81
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions new-log-viewer/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CONFIG_KEY} from "../typings/config";
import {CONFIG_DEFAULT} from "../utils/config";
import CentralContainer from "./CentralContainer";
import MenuBar from "./MenuBar";
import Popups from "./Popups";
import PopUps from "./PopUps";

Check failure on line 7 in new-log-viewer/src/components/Layout.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Unable to resolve path to module './PopUps'
import StatusBar from "./StatusBar";
import APP_THEME from "./theme";

Expand All @@ -24,7 +24,7 @@ const Layout = () => {
<MenuBar/>
<CentralContainer/>
<StatusBar/>
<Popups/>
<PopUps/>
</CssVarsProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import CloseIcon from "@mui/icons-material/Close";

import {
NotificationContext,
PopupMessage,
PopUpMessage,
} from "../../contexts/NotificationContextProvider";
import {WithId} from "../../typings/common";
import {LOG_LEVEL} from "../../typings/logs";
Expand All @@ -25,8 +25,8 @@ import {DO_NOT_TIMEOUT_VALUE} from "../../typings/notifications";

const AUTO_DISMISS_PERCENT_UPDATE_INTERVAL_MILLIS = 50;

interface PopupMessageProps {
message: WithId<PopupMessage>,
interface PopUpMessageProps {
message: WithId<PopUpMessage>,
}

/**
Expand All @@ -36,14 +36,14 @@ interface PopupMessageProps {
* @param props.message
* @return
*/
const PopupMessageBox = ({message}: PopupMessageProps) => {
const PopUpMessageBox = ({message}: PopUpMessageProps) => {
const {id, level, message: messageStr, title, timeoutMillis} = message;

const {handlePopupMessageClose} = useContext(NotificationContext);
const {handlePopUpMessageClose} = useContext(NotificationContext);
const [intervalCount, setIntervalCount] = useState<number>(0);

const handleCloseButtonClick = () => {
handlePopupMessageClose(id);
handlePopUpMessageClose(id);
};

useEffect(() => {
Expand All @@ -59,7 +59,7 @@ const PopupMessageBox = ({message}: PopupMessageProps) => {
};
}, [
timeoutMillis,
handlePopupMessageClose,
handlePopUpMessageClose,
]);

const color = level >= LOG_LEVEL.ERROR ?
Expand All @@ -72,7 +72,7 @@ const PopupMessageBox = ({message}: PopupMessageProps) => {
percentRemaining = 100 - (100 * (intervalCount / totalIntervals));
if (0 >= percentRemaining) {
setTimeout(() => {
handlePopupMessageClose(id);
handlePopUpMessageClose(id);
}, 0);
}
}
Expand Down Expand Up @@ -117,4 +117,4 @@ const PopupMessageBox = ({message}: PopupMessageProps) => {
);
};

export default PopupMessageBox;
export default PopUpMessageBox;
16 changes: 8 additions & 8 deletions new-log-viewer/src/components/Popups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import {
} from "@mui/joy";

import {NotificationContext} from "../../contexts/NotificationContextProvider";
import PopupMessageBox from "./PopupMessageBox";
import PopUpMessageBox from "./PopUpMessageBox";

import "./index.css";


/**
* Displays popups.
* Displays pop-ups in a transparent container positioned on the right side of the viewport.
*
* @return
*/
const Popups = () => {
const {popupMessages} = useContext(NotificationContext);
const PopUps = () => {
const {popUpMessages} = useContext(NotificationContext);

return (
<Snackbar
className={"pop-up-messages-container-snackbar"}
open={0 < popupMessages.length}
open={0 < popUpMessages.length}
>
<Stack
className={"pop-up-messages-container-stack"}
direction={"column-reverse"}
gap={1}
>
{popupMessages.map((message) => (
<PopupMessageBox
{popUpMessages.map((message) => (
<PopUpMessageBox
key={message.id}
message={message}/>
))}
Expand All @@ -39,4 +39,4 @@ const Popups = () => {
);
};

export default Popups;
export default PopUps;
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const handleConfigFormReset = (ev: React.FormEvent) => {
* @return
*/
const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
const {postPopup} = useContext(NotificationContext);
const {postPopUp} = useContext(NotificationContext);

const handleConfigFormSubmit = useCallback((ev: React.FormEvent) => {
ev.preventDefault();
Expand All @@ -102,7 +102,7 @@ const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
});

if (null !== error) {
postPopup({
postPopUp({
level: LOG_LEVEL.ERROR,
message: error,
timeoutMillis: DO_NOT_TIMEOUT_VALUE,
Expand All @@ -111,7 +111,7 @@ const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
} else {
window.location.reload();
}
}, [postPopup]);
}, [postPopUp]);

return (
<form
Expand Down
34 changes: 17 additions & 17 deletions new-log-viewer/src/contexts/NotificationContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import React, {
} from "react";

import {WithId} from "../typings/common";
import {PopupMessage} from "../typings/notifications";
import {PopUpMessage} from "../typings/notifications";


interface NotificationContextType {
popupMessages: WithId<PopupMessage>[],
popUpMessages: WithId<PopUpMessage>[],

handlePopupMessageClose: (messageId: number) => void;
postPopup: (message: PopupMessage) => void,
handlePopUpMessageClose: (messageId: number) => void;
postPopUp: (message: PopUpMessage) => void,
}

const NotificationContext = createContext<NotificationContextType>({} as NotificationContextType);
Expand All @@ -22,10 +22,10 @@ const NotificationContext = createContext<NotificationContextType>({} as Notific
* Default values of the Notification context value object.
*/
const NOTIFICATION_DEFAULT: Readonly<NotificationContextType> = Object.freeze({
popupMessages: [],
popUpMessages: [],

handlePopupMessageClose: () => {},
postPopup: () => {},
handlePopUpMessageClose: () => {},
postPopUp: () => {},
});


Expand All @@ -42,36 +42,36 @@ interface NotificationContextProviderProps {
* @return
*/
const NotificationContextProvider = ({children}: NotificationContextProviderProps) => {
const [popupMessages, setPopupMessages] = useState<WithId<PopupMessage>[]>(
NOTIFICATION_DEFAULT.popupMessages
const [popUpMessages, setPopUpMessages] = useState<WithId<PopUpMessage>[]>(
NOTIFICATION_DEFAULT.popUpMessages
);
const nextPopUpMessageIdRef = useRef<number>(0);

const postPopup = useCallback((message:PopupMessage) => {
const postPopUp = useCallback((message:PopUpMessage) => {
const newMessage = {
id: nextPopUpMessageIdRef.current,
...message,
};

nextPopUpMessageIdRef.current++;

setPopupMessages((v) => ([
setPopUpMessages((v) => ([
newMessage,
...v,
]));
}, []);

const handlePopupMessageClose = useCallback((messageId: number) => {
const handlePopUpMessageClose = useCallback((messageId: number) => {
// Keep everything but except input message.
setPopupMessages((popups) => popups.filter((m) => m.id !== messageId));
setPopUpMessages((v) => v.filter((m) => m.id !== messageId));
}, []);

return (
<NotificationContext.Provider
value={{
popupMessages: popupMessages,
handlePopupMessageClose: handlePopupMessageClose,
postPopup: postPopup,
popUpMessages: popUpMessages,
handlePopUpMessageClose: handlePopUpMessageClose,
postPopUp: postPopUp,
}}
>
{children}
Expand All @@ -80,5 +80,5 @@ const NotificationContextProvider = ({children}: NotificationContextProviderProp
};

export {NotificationContext};
export type {PopupMessage};
export type {PopUpMessage};
export default NotificationContextProvider;
6 changes: 3 additions & 3 deletions new-log-viewer/src/contexts/StateContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const updateUrlIfEventOnPage = (
*/
// eslint-disable-next-line max-lines-per-function, max-statements
const StateContextProvider = ({children}: StateContextProviderProps) => {
const {postPopup} = useContext(NotificationContext);
const {postPopUp} = useContext(NotificationContext);
const {filePath, logEventNum} = useContext(UrlContext);

// States
Expand Down Expand Up @@ -264,7 +264,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
setOnDiskFileSizeInBytes(args.onDiskFileSizeInBytes);
break;
case WORKER_RESP_CODE.NOTIFICATION:
postPopup({
postPopUp({
level: args.logLevel,
message: args.message,
timeoutMillis: DEFAULT_AUTO_DISMISS_TIMEOUT_MILLIS,
Expand All @@ -285,7 +285,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
console.error(`Unexpected ev.data: ${JSON.stringify(ev.data)}`);
break;
}
}, [postPopup]);
}, [postPopUp]);

const exportLogs = useCallback(() => {
if (null === mainWorkerRef.current) {
Expand Down
6 changes: 3 additions & 3 deletions new-log-viewer/src/typings/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {LOG_LEVEL} from "./logs";


/**
* Contents of popup messages and its associated auto dismiss timeout.
* Contents of pop-up messages and its associated auto dismiss timeout.
*/
interface PopupMessage {
interface PopUpMessage {
level: LOG_LEVEL,
message: string,
timeoutMillis: number,
Expand All @@ -22,7 +22,7 @@ const DO_NOT_TIMEOUT_VALUE = 0;
const DEFAULT_AUTO_DISMISS_TIMEOUT_MILLIS = 10_000;


export type {PopupMessage};
export type {PopUpMessage};
export {
DEFAULT_AUTO_DISMISS_TIMEOUT_MILLIS,
DO_NOT_TIMEOUT_VALUE,
Expand Down

0 comments on commit 189be81

Please sign in to comment.