WIP ESLint fixes
This commit is contained in:
@@ -4,21 +4,21 @@ interface RequestParams {
|
|||||||
uri: string;
|
uri: string;
|
||||||
method: "GET" | "POST" | "DELETE" | "PATCH" | "PUT";
|
method: "GET" | "POST" | "DELETE" | "PATCH" | "PUT";
|
||||||
allowFail?: boolean;
|
allowFail?: boolean;
|
||||||
jsonData?: any;
|
jsonData?: unknown;
|
||||||
formData?: FormData;
|
formData?: FormData;
|
||||||
upProgress?: (progress: number) => void;
|
upProgress?: (progress: number) => void;
|
||||||
downProgress?: (e: { progress: number; total: number }) => void;
|
downProgress?: (e: { progress: number; total: number }) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface APIResponse {
|
interface APIResponse {
|
||||||
data: any;
|
data: unknown;
|
||||||
status: number;
|
status: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
public code: number;
|
public code: number;
|
||||||
public data: number;
|
public data: unknown;
|
||||||
constructor(message: string, code: number, data: any) {
|
constructor(message: string, code: number, data: unknown) {
|
||||||
super(`HTTP status: ${code}\nMessage: ${message}\nData=${data}`);
|
super(`HTTP status: ${code}\nMessage: ${message}\nData=${data}`);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@@ -57,6 +57,7 @@ export class APIClient {
|
|||||||
*/
|
*/
|
||||||
static async exec(args: RequestParams): Promise<APIResponse> {
|
static async exec(args: RequestParams): Promise<APIResponse> {
|
||||||
let body: string | undefined | FormData = undefined;
|
let body: string | undefined | FormData = undefined;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const headers: any = {};
|
const headers: any = {};
|
||||||
|
|
||||||
// JSON request
|
// JSON request
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function MatrixAuthCallback(): React.ReactElement {
|
|||||||
};
|
};
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}, [code, state]);
|
}, [code, info, navigate, snackbar, state]);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { format } from "date-and-time";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get UNIX time
|
* Get UNIX time
|
||||||
*
|
*
|
||||||
@@ -15,3 +17,62 @@ export function time(): number {
|
|||||||
export function timeMs(): number {
|
export function timeMs(): number {
|
||||||
return new Date().getTime();
|
return new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ export class RoomEventsManager {
|
|||||||
|
|
||||||
// Adapt receipts to be event-indexed
|
// Adapt receipts to be event-indexed
|
||||||
this.receiptsEventsMap.clear();
|
this.receiptsEventsMap.clear();
|
||||||
for (const [_userId, receipt] of receiptsUsersMap) {
|
for (const receipt of [...receiptsUsersMap.values()]) {
|
||||||
if (!this.receiptsEventsMap.has(receipt.event_id))
|
if (!this.receiptsEventsMap.has(receipt.event_id))
|
||||||
this.receiptsEventsMap.set(receipt.event_id, [receipt]);
|
this.receiptsEventsMap.set(receipt.event_id, [receipt]);
|
||||||
else this.receiptsEventsMap.get(receipt.event_id)!.push(receipt);
|
else this.receiptsEventsMap.get(receipt.event_id)!.push(receipt);
|
||||||
|
|||||||
@@ -1,65 +1,10 @@
|
|||||||
import { Tooltip } from "@mui/material";
|
import { Tooltip } from "@mui/material";
|
||||||
import { format } from "date-and-time";
|
import {
|
||||||
import { time } from "../utils/DateUtils";
|
formatDateTime,
|
||||||
|
formatDate,
|
||||||
export function formatDateTime(time: number): string {
|
timeDiff,
|
||||||
const t = new Date();
|
timeDiffFromNow,
|
||||||
t.setTime(1000 * time);
|
} from "../utils/DateUtils";
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TimeWidget(p: {
|
export function TimeWidget(p: {
|
||||||
time?: number;
|
time?: number;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default function DashboardSidebar({
|
|||||||
if (!isOverSmViewport) {
|
if (!isOverSmViewport) {
|
||||||
setExpanded(false);
|
setExpanded(false);
|
||||||
}
|
}
|
||||||
}, [expanded, setExpanded, isOverSmViewport]);
|
}, [setExpanded, isOverSmViewport]);
|
||||||
|
|
||||||
const hasDrawerTransitions = isOverSmViewport && isOverMdViewport;
|
const hasDrawerTransitions = isOverSmViewport && isOverMdViewport;
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ export default function DashboardSidebar({
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[expanded, !expanded]
|
[expanded]
|
||||||
);
|
);
|
||||||
|
|
||||||
const sidebarContextValue = React.useMemo(() => {
|
const sidebarContextValue = React.useMemo(() => {
|
||||||
@@ -168,7 +168,7 @@ export default function DashboardSidebar({
|
|||||||
fullyExpanded: isFullyExpanded,
|
fullyExpanded: isFullyExpanded,
|
||||||
hasDrawerTransitions,
|
hasDrawerTransitions,
|
||||||
};
|
};
|
||||||
}, [handlePageItemClick, !expanded, isFullyExpanded, hasDrawerTransitions]);
|
}, [handlePageItemClick, isFullyExpanded, hasDrawerTransitions]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardSidebarContext.Provider value={sidebarContextValue}>
|
<DashboardSidebarContext.Provider value={sidebarContextValue}>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export function MainMessageWidget(): React.ReactElement {
|
|||||||
ready={!!rooms && !!users}
|
ready={!!rooms && !!users}
|
||||||
errMsg="Failed to initialize messaging component!"
|
errMsg="Failed to initialize messaging component!"
|
||||||
build={() => (
|
build={() => (
|
||||||
<_MainMessageWidget
|
<MainMessageWidgetInner
|
||||||
rooms={rooms!}
|
rooms={rooms!}
|
||||||
users={users!}
|
users={users!}
|
||||||
onRoomsListUpdate={(cb) => setRooms((r) => cb(r!))}
|
onRoomsListUpdate={(cb) => setRooms((r) => cb(r!))}
|
||||||
@@ -53,7 +53,7 @@ export function MainMessageWidget(): React.ReactElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _MainMessageWidget(p: {
|
function MainMessageWidgetInner(p: {
|
||||||
rooms: Room[];
|
rooms: Room[];
|
||||||
users: UsersMap;
|
users: UsersMap;
|
||||||
onRoomsListUpdate: (cb: (a: Room[]) => Room[]) => void;
|
onRoomsListUpdate: (cb: (a: Room[]) => Room[]) => void;
|
||||||
@@ -79,7 +79,7 @@ function _MainMessageWidget(p: {
|
|||||||
[p.rooms]
|
[p.rooms]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [_refreshCount, setRefreshCount] = React.useState(0);
|
const setRefreshCount = React.useState(0)[1];
|
||||||
const [roomMgr, setRoomMgr] = React.useState<undefined | RoomEventsManager>();
|
const [roomMgr, setRoomMgr] = React.useState<undefined | RoomEventsManager>();
|
||||||
|
|
||||||
const loadRoom = async () => {
|
const loadRoom = async () => {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export function MatrixWS(p: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return () => ws.close();
|
return () => ws.close();
|
||||||
}, [connCount]);
|
}, [connCount, snackbar]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title={state}>
|
<Tooltip title={state}>
|
||||||
|
|||||||
@@ -49,10 +49,11 @@ export function RoomMessagesList(p: {
|
|||||||
const messagesEndRef = React.createRef<HTMLDivElement>();
|
const messagesEndRef = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
// Automatically scroll to bottom when number of messages change
|
// Automatically scroll to bottom when number of messages change
|
||||||
|
const lastEventId = p.manager.messages.at(-1)?.event_id;
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (messagesEndRef)
|
if (messagesEndRef)
|
||||||
messagesEndRef.current?.scrollIntoView({ behavior: "instant" });
|
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
|
// Watch scroll to detect when user reach the top to load older messages
|
||||||
const handleScroll = async () => {
|
const handleScroll = async () => {
|
||||||
@@ -185,7 +186,7 @@ function RoomMessage(p: {
|
|||||||
try {
|
try {
|
||||||
await MatrixApiEvent.DeleteEvent(p.room, p.message.event_id);
|
await MatrixApiEvent.DeleteEvent(p.room, p.message.event_id);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Failed to delete message!`, e),
|
console.error(`Failed to delete message!`, e);
|
||||||
alert(`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) &&
|
p.manager.typingUsers.includes(u.user_id) &&
|
||||||
u.user_id !== user.info.matrix_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 <></>;
|
if (users.length === 0) return <></>;
|
||||||
|
|||||||
Reference in New Issue
Block a user