Skip to content

Commit

Permalink
feat(nest): add create nest popover
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmanelli committed Nov 13, 2024
1 parent 37b640e commit 8a75c56
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 116 deletions.
4 changes: 2 additions & 2 deletions proto/api/v1/nest_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ service NestService {
rpc CreateNest(CreateNestRequest) returns (Nest) {
option (google.api.http) = {
post: "/api/v1/nests"
body: "nest"
body: "uid"
};
}
// ListNests lists all nests.
Expand Down Expand Up @@ -61,7 +61,7 @@ message Nest {
}

message CreateNestRequest {
Nest nest = 1;
string uid = 1;
}

message ListNestsRequest {
Expand Down
211 changes: 104 additions & 107 deletions proto/gen/api/v1/nest_service.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions proto/gen/api/v1/nest_service.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/gen/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,11 @@ paths:
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: nest
- name: uid
in: body
required: true
schema:
$ref: '#/definitions/v1Nest'
type: string
tags:
- NestService
/api/v1/nests:by-uid/{uid}:
Expand Down
2 changes: 1 addition & 1 deletion server/router/api/v1/nest_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *APIV1Service) CreateNest(ctx context.Context, request *v1pb.CreateNestR

create := &store.Nest{
CreatorID: user.ID,
UID: request.Nest.Name,
UID: request.Uid,
}

nest, err := s.Store.CreateNest(ctx, create)
Expand Down
56 changes: 56 additions & 0 deletions web/src/components/AddNestPopover.tsx
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
5 changes: 3 additions & 2 deletions web/src/components/NestBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useCurrentUser from "@/hooks/useCurrentUser";
import { useCommonContext } from "@/layouts/CommonContextProvider";
import NestIcon from "./NestIcon";
import { useNestList, useNestStore } from "@/store/v1";
import { Nest } from "@/types/proto/api/v1/nest_service";
import AddNestPopover from "./AddNestPopover";

interface Props {
collapsed?: boolean;
Expand All @@ -22,7 +22,7 @@ const NestBanner = (props: Props) => {
};

return (
<div className="relative w-full h-auto px-1 shrink-0">
<div className="flex flex-row justify-between items-center">
<Dropdown>
<MenuButton disabled={!user} slots={{ root: "div" }}>
<div
Expand All @@ -45,6 +45,7 @@ const NestBanner = (props: Props) => {
))}
</Menu>
</Dropdown>
<AddNestPopover/>
</div>
);
};
Expand Down
3 changes: 3 additions & 0 deletions web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
"no-memos-found": "No memos found",
"search-placeholder": "Search content"
},
"nest": {
"add-nest": "Add nest"
},
"resource": {
"clear": "Clear",
"copy-link": "Copy Link",
Expand Down

0 comments on commit 8a75c56

Please sign in to comment.