mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-16 12:23:12 +00:00
feat: allow to create shortcut if not found
This commit is contained in:
parent
85848ee317
commit
95f1570796
@ -1,15 +1,23 @@
|
||||
import { Button } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useParams } from "react-router-dom";
|
||||
import CreateShortcutDrawer from "@/components/CreateShortcutDrawer";
|
||||
import { isURL } from "@/helpers/utils";
|
||||
import useNavigateTo from "@/hooks/useNavigateTo";
|
||||
import useShortcutStore from "@/stores/v1/shortcut";
|
||||
import useUserStore from "@/stores/v1/user";
|
||||
import { Shortcut } from "@/types/proto/api/v2/shortcut_service";
|
||||
|
||||
const ShortcutSpace = () => {
|
||||
const params = useParams();
|
||||
const shortcutName = params["*"] || "";
|
||||
const navigateTo = useNavigateTo();
|
||||
const userStore = useUserStore();
|
||||
const currentUser = userStore.getCurrentUser();
|
||||
const shortcutStore = useShortcutStore();
|
||||
const [shortcut, setShortcut] = useState<Shortcut>();
|
||||
const [showCreateShortcutDrawer, setShowCreateShortcutDrawer] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
@ -24,15 +32,40 @@ const ShortcutSpace = () => {
|
||||
}, [shortcutName]);
|
||||
|
||||
if (!shortcut) {
|
||||
return null;
|
||||
if (!currentUser) {
|
||||
navigateTo("/404");
|
||||
return null;
|
||||
}
|
||||
console.log("currentUser", currentUser);
|
||||
return (
|
||||
<>
|
||||
<div className="w-full h-[100svh] flex flex-col justify-center items-center p-4">
|
||||
<p className="text-xl">
|
||||
Shortcut <span className="font-mono">{shortcutName}</span> Not Found.
|
||||
</p>
|
||||
<div className="mt-4">
|
||||
<Button variant="plain" size="sm" onClick={() => setShowCreateShortcutDrawer(true)}>
|
||||
👉 Click here to create it
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{showCreateShortcutDrawer && (
|
||||
<CreateShortcutDrawer
|
||||
initialShortcut={{ name: shortcutName }}
|
||||
onClose={() => setShowCreateShortcutDrawer(false)}
|
||||
onConfirm={() => navigateTo("/")}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// If shortcut is a URL, redirect to it directly.
|
||||
if (isURL(shortcut.link)) {
|
||||
window.document.title = "Redirecting...";
|
||||
window.location.href = shortcut.link;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Otherwise, render the shortcut link as plain text.
|
||||
return <div>{shortcut.link}</div>;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user