chore: update function name

This commit is contained in:
Steven 2023-11-05 23:28:09 +08:00
parent e60e47f76f
commit 39a0e69b04
22 changed files with 42 additions and 51 deletions

View File

@ -46,7 +46,7 @@ func (s *APIV2Service) UpdateInbox(ctx context.Context, request *apiv2pb.UpdateI
return nil, status.Errorf(codes.InvalidArgument, "update mask is required")
}
inboxID, err := GetInboxID(request.Inbox.Name)
inboxID, err := ExtractInboxIDFromName(request.Inbox.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid inbox name: %v", err)
}
@ -77,7 +77,7 @@ func (s *APIV2Service) UpdateInbox(ctx context.Context, request *apiv2pb.UpdateI
}
func (s *APIV2Service) DeleteInbox(ctx context.Context, request *apiv2pb.DeleteInboxRequest) (*apiv2pb.DeleteInboxResponse, error) {
inboxID, err := GetInboxID(request.Name)
inboxID, err := ExtractInboxIDFromName(request.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid inbox name: %v", err)
}

View File

@ -34,8 +34,8 @@ func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error)
return tokens, nil
}
// GetUsername returns the username from a resource name.
func GetUsername(name string) (string, error) {
// ExtractUsernameFromName returns the username from a resource name.
func ExtractUsernameFromName(name string) (string, error) {
tokens, err := GetNameParentTokens(name, UserNamePrefix)
if err != nil {
return "", err
@ -43,8 +43,8 @@ func GetUsername(name string) (string, error) {
return tokens[0], nil
}
// GetInboxID returns the inbox ID from a resource name.
func GetInboxID(name string) (int32, error) {
// ExtractInboxIDFromName returns the inbox ID from a resource name.
func ExtractInboxIDFromName(name string) (int32, error) {
tokens, err := GetNameParentTokens(name, InboxNamePrefix)
if err != nil {
return 0, err

View File

@ -28,7 +28,7 @@ var (
)
func (s *APIV2Service) GetUser(ctx context.Context, request *apiv2pb.GetUserRequest) (*apiv2pb.GetUserResponse, error) {
username, err := GetUsername(request.Name)
username, err := ExtractUsernameFromName(request.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "name is required")
}
@ -58,7 +58,7 @@ func (s *APIV2Service) CreateUser(ctx context.Context, request *apiv2pb.CreateUs
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
username, err := GetUsername(request.User.Name)
username, err := ExtractUsernameFromName(request.User.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "name is required")
}
@ -88,7 +88,7 @@ func (s *APIV2Service) CreateUser(ctx context.Context, request *apiv2pb.CreateUs
}
func (s *APIV2Service) UpdateUser(ctx context.Context, request *apiv2pb.UpdateUserRequest) (*apiv2pb.UpdateUserResponse, error) {
username, err := GetUsername(request.User.Name)
username, err := ExtractUsernameFromName(request.User.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "name is required")
}
@ -159,7 +159,7 @@ func (s *APIV2Service) ListUserAccessTokens(ctx context.Context, request *apiv2p
}
userID := user.ID
username, err := GetUsername(request.Name)
username, err := ExtractUsernameFromName(request.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "name is required")
}

View File

@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { useUserStore } from "@/store/module";
import { useUserV1Store, UserNamePrefix } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { generateDialog } from "./Dialog";
import Icon from "./Icon";
@ -10,9 +10,9 @@ interface Props extends DialogProps {
}
const ChangeMemberPasswordDialog: React.FC<Props> = (props: Props) => {
const { user: propsUser, destroy } = props;
const { user, destroy } = props;
const t = useTranslate();
const userStore = useUserStore();
const userStore = useUserV1Store();
const [newPassword, setNewPassword] = useState("");
const [newPasswordAgain, setNewPasswordAgain] = useState("");
@ -47,10 +47,13 @@ const ChangeMemberPasswordDialog: React.FC<Props> = (props: Props) => {
}
try {
await userStore.patchUser({
id: propsUser.id,
password: newPassword,
});
await userStore.updateUser(
{
name: `${UserNamePrefix}${user.username}`,
password: newPassword,
},
["password"]
);
toast(t("message.password-changed"));
handleCloseBtnClick();
} catch (error: any) {
@ -63,7 +66,7 @@ const ChangeMemberPasswordDialog: React.FC<Props> = (props: Props) => {
<>
<div className="dialog-header-container !w-64">
<p className="title-text">
{t("setting.account-section.change-password")} ({propsUser.username})
{t("setting.account-section.change-password")} ({user.username})
</p>
<button className="btn close-btn" onClick={handleCloseBtnClick}>
<Icon.X />

View File

@ -1,8 +1,7 @@
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { useGlobalStore, useUserStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { UserNamePrefix } from "@/store/v1/resourceName";
import { useUserV1Store, UserNamePrefix } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { generateDialog } from "./Dialog";
import Icon from "./Icon";

View File

@ -3,7 +3,7 @@ import { useEffect } from "react";
import { NavLink, useLocation } from "react-router-dom";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useLayoutStore } from "@/store/module";
import useInboxStore from "@/store/v1/inbox";
import { useInboxStore } from "@/store/v1";
import { Inbox_Status } from "@/types/proto/api/v2/inbox_service";
import { useTranslate } from "@/utils/i18n";
import { resolution } from "@/utils/layout";

View File

@ -4,8 +4,7 @@ import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { activityServiceClient } from "@/grpcweb";
import useNavigateTo from "@/hooks/useNavigateTo";
import useInboxStore from "@/store/v1/inbox";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { useInboxStore, extractUsernameFromName } from "@/store/v1";
import { Activity } from "@/types/proto/api/v2/activity_service";
import { Inbox, Inbox_Status } from "@/types/proto/api/v2/inbox_service";
import { useTranslate } from "@/utils/i18n";

View File

@ -8,8 +8,7 @@ import { getRelativeTimeString } from "@/helpers/datetime";
import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useFilterStore, useMemoStore, useUserStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { useUserV1Store, extractUsernameFromName } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import showChangeMemoCreatedTsDialog from "./ChangeMemoCreatedTsDialog";
import { showCommonDialog } from "./Dialog/CommonDialog";

View File

@ -7,7 +7,7 @@ import { getTimeStampByDate } from "@/helpers/datetime";
import useCurrentUser from "@/hooks/useCurrentUser";
import { TAG_REG } from "@/labs/marked/parser";
import { useFilterStore, useMemoStore } from "@/store/module";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { extractUsernameFromName } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import Empty from "./Empty";
import Memo from "./Memo";

View File

@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { userServiceClient } from "@/grpcweb";
import useCurrentUser from "@/hooks/useCurrentUser";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { extractUsernameFromName } from "@/store/v1";
import { UserAccessToken } from "@/types/proto/api/v2/user_service";
import { useTranslate } from "@/utils/i18n";
import showCreateAccessTokenDialog from "../CreateAccessTokenDialog";

View File

@ -1,6 +1,6 @@
import { Button } from "@mui/joy";
import useCurrentUser from "@/hooks/useCurrentUser";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { extractUsernameFromName } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import showChangePasswordDialog from "../ChangePasswordDialog";
import showUpdateAccountDialog from "../UpdateAccountDialog";

View File

@ -5,8 +5,7 @@ import { toast } from "react-hot-toast";
import { getDateTimeString } from "@/helpers/datetime";
import useLoading from "@/hooks/useLoading";
import toImage from "@/labs/html2image";
import { useUserV1Store } from "@/store/v1";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { useUserV1Store, extractUsernameFromName } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { generateDialog } from "./Dialog";
import showEmbedMemoDialog from "./EmbedMemoDialog";

View File

@ -5,8 +5,7 @@ import { getDateStampByDate, getDateString, getTimeStampByDate } from "@/helpers
import * as utils from "@/helpers/utils";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useGlobalStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { useUserV1Store, extractUsernameFromName } from "@/store/v1";
import { useTranslate, Translations } from "@/utils/i18n";
import { useFilterStore, useMemoStore } from "../store/module";
import "@/less/usage-heat-map.less";

View File

@ -1,7 +1,7 @@
import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useGlobalStore, useUserStore } from "@/store/module";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { extractUsernameFromName } from "@/store/v1";
import { User_Role } from "@/types/proto/api/v2/user_service";
import { useTranslate } from "@/utils/i18n";
import showAboutSiteDialog from "./AboutSiteDialog";

View File

@ -5,7 +5,7 @@ import { getMemoStats } from "@/helpers/api";
import { DAILY_TIMESTAMP } from "@/helpers/consts";
import { getDateStampByDate, isFutureDate } from "@/helpers/datetime";
import useCurrentUser from "@/hooks/useCurrentUser";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { extractUsernameFromName } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import Icon from "../Icon";
import "@/less/common/date-picker.less";

View File

@ -15,7 +15,7 @@ import { DAILY_TIMESTAMP, DEFAULT_MEMO_LIMIT } from "@/helpers/consts";
import { getDateStampByDate, getNormalizedDateString, getTimeStampByDate, getTimeString } from "@/helpers/datetime";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useMemoStore, useUserStore } from "@/store/module";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { extractUsernameFromName } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
const DailyReview = () => {

View File

@ -3,7 +3,7 @@ import Empty from "@/components/Empty";
import Icon from "@/components/Icon";
import MemoCommentMessage from "@/components/Inbox/MemoCommentMessage";
import MobileHeader from "@/components/MobileHeader";
import useInboxStore from "@/store/v1/inbox";
import { useInboxStore } from "@/store/v1";
import { Inbox_Type } from "@/types/proto/api/v2/inbox_service";
import { useTranslate } from "@/utils/i18n";

View File

@ -19,8 +19,7 @@ import { getDateTimeString } from "@/helpers/datetime";
import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useGlobalStore, useMemoStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { extractUsernameFromName } from "@/store/v1/resourceName";
import { useUserV1Store, extractUsernameFromName } from "@/store/v1";
import { User, User_Role } from "@/types/proto/api/v2/user_service";
import { useTranslate } from "@/utils/i18n";

View File

@ -8,7 +8,7 @@ interface InboxStore {
updateInbox: (inbox: Partial<Inbox>, updateMask: string[]) => Promise<Inbox>;
}
const useInboxStore = create<InboxStore>()((set, get) => ({
export const useInboxStore = create<InboxStore>()((set, get) => ({
inboxes: [],
fetchInboxes: async () => {
const { inboxes } = await inboxServiceClient.listInboxes({});
@ -28,5 +28,3 @@ const useInboxStore = create<InboxStore>()((set, get) => ({
return updatedInbox;
},
}));
export default useInboxStore;

View File

@ -1,4 +1,4 @@
import useMemoCacheStore from "./memo";
import useUserV1Store from "./user";
export { useUserV1Store, useMemoCacheStore };
export * from "./user";
export * from "./memo";
export * from "./inbox";
export * from "./resourceName";

View File

@ -3,7 +3,7 @@ import { combine } from "zustand/middleware";
import * as api from "@/helpers/api";
import { convertResponseModelMemo } from "../module";
const useMemoCacheStore = create(
export const useMemoCacheStore = create(
combine({ memoById: new Map<MemoId, Memo>() }, (set, get) => ({
getState: () => get(),
getOrFetchMemoById: async (memoId: MemoId) => {
@ -39,5 +39,3 @@ const useMemoCacheStore = create(
},
}))
);
export default useMemoCacheStore;

View File

@ -13,7 +13,7 @@ interface UserV1Store {
// Request cache is used to prevent multiple requests.
const requestCache = new Map<string, Promise<any>>();
const useUserV1Store = create<UserV1Store>()((set, get) => ({
export const useUserV1Store = create<UserV1Store>()((set, get) => ({
userMapByUsername: {},
getOrFetchUserByUsername: async (username: string) => {
const userMap = get().userMapByUsername;
@ -58,5 +58,3 @@ const useUserV1Store = create<UserV1Store>()((set, get) => ({
return updatedUser;
},
}));
export default useUserV1Store;