Skip to content

Commit 5f47eb7

Browse files
authored
Merge pull request #363 from StubberG3/balancer/319/publication-dates
bugfix: #319 - Fix yesterday's date issue for publication date
2 parents e1605c2 + 454133c commit 5f47eb7

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

frontend/src/pages/Files/FileRow.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ const FileRow: React.FC<FileRowProps> = ({
8484
setIsEditing(false);
8585
};
8686

87+
const formatUTCDate = (dateStr: string | null) => {
88+
if (!dateStr) return "N/A";
89+
const formatter = new Intl.DateTimeFormat("en-US", {
90+
timeZone: "UTC",
91+
year: "numeric",
92+
month: "numeric",
93+
day: "numeric"
94+
});
95+
const formattedDate = formatter.format(new Date(dateStr));
96+
return formattedDate;
97+
}
98+
8799
return (
88100
<li className="border-b p-4">
89101
{isEditing ? (
@@ -187,7 +199,7 @@ const FileRow: React.FC<FileRowProps> = ({
187199
<div className="w-full">
188200
<p>
189201
<strong>Publication Date:</strong>{" "}
190-
{isEditing ? (
202+
{isEditing ?
191203
<input
192204
type="date"
193205
value={publicationDate || ''}
@@ -196,15 +208,7 @@ const FileRow: React.FC<FileRowProps> = ({
196208
disabled={loading}
197209
placeholder="Publication Date"
198210
/>
199-
) : (
200-
file.publication_date
201-
? new Intl.DateTimeFormat("en-US", {
202-
year: "numeric",
203-
month: "2-digit",
204-
day: "2-digit"
205-
}).format(new Date(file.publication_date))
206-
: "N/A"
207-
)}
211+
: formatUTCDate(file.publication_date)}
208212
</p>
209213
</div>
210214
</div>

frontend/src/pages/Files/ListOfFiles.tsx

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect } from "react";
2-
import axios from "axios";
2+
import { api } from "../../api/apiClient";
33
import Layout from "../Layout/Layout";
44
import FileRow from "./FileRow";
55
import Table from "../../components/Table/Table";
@@ -30,17 +30,17 @@ const ListOfFiles: React.FC<{ showTable?: boolean }> = ({
3030
const [downloading, setDownloading] = useState<string | null>(null);
3131
const [opening, setOpening] = useState<string | null>(null);
3232

33+
const baseUrl = import.meta.env.VITE_API_BASE_URL;
34+
3335
useEffect(() => {
3436
const fetchFiles = async () => {
3537
try {
36-
const baseUrl = import.meta.env.VITE_API_BASE_URL;
37-
const response = await axios.get(`${baseUrl}/v1/api/uploadFile`, {
38-
headers: {
39-
Authorization: `JWT ${localStorage.getItem("access")}`,
40-
},
41-
});
42-
if (Array.isArray(response.data)) {
43-
setFiles(response.data);
38+
const url = `${baseUrl}/v1/api/uploadFile`;
39+
40+
const { data } = await api.get(url);
41+
42+
if (Array.isArray(data)) {
43+
setFiles(data);
4444
}
4545
} catch (error) {
4646
console.error("Error fetching files", error);
@@ -50,7 +50,7 @@ const ListOfFiles: React.FC<{ showTable?: boolean }> = ({
5050
};
5151

5252
fetchFiles();
53-
}, []);
53+
}, [baseUrl]);
5454

5555
const updateFileName = (guid: string, updatedFile: Partial<File>) => {
5656
setFiles((prevFiles) =>
@@ -63,15 +63,9 @@ const ListOfFiles: React.FC<{ showTable?: boolean }> = ({
6363
const handleDownload = async (guid: string, fileName: string) => {
6464
try {
6565
setDownloading(guid);
66-
const baseUrl = import.meta.env.VITE_API_BASE_URL;
67-
const response = await axios.get(`${baseUrl}/v1/api/uploadFile/${guid}`, {
68-
headers: {
69-
Authorization: `JWT ${localStorage.getItem("access")}`,
70-
},
71-
responseType: "blob",
72-
});
66+
const { data } = await api.get(`/v1/api/uploadFile/${guid}`, { responseType: 'blob' });
7367

74-
const url = window.URL.createObjectURL(new Blob([response.data]));
68+
const url = window.URL.createObjectURL(new Blob([data]));
7569
const link = document.createElement("a");
7670
link.href = url;
7771
link.setAttribute("download", fileName);
@@ -90,15 +84,9 @@ const ListOfFiles: React.FC<{ showTable?: boolean }> = ({
9084
const handleOpen = async (guid: string) => {
9185
try {
9286
setOpening(guid);
93-
const baseUrl = import.meta.env.VITE_API_BASE_URL;
94-
const response = await axios.get(`${baseUrl}/v1/api/uploadFile/${guid}`, {
95-
headers: {
96-
Authorization: `JWT ${localStorage.getItem("access")}`,
97-
},
98-
responseType: "arraybuffer",
99-
});
87+
const { data } = await api.get(`/v1/api/uploadFile/${guid}`, { responseType: 'arraybuffer' });
10088

101-
const file = new Blob([response.data], { type: 'application/pdf' });
89+
const file = new Blob([data], { type: 'application/pdf' });
10290
const fileURL = window.URL.createObjectURL(file);
10391
window.open(fileURL);
10492
} catch (error) {
@@ -118,17 +106,24 @@ const ListOfFiles: React.FC<{ showTable?: boolean }> = ({
118106
{ Header: 'Date Published', accessor: 'publication_date' },
119107
{ Header: '', accessor: 'file_open' },
120108
];
109+
110+
const formatUTCDate = (dateStr: string | null) => {
111+
if (!dateStr) return "N/A";
112+
const formatter = new Intl.DateTimeFormat("en-US", {
113+
timeZone: "UTC",
114+
year: "numeric",
115+
month: "numeric",
116+
day: "numeric"
117+
});
118+
const formattedDate = formatter.format(new Date(dateStr));
119+
return formattedDate;
120+
}
121+
121122
const data = files.map((file) => (
122123
{
123124
file_name: file?.title || file.file_name.replace(/\.[^/.]+$/, ""),
124125
publication: file?.publication || '',
125-
publication_date: file.publication_date
126-
? new Intl.DateTimeFormat("en-US", {
127-
year: "numeric",
128-
month: "2-digit",
129-
day: "2-digit"
130-
}).format(new Date(file.publication_date))
131-
: "",
126+
publication_date: formatUTCDate(file.publication_date),
132127
file_open:
133128
<a
134129
key={file.guid}

0 commit comments

Comments
 (0)