Commit 64b27d5a authored by Steven's avatar Steven

refactor: shortcut service

parent 6964c1df
syntax = "proto3";
package memos.api.v1;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
option go_package = "gen/api/v1";
service ShortcutService {
// ListShortcuts returns a list of shortcuts for a user.
rpc ListShortcuts(ListShortcutsRequest) returns (ListShortcutsResponse) {
option (google.api.http) = {get: "/api/v1/{parent=users/*}/shortcuts"};
option (google.api.method_signature) = "parent";
}
// CreateShortcut creates a new shortcut for a user.
rpc CreateShortcut(CreateShortcutRequest) returns (Shortcut) {
option (google.api.http) = {
post: "/api/v1/{parent=users/*}/shortcuts"
body: "shortcut"
};
option (google.api.method_signature) = "parent,shortcut";
}
// UpdateShortcut updates a shortcut for a user.
rpc UpdateShortcut(UpdateShortcutRequest) returns (Shortcut) {
option (google.api.http) = {
patch: "/api/v1/{parent=users/*}/shortcuts/{shortcut.id}"
body: "shortcut"
};
option (google.api.method_signature) = "parent,shortcut,update_mask";
}
// DeleteShortcut deletes a shortcut for a user.
rpc DeleteShortcut(DeleteShortcutRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {delete: "/api/v1/{parent=users/*}/shortcuts/{id}"};
option (google.api.method_signature) = "parent,id";
}
}
message Shortcut {
string id = 1;
string title = 2;
string filter = 3;
}
message ListShortcutsRequest {
// The name of the user.
string parent = 1;
}
message ListShortcutsResponse {
repeated Shortcut shortcuts = 1;
}
message CreateShortcutRequest {
// The name of the user.
string parent = 1;
Shortcut shortcut = 2;
bool validate_only = 3;
}
message UpdateShortcutRequest {
// The name of the user.
string parent = 1;
Shortcut shortcut = 2;
google.protobuf.FieldMask update_mask = 3;
}
message DeleteShortcutRequest {
// The name of the user.
string parent = 1;
// The id of the shortcut.
string id = 2;
}
...@@ -94,32 +94,6 @@ service UserService { ...@@ -94,32 +94,6 @@ service UserService {
option (google.api.http) = {delete: "/api/v1/{name=users/*}/access_tokens/{access_token}"}; option (google.api.http) = {delete: "/api/v1/{name=users/*}/access_tokens/{access_token}"};
option (google.api.method_signature) = "name,access_token"; option (google.api.method_signature) = "name,access_token";
} }
// ListShortcuts returns a list of shortcuts for a user.
rpc ListShortcuts(ListShortcutsRequest) returns (ListShortcutsResponse) {
option (google.api.http) = {get: "/api/v1/{parent=users/*}/shortcuts"};
option (google.api.method_signature) = "parent";
}
// CreateShortcut creates a new shortcut for a user.
rpc CreateShortcut(CreateShortcutRequest) returns (Shortcut) {
option (google.api.http) = {
post: "/api/v1/{parent=users/*}/shortcuts"
body: "shortcut"
};
option (google.api.method_signature) = "parent,shortcut";
}
// UpdateShortcut updates a shortcut for a user.
rpc UpdateShortcut(UpdateShortcutRequest) returns (Shortcut) {
option (google.api.http) = {
patch: "/api/v1/{parent=users/*}/shortcuts/{shortcut.id}"
body: "shortcut"
};
option (google.api.method_signature) = "parent,shortcut,update_mask";
}
// DeleteShortcut deletes a shortcut for a user.
rpc DeleteShortcut(DeleteShortcutRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {delete: "/api/v1/{parent=users/*}/shortcuts/{id}"};
option (google.api.method_signature) = "parent,id";
}
} }
message User { message User {
...@@ -288,44 +262,3 @@ message DeleteUserAccessTokenRequest { ...@@ -288,44 +262,3 @@ message DeleteUserAccessTokenRequest {
// access_token is the access token to delete. // access_token is the access token to delete.
string access_token = 2; string access_token = 2;
} }
message Shortcut {
string id = 1;
string title = 2;
string filter = 3;
}
message ListShortcutsRequest {
// The name of the user.
string parent = 1;
}
message ListShortcutsResponse {
repeated Shortcut shortcuts = 1;
}
message CreateShortcutRequest {
// The name of the user.
string parent = 1;
Shortcut shortcut = 2;
bool validate_only = 3;
}
message UpdateShortcutRequest {
// The name of the user.
string parent = 1;
Shortcut shortcut = 2;
google.protobuf.FieldMask update_mask = 3;
}
message DeleteShortcutRequest {
// The name of the user.
string parent = 1;
// The id of the shortcut.
string id = 2;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -35,10 +35,6 @@ const ( ...@@ -35,10 +35,6 @@ const (
UserService_ListUserAccessTokens_FullMethodName = "/memos.api.v1.UserService/ListUserAccessTokens" UserService_ListUserAccessTokens_FullMethodName = "/memos.api.v1.UserService/ListUserAccessTokens"
UserService_CreateUserAccessToken_FullMethodName = "/memos.api.v1.UserService/CreateUserAccessToken" UserService_CreateUserAccessToken_FullMethodName = "/memos.api.v1.UserService/CreateUserAccessToken"
UserService_DeleteUserAccessToken_FullMethodName = "/memos.api.v1.UserService/DeleteUserAccessToken" UserService_DeleteUserAccessToken_FullMethodName = "/memos.api.v1.UserService/DeleteUserAccessToken"
UserService_ListShortcuts_FullMethodName = "/memos.api.v1.UserService/ListShortcuts"
UserService_CreateShortcut_FullMethodName = "/memos.api.v1.UserService/CreateShortcut"
UserService_UpdateShortcut_FullMethodName = "/memos.api.v1.UserService/UpdateShortcut"
UserService_DeleteShortcut_FullMethodName = "/memos.api.v1.UserService/DeleteShortcut"
) )
// UserServiceClient is the client API for UserService service. // UserServiceClient is the client API for UserService service.
...@@ -73,14 +69,6 @@ type UserServiceClient interface { ...@@ -73,14 +69,6 @@ type UserServiceClient interface {
CreateUserAccessToken(ctx context.Context, in *CreateUserAccessTokenRequest, opts ...grpc.CallOption) (*UserAccessToken, error) CreateUserAccessToken(ctx context.Context, in *CreateUserAccessTokenRequest, opts ...grpc.CallOption) (*UserAccessToken, error)
// DeleteUserAccessToken deletes an access token for a user. // DeleteUserAccessToken deletes an access token for a user.
DeleteUserAccessToken(ctx context.Context, in *DeleteUserAccessTokenRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) DeleteUserAccessToken(ctx context.Context, in *DeleteUserAccessTokenRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// ListShortcuts returns a list of shortcuts for a user.
ListShortcuts(ctx context.Context, in *ListShortcutsRequest, opts ...grpc.CallOption) (*ListShortcutsResponse, error)
// CreateShortcut creates a new shortcut for a user.
CreateShortcut(ctx context.Context, in *CreateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error)
// UpdateShortcut updates a shortcut for a user.
UpdateShortcut(ctx context.Context, in *UpdateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error)
// DeleteShortcut deletes a shortcut for a user.
DeleteShortcut(ctx context.Context, in *DeleteShortcutRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
} }
type userServiceClient struct { type userServiceClient struct {
...@@ -231,46 +219,6 @@ func (c *userServiceClient) DeleteUserAccessToken(ctx context.Context, in *Delet ...@@ -231,46 +219,6 @@ func (c *userServiceClient) DeleteUserAccessToken(ctx context.Context, in *Delet
return out, nil return out, nil
} }
func (c *userServiceClient) ListShortcuts(ctx context.Context, in *ListShortcutsRequest, opts ...grpc.CallOption) (*ListShortcutsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListShortcutsResponse)
err := c.cc.Invoke(ctx, UserService_ListShortcuts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userServiceClient) CreateShortcut(ctx context.Context, in *CreateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Shortcut)
err := c.cc.Invoke(ctx, UserService_CreateShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userServiceClient) UpdateShortcut(ctx context.Context, in *UpdateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Shortcut)
err := c.cc.Invoke(ctx, UserService_UpdateShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *userServiceClient) DeleteShortcut(ctx context.Context, in *DeleteShortcutRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, UserService_DeleteShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// UserServiceServer is the server API for UserService service. // UserServiceServer is the server API for UserService service.
// All implementations must embed UnimplementedUserServiceServer // All implementations must embed UnimplementedUserServiceServer
// for forward compatibility. // for forward compatibility.
...@@ -303,14 +251,6 @@ type UserServiceServer interface { ...@@ -303,14 +251,6 @@ type UserServiceServer interface {
CreateUserAccessToken(context.Context, *CreateUserAccessTokenRequest) (*UserAccessToken, error) CreateUserAccessToken(context.Context, *CreateUserAccessTokenRequest) (*UserAccessToken, error)
// DeleteUserAccessToken deletes an access token for a user. // DeleteUserAccessToken deletes an access token for a user.
DeleteUserAccessToken(context.Context, *DeleteUserAccessTokenRequest) (*emptypb.Empty, error) DeleteUserAccessToken(context.Context, *DeleteUserAccessTokenRequest) (*emptypb.Empty, error)
// ListShortcuts returns a list of shortcuts for a user.
ListShortcuts(context.Context, *ListShortcutsRequest) (*ListShortcutsResponse, error)
// CreateShortcut creates a new shortcut for a user.
CreateShortcut(context.Context, *CreateShortcutRequest) (*Shortcut, error)
// UpdateShortcut updates a shortcut for a user.
UpdateShortcut(context.Context, *UpdateShortcutRequest) (*Shortcut, error)
// DeleteShortcut deletes a shortcut for a user.
DeleteShortcut(context.Context, *DeleteShortcutRequest) (*emptypb.Empty, error)
mustEmbedUnimplementedUserServiceServer() mustEmbedUnimplementedUserServiceServer()
} }
...@@ -363,18 +303,6 @@ func (UnimplementedUserServiceServer) CreateUserAccessToken(context.Context, *Cr ...@@ -363,18 +303,6 @@ func (UnimplementedUserServiceServer) CreateUserAccessToken(context.Context, *Cr
func (UnimplementedUserServiceServer) DeleteUserAccessToken(context.Context, *DeleteUserAccessTokenRequest) (*emptypb.Empty, error) { func (UnimplementedUserServiceServer) DeleteUserAccessToken(context.Context, *DeleteUserAccessTokenRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteUserAccessToken not implemented") return nil, status.Errorf(codes.Unimplemented, "method DeleteUserAccessToken not implemented")
} }
func (UnimplementedUserServiceServer) ListShortcuts(context.Context, *ListShortcutsRequest) (*ListShortcutsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListShortcuts not implemented")
}
func (UnimplementedUserServiceServer) CreateShortcut(context.Context, *CreateShortcutRequest) (*Shortcut, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateShortcut not implemented")
}
func (UnimplementedUserServiceServer) UpdateShortcut(context.Context, *UpdateShortcutRequest) (*Shortcut, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateShortcut not implemented")
}
func (UnimplementedUserServiceServer) DeleteShortcut(context.Context, *DeleteShortcutRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteShortcut not implemented")
}
func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {} func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {}
func (UnimplementedUserServiceServer) testEmbeddedByValue() {} func (UnimplementedUserServiceServer) testEmbeddedByValue() {}
...@@ -648,78 +576,6 @@ func _UserService_DeleteUserAccessToken_Handler(srv interface{}, ctx context.Con ...@@ -648,78 +576,6 @@ func _UserService_DeleteUserAccessToken_Handler(srv interface{}, ctx context.Con
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _UserService_ListShortcuts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListShortcutsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServiceServer).ListShortcuts(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserService_ListShortcuts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServiceServer).ListShortcuts(ctx, req.(*ListShortcutsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _UserService_CreateShortcut_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateShortcutRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServiceServer).CreateShortcut(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserService_CreateShortcut_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServiceServer).CreateShortcut(ctx, req.(*CreateShortcutRequest))
}
return interceptor(ctx, in, info, handler)
}
func _UserService_UpdateShortcut_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateShortcutRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServiceServer).UpdateShortcut(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserService_UpdateShortcut_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServiceServer).UpdateShortcut(ctx, req.(*UpdateShortcutRequest))
}
return interceptor(ctx, in, info, handler)
}
func _UserService_DeleteShortcut_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteShortcutRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServiceServer).DeleteShortcut(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserService_DeleteShortcut_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServiceServer).DeleteShortcut(ctx, req.(*DeleteShortcutRequest))
}
return interceptor(ctx, in, info, handler)
}
// UserService_ServiceDesc is the grpc.ServiceDesc for UserService service. // UserService_ServiceDesc is the grpc.ServiceDesc for UserService service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
...@@ -783,22 +639,6 @@ var UserService_ServiceDesc = grpc.ServiceDesc{ ...@@ -783,22 +639,6 @@ var UserService_ServiceDesc = grpc.ServiceDesc{
MethodName: "DeleteUserAccessToken", MethodName: "DeleteUserAccessToken",
Handler: _UserService_DeleteUserAccessToken_Handler, Handler: _UserService_DeleteUserAccessToken_Handler,
}, },
{
MethodName: "ListShortcuts",
Handler: _UserService_ListShortcuts_Handler,
},
{
MethodName: "CreateShortcut",
Handler: _UserService_CreateShortcut_Handler,
},
{
MethodName: "UpdateShortcut",
Handler: _UserService_UpdateShortcut_Handler,
},
{
MethodName: "DeleteShortcut",
Handler: _UserService_DeleteShortcut_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "api/v1/user_service.proto", Metadata: "api/v1/user_service.proto",
......
...@@ -11,6 +11,7 @@ tags: ...@@ -11,6 +11,7 @@ tags:
- name: MarkdownService - name: MarkdownService
- name: ResourceService - name: ResourceService
- name: MemoService - name: MemoService
- name: ShortcutService
- name: WebhookService - name: WebhookService
- name: WorkspaceService - name: WorkspaceService
- name: WorkspaceSettingService - name: WorkspaceSettingService
...@@ -1520,7 +1521,7 @@ paths: ...@@ -1520,7 +1521,7 @@ paths:
/api/v1/{parent}/shortcuts: /api/v1/{parent}/shortcuts:
get: get:
summary: ListShortcuts returns a list of shortcuts for a user. summary: ListShortcuts returns a list of shortcuts for a user.
operationId: UserService_ListShortcuts operationId: ShortcutService_ListShortcuts
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
...@@ -1538,10 +1539,10 @@ paths: ...@@ -1538,10 +1539,10 @@ paths:
type: string type: string
pattern: users/[^/]+ pattern: users/[^/]+
tags: tags:
- UserService - ShortcutService
post: post:
summary: CreateShortcut creates a new shortcut for a user. summary: CreateShortcut creates a new shortcut for a user.
operationId: UserService_CreateShortcut operationId: ShortcutService_CreateShortcut
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
...@@ -1568,11 +1569,11 @@ paths: ...@@ -1568,11 +1569,11 @@ paths:
required: false required: false
type: boolean type: boolean
tags: tags:
- UserService - ShortcutService
/api/v1/{parent}/shortcuts/{id}: /api/v1/{parent}/shortcuts/{id}:
delete: delete:
summary: DeleteShortcut deletes a shortcut for a user. summary: DeleteShortcut deletes a shortcut for a user.
operationId: UserService_DeleteShortcut operationId: ShortcutService_DeleteShortcut
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
...@@ -1596,11 +1597,11 @@ paths: ...@@ -1596,11 +1597,11 @@ paths:
required: true required: true
type: string type: string
tags: tags:
- UserService - ShortcutService
/api/v1/{parent}/shortcuts/{shortcut.id}: /api/v1/{parent}/shortcuts/{shortcut.id}:
patch: patch:
summary: UpdateShortcut updates a shortcut for a user. summary: UpdateShortcut updates a shortcut for a user.
operationId: UserService_UpdateShortcut operationId: ShortcutService_UpdateShortcut
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
...@@ -1632,7 +1633,7 @@ paths: ...@@ -1632,7 +1633,7 @@ paths:
filter: filter:
type: string type: string
tags: tags:
- UserService - ShortcutService
/api/v1/{parent}/tags/{tag}: /api/v1/{parent}/tags/{tag}:
delete: delete:
summary: DeleteMemoTag deletes a tag for a memo. summary: DeleteMemoTag deletes a tag for a memo.
......
...@@ -2,11 +2,11 @@ import { Input, Textarea, Button } from "@usememos/mui"; ...@@ -2,11 +2,11 @@ import { Input, Textarea, Button } from "@usememos/mui";
import { XIcon } from "lucide-react"; import { XIcon } from "lucide-react";
import React, { useState } from "react"; import React, { useState } from "react";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import { userServiceClient } from "@/grpcweb"; import { shortcutServiceClient } from "@/grpcweb";
import useCurrentUser from "@/hooks/useCurrentUser"; import useCurrentUser from "@/hooks/useCurrentUser";
import useLoading from "@/hooks/useLoading"; import useLoading from "@/hooks/useLoading";
import { userStore } from "@/store/v2"; import { userStore } from "@/store/v2";
import { Shortcut } from "@/types/proto/api/v1/user_service"; import { Shortcut } from "@/types/proto/api/v1/shortcut_service";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import { generateUUID } from "@/utils/uuid"; import { generateUUID } from "@/utils/uuid";
import { generateDialog } from "./Dialog"; import { generateDialog } from "./Dialog";
...@@ -19,7 +19,11 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => { ...@@ -19,7 +19,11 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
const { destroy } = props; const { destroy } = props;
const t = useTranslate(); const t = useTranslate();
const user = useCurrentUser(); const user = useCurrentUser();
const [shortcut, setShortcut] = useState(Shortcut.fromPartial({ ...props.shortcut })); const [shortcut, setShortcut] = useState<Shortcut>({
id: props.shortcut?.id || "",
title: props.shortcut?.title || "",
filter: props.shortcut?.filter || "",
});
const requestState = useLoading(false); const requestState = useLoading(false);
const isCreating = !props.shortcut; const isCreating = !props.shortcut;
...@@ -39,7 +43,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => { ...@@ -39,7 +43,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
try { try {
if (isCreating) { if (isCreating) {
await userServiceClient.createShortcut({ await shortcutServiceClient.createShortcut({
parent: user.name, parent: user.name,
shortcut: { shortcut: {
...shortcut, ...shortcut,
...@@ -48,7 +52,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => { ...@@ -48,7 +52,7 @@ const CreateShortcutDialog: React.FC<Props> = (props: Props) => {
}); });
toast.success("Create shortcut successfully"); toast.success("Create shortcut successfully");
} else { } else {
await userServiceClient.updateShortcut({ parent: user.name, shortcut, updateMask: ["title", "filter"] }); await shortcutServiceClient.updateShortcut({ parent: user.name, shortcut, updateMask: ["title", "filter"] });
toast.success("Update shortcut successfully"); toast.success("Update shortcut successfully");
} }
// Refresh shortcuts. // Refresh shortcuts.
......
import { Dropdown, Menu, MenuButton, MenuItem, Tooltip } from "@mui/joy"; import { Dropdown, Menu, MenuButton, MenuItem, Tooltip } from "@mui/joy";
import { Edit3Icon, MoreVerticalIcon, TrashIcon, PlusIcon } from "lucide-react"; import { Edit3Icon, MoreVerticalIcon, TrashIcon, PlusIcon } from "lucide-react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { userServiceClient } from "@/grpcweb"; import { shortcutServiceClient } from "@/grpcweb";
import useAsyncEffect from "@/hooks/useAsyncEffect"; import useAsyncEffect from "@/hooks/useAsyncEffect";
import useCurrentUser from "@/hooks/useCurrentUser"; import useCurrentUser from "@/hooks/useCurrentUser";
import { useMemoFilterStore } from "@/store/v1"; import { useMemoFilterStore } from "@/store/v1";
import { userStore } from "@/store/v2"; import { userStore } from "@/store/v2";
import { Shortcut } from "@/types/proto/api/v1/user_service"; import { Shortcut } from "@/types/proto/api/v1/shortcut_service";
import { cn } from "@/utils"; import { cn } from "@/utils";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import showCreateShortcutDialog from "../CreateShortcutDialog"; import showCreateShortcutDialog from "../CreateShortcutDialog";
...@@ -26,7 +26,7 @@ const ShortcutsSection = observer(() => { ...@@ -26,7 +26,7 @@ const ShortcutsSection = observer(() => {
const handleDeleteShortcut = async (shortcut: Shortcut) => { const handleDeleteShortcut = async (shortcut: Shortcut) => {
const confirmed = window.confirm("Are you sure you want to delete this shortcut?"); const confirmed = window.confirm("Are you sure you want to delete this shortcut?");
if (confirmed) { if (confirmed) {
await userServiceClient.deleteShortcut({ parent: user.name, id: shortcut.id }); await shortcutServiceClient.deleteShortcut({ parent: user.name, id: shortcut.id });
await userStore.fetchShortcuts(); await userStore.fetchShortcuts();
} }
}; };
......
...@@ -6,6 +6,7 @@ import { InboxServiceDefinition } from "./types/proto/api/v1/inbox_service"; ...@@ -6,6 +6,7 @@ import { InboxServiceDefinition } from "./types/proto/api/v1/inbox_service";
import { MarkdownServiceDefinition } from "./types/proto/api/v1/markdown_service"; import { MarkdownServiceDefinition } from "./types/proto/api/v1/markdown_service";
import { MemoServiceDefinition } from "./types/proto/api/v1/memo_service"; import { MemoServiceDefinition } from "./types/proto/api/v1/memo_service";
import { ResourceServiceDefinition } from "./types/proto/api/v1/resource_service"; import { ResourceServiceDefinition } from "./types/proto/api/v1/resource_service";
import { ShortcutServiceDefinition } from "./types/proto/api/v1/shortcut_service";
import { UserServiceDefinition } from "./types/proto/api/v1/user_service"; import { UserServiceDefinition } from "./types/proto/api/v1/user_service";
import { WebhookServiceDefinition } from "./types/proto/api/v1/webhook_service"; import { WebhookServiceDefinition } from "./types/proto/api/v1/webhook_service";
import { WorkspaceServiceDefinition } from "./types/proto/api/v1/workspace_service"; import { WorkspaceServiceDefinition } from "./types/proto/api/v1/workspace_service";
...@@ -32,6 +33,8 @@ export const memoServiceClient = clientFactory.create(MemoServiceDefinition, cha ...@@ -32,6 +33,8 @@ export const memoServiceClient = clientFactory.create(MemoServiceDefinition, cha
export const resourceServiceClient = clientFactory.create(ResourceServiceDefinition, channel); export const resourceServiceClient = clientFactory.create(ResourceServiceDefinition, channel);
export const shortcutServiceClient = clientFactory.create(ShortcutServiceDefinition, channel);
export const inboxServiceClient = clientFactory.create(InboxServiceDefinition, channel); export const inboxServiceClient = clientFactory.create(InboxServiceDefinition, channel);
export const activityServiceClient = clientFactory.create(ActivityServiceDefinition, channel); export const activityServiceClient = clientFactory.create(ActivityServiceDefinition, channel);
......
import { uniqueId } from "lodash-es"; import { uniqueId } from "lodash-es";
import { makeAutoObservable } from "mobx"; import { makeAutoObservable } from "mobx";
import { authServiceClient, inboxServiceClient, userServiceClient } from "@/grpcweb"; import { authServiceClient, inboxServiceClient, shortcutServiceClient, userServiceClient } from "@/grpcweb";
import { Inbox } from "@/types/proto/api/v1/inbox_service"; import { Inbox } from "@/types/proto/api/v1/inbox_service";
import { Shortcut, User, UserSetting, UserStats } from "@/types/proto/api/v1/user_service"; import { Shortcut } from "@/types/proto/api/v1/shortcut_service";
import { User, UserSetting, UserStats } from "@/types/proto/api/v1/user_service";
import { findNearestMatchedLanguage } from "@/utils/i18n"; import { findNearestMatchedLanguage } from "@/utils/i18n";
import workspaceStore from "./workspace"; import workspaceStore from "./workspace";
...@@ -138,7 +139,7 @@ const userStore = (() => { ...@@ -138,7 +139,7 @@ const userStore = (() => {
return; return;
} }
const { shortcuts } = await userServiceClient.listShortcuts({ parent: state.currentUser }); const { shortcuts } = await shortcutServiceClient.listShortcuts({ parent: state.currentUser });
state.setPartial({ state.setPartial({
shortcuts, shortcuts,
}); });
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment