-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37b640e
commit 8a75c56
Showing
8 changed files
with
173 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Input } from "@mui/joy"; | ||
import { Button } from "@usememos/mui"; | ||
import { PlusIcon } from "lucide-react"; | ||
import { useState } from "react"; | ||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/Popover"; | ||
import { useTranslate } from "@/utils/i18n"; | ||
import { useNestStore } from "@/store/v1"; | ||
import { useCommonContext } from "@/layouts/CommonContextProvider"; | ||
|
||
const AddNestPopover = () => { | ||
const t = useTranslate(); | ||
const nestStore = useNestStore(); | ||
const [popoverOpen, setPopoverOpen] = useState<boolean>(false); | ||
const [nestUID, setNestUID] = useState<string>(""); | ||
const commonContext = useCommonContext(); | ||
|
||
const addNest = async () => { | ||
const nest = await nestStore.createNest({ | ||
uid: nestUID | ||
}) | ||
if (nest) { | ||
await nestStore.fetchNests(); | ||
commonContext.setNest(nest.name); | ||
} | ||
setPopoverOpen(false); | ||
setNestUID(""); | ||
}; | ||
|
||
return ( | ||
<Popover open={popoverOpen} onOpenChange={setPopoverOpen}> | ||
<PopoverTrigger className="w-9"> | ||
<Button className="flex items-center justify-center" size="sm" variant="plain" asChild> | ||
<PlusIcon className="w-5 h-5 mx-auto p-0" /> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent align="center"> | ||
<div className="w-[16rem] flex flex-col justify-start items-start"> | ||
<Input | ||
className="w-full" | ||
size="md" | ||
placeholder={t("nest.add-nest")} | ||
value={nestUID} | ||
onChange={(e) => setNestUID(e.target.value.trim())} | ||
/> | ||
<div className="mt-2 w-full flex flex-row justify-end items-center gap-2"> | ||
<Button size="sm" color="primary" onClick={addNest} disabled={nestUID.length === 0}> | ||
{t("common.add")} | ||
</Button> | ||
</div> | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default AddNestPopover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters