WIP ESLint fixes
This commit is contained in:
@@ -1,65 +1,10 @@
|
||||
import { Tooltip } from "@mui/material";
|
||||
import { format } from "date-and-time";
|
||||
import { time } from "../utils/DateUtils";
|
||||
|
||||
export function formatDateTime(time: number): string {
|
||||
const t = new Date();
|
||||
t.setTime(1000 * time);
|
||||
return format(t, "DD/MM/YYYY HH:mm:ss");
|
||||
}
|
||||
|
||||
export function formatDate(time: number): string {
|
||||
const t = new Date();
|
||||
t.setTime(1000 * time);
|
||||
return format(t, "DD/MM/YYYY");
|
||||
}
|
||||
|
||||
export function timeDiff(a: number, b: number): string {
|
||||
let diff = b - a;
|
||||
|
||||
if (diff === 0) return "now";
|
||||
if (diff === 1) return "1 second";
|
||||
|
||||
if (diff < 60) {
|
||||
return `${diff} seconds`;
|
||||
}
|
||||
|
||||
diff = Math.floor(diff / 60);
|
||||
|
||||
if (diff === 1) return "1 minute";
|
||||
if (diff < 60) {
|
||||
return `${diff} minutes`;
|
||||
}
|
||||
|
||||
diff = Math.floor(diff / 60);
|
||||
|
||||
if (diff === 1) return "1 hour";
|
||||
if (diff < 24) {
|
||||
return `${diff} hours`;
|
||||
}
|
||||
|
||||
const diffDays = Math.floor(diff / 24);
|
||||
|
||||
if (diffDays === 1) return "1 day";
|
||||
if (diffDays < 31) {
|
||||
return `${diffDays} days`;
|
||||
}
|
||||
|
||||
diff = Math.floor(diffDays / 31);
|
||||
|
||||
if (diff < 12) {
|
||||
return `${diff} month`;
|
||||
}
|
||||
|
||||
const diffYears = Math.floor(diffDays / 365);
|
||||
|
||||
if (diffYears === 1) return "1 year";
|
||||
return `${diffYears} years`;
|
||||
}
|
||||
|
||||
export function timeDiffFromNow(t: number): string {
|
||||
return timeDiff(t, time());
|
||||
}
|
||||
import {
|
||||
formatDateTime,
|
||||
formatDate,
|
||||
timeDiff,
|
||||
timeDiffFromNow,
|
||||
} from "../utils/DateUtils";
|
||||
|
||||
export function TimeWidget(p: {
|
||||
time?: number;
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function DashboardSidebar({
|
||||
if (!isOverSmViewport) {
|
||||
setExpanded(false);
|
||||
}
|
||||
}, [expanded, setExpanded, isOverSmViewport]);
|
||||
}, [setExpanded, isOverSmViewport]);
|
||||
|
||||
const hasDrawerTransitions = isOverSmViewport && isOverMdViewport;
|
||||
|
||||
@@ -159,7 +159,7 @@ export default function DashboardSidebar({
|
||||
},
|
||||
};
|
||||
},
|
||||
[expanded, !expanded]
|
||||
[expanded]
|
||||
);
|
||||
|
||||
const sidebarContextValue = React.useMemo(() => {
|
||||
@@ -168,7 +168,7 @@ export default function DashboardSidebar({
|
||||
fullyExpanded: isFullyExpanded,
|
||||
hasDrawerTransitions,
|
||||
};
|
||||
}, [handlePageItemClick, !expanded, isFullyExpanded, hasDrawerTransitions]);
|
||||
}, [handlePageItemClick, isFullyExpanded, hasDrawerTransitions]);
|
||||
|
||||
return (
|
||||
<DashboardSidebarContext.Provider value={sidebarContextValue}>
|
||||
|
||||
@@ -43,7 +43,7 @@ export function MainMessageWidget(): React.ReactElement {
|
||||
ready={!!rooms && !!users}
|
||||
errMsg="Failed to initialize messaging component!"
|
||||
build={() => (
|
||||
<_MainMessageWidget
|
||||
<MainMessageWidgetInner
|
||||
rooms={rooms!}
|
||||
users={users!}
|
||||
onRoomsListUpdate={(cb) => setRooms((r) => cb(r!))}
|
||||
@@ -53,7 +53,7 @@ export function MainMessageWidget(): React.ReactElement {
|
||||
);
|
||||
}
|
||||
|
||||
function _MainMessageWidget(p: {
|
||||
function MainMessageWidgetInner(p: {
|
||||
rooms: Room[];
|
||||
users: UsersMap;
|
||||
onRoomsListUpdate: (cb: (a: Room[]) => Room[]) => void;
|
||||
@@ -79,7 +79,7 @@ function _MainMessageWidget(p: {
|
||||
[p.rooms]
|
||||
);
|
||||
|
||||
const [_refreshCount, setRefreshCount] = React.useState(0);
|
||||
const setRefreshCount = React.useState(0)[1];
|
||||
const [roomMgr, setRoomMgr] = React.useState<undefined | RoomEventsManager>();
|
||||
|
||||
const loadRoom = async () => {
|
||||
|
||||
@@ -75,7 +75,7 @@ export function MatrixWS(p: {
|
||||
};
|
||||
|
||||
return () => ws.close();
|
||||
}, [connCount]);
|
||||
}, [connCount, snackbar]);
|
||||
|
||||
return (
|
||||
<Tooltip title={state}>
|
||||
|
||||
@@ -49,10 +49,11 @@ export function RoomMessagesList(p: {
|
||||
const messagesEndRef = React.createRef<HTMLDivElement>();
|
||||
|
||||
// Automatically scroll to bottom when number of messages change
|
||||
const lastEventId = p.manager.messages.at(-1)?.event_id;
|
||||
React.useEffect(() => {
|
||||
if (messagesEndRef)
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: "instant" });
|
||||
}, [p.manager.messages.at(-1)?.event_id]);
|
||||
}, [lastEventId, messagesEndRef]);
|
||||
|
||||
// Watch scroll to detect when user reach the top to load older messages
|
||||
const handleScroll = async () => {
|
||||
@@ -185,8 +186,8 @@ function RoomMessage(p: {
|
||||
try {
|
||||
await MatrixApiEvent.DeleteEvent(p.room, p.message.event_id);
|
||||
} catch (e) {
|
||||
console.error(`Failed to delete message!`, e),
|
||||
alert(`Failed to delete message!${e}`);
|
||||
console.error(`Failed to delete message!`, e);
|
||||
alert(`Failed to delete message!${e}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export function TypingNotice(p: {
|
||||
p.manager.typingUsers.includes(u.user_id) &&
|
||||
u.user_id !== user.info.matrix_user_id
|
||||
),
|
||||
[p.manager.typingUsers]
|
||||
[p.manager.typingUsers, p.users, user.info.matrix_user_id]
|
||||
);
|
||||
|
||||
if (users.length === 0) return <></>;
|
||||
|
||||
Reference in New Issue
Block a user