Skip to content

Commit

Permalink
find first page for repo in layout
Browse files Browse the repository at this point in the history
  • Loading branch information
zizdlp committed Aug 31, 2024
1 parent d941585 commit 591e2a2
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 129 deletions.
6 changes: 6 additions & 0 deletions zbook_backend/doc/swagger/service_zbook_repo.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@
},
"repoName": {
"type": "string"
},
"lang": {
"type": "string"
}
},
"title": "2.GetRepoConfig"
Expand All @@ -643,6 +646,9 @@
},
"themeColor": {
"type": "string"
},
"firstPath": {
"type": "string"
}
}
},
Expand Down
10 changes: 10 additions & 0 deletions zbook_backend/gapi/repo_get_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/rs/zerolog/log"
db "github.com/zizdlp/zbook/db/sqlc"
"github.com/zizdlp/zbook/pb/rpcs"
"github.com/zizdlp/zbook/util"
"github.com/zizdlp/zbook/val"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -49,12 +50,21 @@ func (server *Server) GetRepoConfig(ctx context.Context, req *rpcs.GetRepoConfig
return nil, status.Errorf(codes.Internal, "get user by id failed: %s", err)
}

config, err := util.ParseRepoConfigFromString(repo.Config)
if err != nil {
return nil, status.Errorf(codes.Internal, "ParseRepoConfigFromString error : %s", err)
}
relative_path, err := config.GetFirstDocument(req.GetLang())
if err != nil {
return nil, status.Errorf(codes.Internal, "GetFirstDocument error : %s", err)
}
rsp := &rpcs.GetRepoConfigResponse{
Config: repo.Config,
Username: user.Username,
VisibilityLevel: repo.VisibilityLevel,
ThemeSidebar: repo.ThemeSidebar,
ThemeColor: repo.ThemeColor,
FirstPath: relative_path,
}
return rsp, nil
}
Expand Down
272 changes: 146 additions & 126 deletions zbook_backend/pb/rpcs/rpc_repo.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions zbook_backend/proto/rpcs/rpc_repo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ message CreateRepoResponse {}
message GetRepoConfigRequest {
string username = 1;
string repo_name = 2;
string lang = 3;
}
message GetRepoConfigResponse {
string username = 1;
string config = 2;
string visibility_level = 3;
string theme_sidebar = 4;
string theme_color = 5;
string first_path = 6;
}

// 3.DeleteRepo
Expand Down
2 changes: 1 addition & 1 deletion zbook_backend/statik/statik.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions zbook_frontend/src/components/sidebars/RepoSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function RepoSideBar({
theme_sidebar,
theme_color,
visibility_level,
first_path,
}: {
sublayouts: MenuStruct[];
anchors: Anchor[];
Expand All @@ -27,6 +28,7 @@ export default function RepoSideBar({
theme_color: ThemeColor;
theme_sidebar: string;
visibility_level: string;
first_path: string;
}) {
const pathname = usePathname();
const locale = useLocale();
Expand All @@ -48,6 +50,7 @@ export default function RepoSideBar({
anchors={anchors ?? []}
visibility_level={visibility_level}
theme_color={theme_color}
first_path={first_path}
/>
{theme_sidebar == "theme_sidebar_fold" ? (
<FoldSubMenu
Expand Down
2 changes: 2 additions & 0 deletions zbook_frontend/src/components/sidebars/RepoSideBarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default async function RepoSideBarLayout({
values: {
repo_name: decodeURIComponent(reponame),
username: username,
lang: locale == "" ? "en" : locale,
},
});

Expand All @@ -60,6 +61,7 @@ export default async function RepoSideBarLayout({
username={data.username}
authname={authname}
visibility_level={data.visibility_level}
first_path={data.first_path}
/>
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { FetchServerWithAuthWrapperEndPoint } from "@/fetchs/server_with_auth_util";
import { useTranslations } from "next-intl";
import { FetchError } from "@/fetchs/util";
import { MdCloudSync, MdOutlineVisibility, MdSync } from "react-icons/md";
import { MdCloudSync, MdOutlineVisibility } from "react-icons/md";
import { Anchor } from "@/types/interface";
import RepoSideBarSettingItem from "./RepoSideBarSetttingItem";
import { FaDiscord, FaGithub } from "react-icons/fa";
Expand All @@ -21,13 +21,15 @@ export default function RepoSideBarSetting({
anchors,
visibility_level,
theme_color,
first_path,
}: {
username: string;
reponame: string;
authname: string;
anchors: Anchor[];
visibility_level: string;
theme_color: ThemeColor;
first_path: string;
}) {
const pathname = usePathname();
let page_type = "";
Expand Down Expand Up @@ -81,7 +83,7 @@ export default function RepoSideBarSetting({
return (
<>
<RepoSideBarSettingItem
href={`/workspace/${username}/o/${reponame}`}
href={`/workspace/${username}/o/${reponame}/${first_path}`}
selected={page_type != "~visi"}
icon={IoBook}
text={t("RepoHome")}
Expand Down
1 change: 1 addition & 0 deletions zbook_frontend/src/fetchs/server_with_auth_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ interface GetUserInfoRequest {
interface GetRepoConfigRequest {
username: string;
repo_name: string;
lang: string;
}
interface GetMarkdownContentRequest {
username: string;
Expand Down

0 comments on commit 591e2a2

Please sign in to comment.