Change timeline view bounds; add remote copy to DB Admin page
This commit is contained in:
parent
2c3a2b520f
commit
613d6f3f32
@ -7,7 +7,7 @@ async function fetchDays(view: string, dateQuery: string) {
|
|||||||
const timezone = await api.users.getTimezone();
|
const timezone = await api.users.getTimezone();
|
||||||
|
|
||||||
const today = spacetime(dateQuery ?? "today");
|
const today = spacetime(dateQuery ?? "today");
|
||||||
const firstDay = today.subtract(3, "day").last("week").startOf("week");
|
const firstDay = today.subtract(2, "week").startOf("week");
|
||||||
|
|
||||||
const days = [];
|
const days = [];
|
||||||
for (let i = 0; i < 20; i++) {
|
for (let i = 0; i < 20; i++) {
|
||||||
|
|||||||
@ -1,17 +1,13 @@
|
|||||||
"use client"; // Mark as client component
|
"use client"; // Mark as client component
|
||||||
|
|
||||||
import { Separator } from "@radix-ui/react-dropdown-menu";
|
import { Separator } from "@radix-ui/react-dropdown-menu";
|
||||||
import { useState } from "react";
|
import { Dispatch, useState } from "react";
|
||||||
|
|
||||||
export default function DatabaseSettings() {
|
export default function DatabaseSettings() {
|
||||||
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
||||||
|
const [remoteCopyStatus, setRemoteCopyStatus] = useState<string | null>(null);
|
||||||
|
|
||||||
// Handle form submission
|
const uploadDB = async (formData: FormData, setStatus: Dispatch<string>) => {
|
||||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
|
||||||
event.preventDefault(); // Prevent default form submission
|
|
||||||
|
|
||||||
const formData = new FormData(event.currentTarget);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/db/upload", {
|
const response = await fetch("/api/db/upload", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -19,15 +15,57 @@ export default function DatabaseSettings() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setUploadStatus("Database uploaded successfully!");
|
setStatus("Database uploaded successfully!");
|
||||||
} else {
|
} else {
|
||||||
const error = await response.json();
|
const error = await response.json();
|
||||||
setUploadStatus(error.message || "An error occurred during upload.");
|
setStatus(error.message || "An error occurred during upload.");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error uploading the database:", error);
|
console.error("Error uploading the database:", error);
|
||||||
setUploadStatus("An error occurred during upload.");
|
setStatus("An error occurred during upload.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle form submission
|
||||||
|
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault(); // Prevent default form submission
|
||||||
|
|
||||||
|
const formData = new FormData(event.currentTarget);
|
||||||
|
uploadDB(formData, setUploadStatus);
|
||||||
|
};
|
||||||
|
|
||||||
|
const remoteCopy = async () => {
|
||||||
|
|
||||||
|
const remoteUrl = "https://lifetracker.ryanpandya.com/api/db/download";
|
||||||
|
|
||||||
|
setRemoteCopyStatus("Downloading...");
|
||||||
|
const download = await fetch(remoteUrl);
|
||||||
|
if (!download.ok) {
|
||||||
|
throw new Error(`Failed to fetch from ${remoteUrl}: ${download.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dbData = await download.blob();
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('sqliteFile', dbData, 'remoteDB-file.db');
|
||||||
|
uploadDB(formData, setRemoteCopyStatus);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const response = await fetch("/api/db/upload", {
|
||||||
|
// method: "POST",
|
||||||
|
// body: formData,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (response.ok) {
|
||||||
|
// setUploadStatus("Database uploaded successfully!");
|
||||||
|
// } else {
|
||||||
|
// const error = await response.json();
|
||||||
|
// setUploadStatus(error.message || "An error occurred during upload.");
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Error uploading the database:", error);
|
||||||
|
// setUploadStatus("An error occurred during upload.");
|
||||||
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -45,7 +83,7 @@ export default function DatabaseSettings() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-8 flex w-full flex-col sm:flex-row">
|
<div className="mb-2 flex w-full flex-col sm:flex-row">
|
||||||
<div className="mb-4 w-full text-lg font-medium sm:w-1/3">
|
<div className="mb-4 w-full text-lg font-medium sm:w-1/3">
|
||||||
Download SQLite Database
|
Download SQLite Database
|
||||||
</div>
|
</div>
|
||||||
@ -57,6 +95,19 @@ export default function DatabaseSettings() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{process.env.NODE_ENV === 'development' ?
|
||||||
|
<div className="mb-2 flex w-full flex-col sm:flex-row">
|
||||||
|
<div className="mb-4 w-full text-lg font-medium sm:w-1/3">
|
||||||
|
Copy from Remote URL
|
||||||
|
</div>
|
||||||
|
<div className="w-full">
|
||||||
|
<div className="mb-2">
|
||||||
|
<button onClick={remoteCopy}>Copy</button>
|
||||||
|
{remoteCopyStatus && <p>{remoteCopyStatus}</p>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
: ""}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user