mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-21 05:12:23 +00:00
actually import data to backend
This commit is contained in:
parent
b2933a5af6
commit
e60b5ce015
2 changed files with 35 additions and 7 deletions
|
|
@ -282,6 +282,7 @@
|
||||||
"exportedOn": "Exported on",
|
"exportedOn": "Exported on",
|
||||||
"button": {
|
"button": {
|
||||||
"import": "Import data",
|
"import": "Import data",
|
||||||
|
"processing": "Processing...",
|
||||||
"success": "Import complete",
|
"success": "Import complete",
|
||||||
"home": "Continue to home"
|
"home": "Continue to home"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { Stepper } from "@/components/layout/Stepper";
|
||||||
import { CenterContainer } from "@/components/layout/ThinContainer";
|
import { CenterContainer } from "@/components/layout/ThinContainer";
|
||||||
import { Divider } from "@/components/utils/Divider";
|
import { Divider } from "@/components/utils/Divider";
|
||||||
import { Heading2, Paragraph } from "@/components/utils/Text";
|
import { Heading2, Paragraph } from "@/components/utils/Text";
|
||||||
|
import { useAuth } from "@/hooks/auth/useAuth";
|
||||||
import { MinimalPageLayout } from "@/pages/layouts/MinimalPageLayout";
|
import { MinimalPageLayout } from "@/pages/layouts/MinimalPageLayout";
|
||||||
import { PageTitle } from "@/pages/parts/util/PageTitle";
|
import { PageTitle } from "@/pages/parts/util/PageTitle";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
|
@ -33,6 +34,7 @@ export function MigrationUploadPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const user = useAuthStore();
|
const user = useAuthStore();
|
||||||
|
const { importData } = useAuth();
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const replaceBookmarks = useBookmarkStore((s) => s.replaceBookmarks);
|
const replaceBookmarks = useBookmarkStore((s) => s.replaceBookmarks);
|
||||||
const replaceProgress = useProgressStore((s) => s.replaceItems);
|
const replaceProgress = useProgressStore((s) => s.replaceItems);
|
||||||
|
|
@ -132,7 +134,13 @@ export function MigrationUploadPage() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = useCallback(() => {
|
const handleImport = useCallback(() => {
|
||||||
if (!uploadedData) return;
|
if (status === "processing") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!uploadedData || !user.account) return;
|
||||||
|
|
||||||
|
setStatus("processing");
|
||||||
|
|
||||||
if (uploadedData.bookmarks) {
|
if (uploadedData.bookmarks) {
|
||||||
replaceBookmarks(uploadedData.bookmarks);
|
replaceBookmarks(uploadedData.bookmarks);
|
||||||
|
|
@ -142,10 +150,26 @@ export function MigrationUploadPage() {
|
||||||
replaceProgress(uploadedData.progress);
|
replaceProgress(uploadedData.progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user profile data is available in the uploaded data, we could update that too
|
importData(
|
||||||
|
user.account,
|
||||||
setStatus("success");
|
uploadedData.progress || {},
|
||||||
}, [replaceBookmarks, replaceProgress, uploadedData]);
|
uploadedData.bookmarks || {},
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
setStatus("success");
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error importing data:", error);
|
||||||
|
setStatus("error");
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
replaceBookmarks,
|
||||||
|
replaceProgress,
|
||||||
|
uploadedData,
|
||||||
|
user.account,
|
||||||
|
importData,
|
||||||
|
status,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MinimalPageLayout>
|
<MinimalPageLayout>
|
||||||
|
|
@ -206,7 +230,7 @@ export function MigrationUploadPage() {
|
||||||
|
|
||||||
{status === "processing" && (
|
{status === "processing" && (
|
||||||
<div className="flex items-center gap-2 text-sm text-green-400">
|
<div className="flex items-center gap-2 text-sm text-green-400">
|
||||||
<Icon icon={Icons.CLOCK} className="animate-spin pr-2" />
|
<Icon icon={Icons.CLOCK} className="pr-2" />
|
||||||
{t("migration.upload.status.processing")}
|
{t("migration.upload.status.processing")}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -269,9 +293,12 @@ export function MigrationUploadPage() {
|
||||||
className="w-full max-w-xs"
|
className="w-full max-w-xs"
|
||||||
theme="purple"
|
theme="purple"
|
||||||
padding="md:px-12 p-2.5"
|
padding="md:px-12 p-2.5"
|
||||||
|
disabled={status === "processing"}
|
||||||
>
|
>
|
||||||
<Icon icon={Icons.CLOUD_ARROW_UP} className="pr-2" />
|
<Icon icon={Icons.CLOUD_ARROW_UP} className="pr-2" />
|
||||||
{t("migration.upload.button.import")}
|
{status === "processing"
|
||||||
|
? t("migration.upload.button.processing")
|
||||||
|
: t("migration.upload.button.import")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue