Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

attachments_ui: Fix TypeScript noUncheckedIndexedAccess errors.

Anders Kaseorg01677db59e8e
diff --git a/web/src/attachments_ui.ts b/web/src/attachments_ui.ts
index c318f0740f9..a2e03b0b7d6 100644
--- a/web/src/attachments_ui.ts
+++ b/web/src/attachments_ui.ts
@@ -167,12 +167,12 @@ function render_attachments_ui(): void {
scroll_util.reset_scrollbar($uploaded_files_table.closest(".progressive-table-wrapper"));
}
-function format_attachment_data(new_attachments: ServerAttachment[]): Attachment[] {
- return new_attachments.map((attachment) => ({
+function format_attachment_data(attachment: ServerAttachment): Attachment {
+ return {
...attachment,
create_time_str: timerender.render_now(new Date(attachment.create_time)).time_str,
size_str: bytes_to_size(attachment.size),
- }));
+ };
}
export function update_attachments(event: AttachmentEvent): void {
@@ -184,7 +184,7 @@ export function update_attachments(event: AttachmentEvent): void {
attachments = attachments.filter((a) => a.id !== event.attachment.id);
}
if (event.op === "add" || event.op === "update") {
- attachments.push(format_attachment_data([event.attachment])[0]);
+ attachments.push(format_attachment_data(event.attachment));
}
upload_space_used = event.upload_space_used;
// TODO: This is inefficient and we should be able to do some sort
@@ -213,7 +213,9 @@ export function set_up_attachments(): void {
success(data) {
const clean_data = attachment_api_response_schema.parse(data);
loading.destroy_indicator($("#attachments_loading_indicator"));
- attachments = format_attachment_data(clean_data.attachments);
+ attachments = clean_data.attachments.map((attachment) =>
+ format_attachment_data(attachment),
+ );
upload_space_used = clean_data.upload_space_used;
render_attachments_ui();
},