Skip to content

Commit

Permalink
pre version v0.0.6 (#29)
Browse files Browse the repository at this point in the history
* update readme:redirect to documentation (#27)

* find first page for repo in layout (#28)

* find first page for repo in layout

* add hidden option for sync token
  • Loading branch information
zizdlp authored Aug 31, 2024
1 parent 04d8c16 commit 040a5cc
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 154 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">ZBook</h1>
<p align="center">
<a href="https://github.com/zizdlp/zbook-docs">ZBook Docs</a> - <a href="https://discord.com/channels/1250069935594536960/1250069935594536963">Discord</a> - <a href="https://www.youtube.com/channel/UC9D6VAJRoG7bD38dz8F9CSg">Youtube</a>
<a href="https://github.com/zizdlp/zbook-docs">Documention</a> - <a href="https://discord.com/channels/1250069935594536960/1250069935594536963">Discord</a> - <a href="https://www.youtube.com/channel/UC9D6VAJRoG7bD38dz8F9CSg">Youtube</a>
</p>

<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">ZBook</h1>
<p align="center">
<a href="https://github.com/zizdlp/zbook-user-guide">用户指南</a> - <a href="https://github.com/zizdlp/zbook-user-guide">开发者指南</a> - <a href="https://discord.com/channels/1250069935594536960/1250069935594536963">Discord</a> - <a href="https://www.youtube.com/channel/UC9D6VAJRoG7bD38dz8F9CSg">Youtube</a>
<a href="https://github.com/zizdlp/zbook-docs">文档</a> - <a href="https://discord.com/channels/1250069935594536960/1250069935594536963">Discord</a> - <a href="https://www.youtube.com/channel/UC9D6VAJRoG7bD38dz8F9CSg">Youtube</a>
</p>

<div align="center">
Expand Down
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.

6 changes: 3 additions & 3 deletions zbook_frontend/src/components/navbars/NavNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ export default function NavNotification({
// Reconnect on unexpected closure (you can add more conditions to handle specific closure codes)
if (!event.wasClean) {
reconnectRef.current += 1; // 使用ref的current属性修改reconnect值
if (reconnectRef.current < 5) {
if (reconnectRef.current < 10) {
logger.warn(
`websocket connection closed unexpectedly, attempting to reconnect...:${reconnectRef.current}`
);
fetchData();
} else {
logger.error(
"websocket connection closed unexpectedly, already try to reconnect 5 times"
"websocket connection closed unexpectedly, already try to reconnect 10 times"
);
toast(t("websocket_closed"), {
type: "warning",
autoClose: false,
autoClose: 2500,
});
}
}
Expand Down
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
32 changes: 22 additions & 10 deletions zbook_frontend/src/providers/dialogs/CreateRepoDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function CreateRepoDialog() {
const { createRepoOpen, setCreateRepoOpen } = useContext(OperationContext);
const t = useTranslations("Repo");
const cancelButtonRef = useRef(null);
const [show, setShow] = useState(false);
const [show, setShow] = useState({ sync_token: false, access_token: false });
// 将枚举值转换为 options 数组
const themeColorOptions = Object.values(ThemeColor).map((color) => ({
value: color,
Expand Down Expand Up @@ -262,13 +262,23 @@ export default function CreateRepoDialog() {
showName={t("GitHubSyncToken")}
formik={formik}
>
<FormInputWrapper
show={true}
name="sync_token"
placeholder={t("GitHubSyncTokenTip")}
formik={formik}
error={formik.errors.sync_token}
/>
<div className="flex items-center space-x-2 relative">
<FormInputWrapper
show={show.sync_token}
name="sync_token"
placeholder={t("GitHubSyncTokenTip")}
formik={formik}
error={formik.errors.sync_token}
/>
<div
className="absolute inset-y-0 right-0 pr-2 flex items-center cursor-pointer"
onClick={() =>
setShow({ ...show, sync_token: !show.sync_token })
}
>
<HiFingerPrint size={25} />
</div>
</div>
</FormGroupWrapper>
<FormGroupWrapper
classType="col-span-6 sm:col-span-3"
Expand All @@ -278,15 +288,17 @@ export default function CreateRepoDialog() {
>
<div className="flex items-center space-x-2 relative">
<FormInputWrapper
show={show}
show={show.access_token}
name="git_access_token"
placeholder={t("TokenPasswordTip")}
formik={formik}
error={formik.errors.git_access_token}
/>
<div
className="absolute inset-y-0 right-0 pr-2 flex items-center cursor-pointer"
onClick={() => setShow(!show)}
onClick={() =>
setShow({ ...show, access_token: !show.access_token })
}
>
<HiFingerPrint size={25} />
</div>
Expand Down
32 changes: 22 additions & 10 deletions zbook_frontend/src/providers/dialogs/UpdateRepoDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function UpdateRepoDialog() {
operationRepoName,
operationUsername,
} = useContext(OperationContext);
const [show, setShow] = useState(false);
const [show, setShow] = useState({ sync_token: false, access_token: false });
const cancelButtonRef = useRef(null);
function updateRepoValidate(values: any) {
let errors: FormikErrors<FormikValues> = {};
Expand Down Expand Up @@ -209,13 +209,23 @@ export default function UpdateRepoDialog() {
showName={t("GitHubSyncToken")}
formik={formik}
>
<FormInputWrapper
show={true}
name="sync_token"
placeholder={t("GitHubSyncTokenTip")}
formik={formik}
error={formik.errors.sync_token}
/>
<div className="flex items-center space-x-2 relative">
<FormInputWrapper
show={show.sync_token}
name="sync_token"
placeholder={t("GitHubSyncTokenTip")}
formik={formik}
error={formik.errors.sync_token}
/>
<div
className="absolute inset-y-0 right-0 pr-2 flex items-center cursor-pointer"
onClick={() =>
setShow({ ...show, sync_token: !show.sync_token })
}
>
<HiFingerPrint size={25} />
</div>
</div>
</FormGroupWrapper>
<FormGroupWrapper
classType="col-span-6 sm:col-span-3"
Expand All @@ -225,15 +235,17 @@ export default function UpdateRepoDialog() {
>
<div className="flex items-center space-x-2 relative">
<FormInputWrapper
show={show}
show={show.access_token}
name="git_access_token"
placeholder={t("TokenPasswordTip")}
formik={formik}
error={formik.errors.git_access_token}
/>
<div
className="absolute inset-y-0 right-0 pr-2 flex items-center cursor-pointer"
onClick={() => setShow(!show)}
onClick={() =>
setShow({ ...show, access_token: !show.access_token })
}
>
<HiFingerPrint size={25} />
</div>
Expand Down

0 comments on commit 040a5cc

Please sign in to comment.