@bbki.ng/site 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 1.0.15
4
+
5
+ ## 1.0.14
6
+
3
7
  ## 1.0.13
4
8
 
5
9
  ## 1.0.12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "url": "git+https://github.com/bbbottle/bbki.ng.git"
17
17
  },
18
18
  "dependencies": {
19
- "@bbki.ng/components": "workspace:2.1.32",
19
+ "@bbki.ng/components": "workspace:2.1.33",
20
20
  "@supabase/supabase-js": "^1.30.6",
21
21
  "classnames": "2.3.1",
22
22
  "react": "^18.0.0",
package/src/app.tsx CHANGED
@@ -39,6 +39,7 @@ const Layout = () => {
39
39
 
40
40
  const NowInMidCol = threeColWrapper(NowPage);
41
41
  const ContentInMidCol = threeColWrapper(Txt);
42
+ const ProjectsInMidCol = threeColWrapper(Png);
42
43
  const ArticleInMidCol = threeColWrapper(ArticlePage);
43
44
  const TagsInMidCol = threeColWrapper(Tags);
44
45
  const LoginInMidCol = threeColWrapper(Login);
@@ -55,7 +56,7 @@ export const App = () => {
55
56
  <Route path="/" element={<Layout />}>
56
57
  <Route index element={<CoverInMidCol />} />
57
58
 
58
- <Route path="/projects" element={<Png />} />
59
+ <Route path="/projects" element={<ProjectsInMidCol />} />
59
60
  <Route path="/projects/:id" element={<PhotoProjects />} />
60
61
 
61
62
  <Route path="blog" element={<ContentInMidCol />} />
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { FunctionComponent } from "react";
3
3
  import { ArticlePage } from "@/components/article";
4
- import { ThreeColLayout, ErrorBoundary, Link } from "@bbki.ng/components";
4
+ import { ThreeColLayout, ErrorBoundary } from "@bbki.ng/components";
5
5
 
6
6
  export const withArticleWrapper =
7
7
  (Component: FunctionComponent<any>): FunctionComponent<any> =>
@@ -16,15 +16,20 @@ export const withArticleWrapper =
16
16
  };
17
17
 
18
18
  export const threeColWrapper =
19
- <T extends object>(Component: any) =>
19
+ <T extends object>(Component: any, catchError: boolean = true) =>
20
20
  (props: T) => {
21
21
  return (
22
22
  <ThreeColLayout
23
- middleRenderer={() => (
24
- <ErrorBoundary>
25
- <Component {...props} />
26
- </ErrorBoundary>
27
- )}
23
+ middleRenderer={() => {
24
+ if (!catchError) {
25
+ return <Component {...props} />;
26
+ }
27
+ return (
28
+ <ErrorBoundary>
29
+ <Component {...props} />
30
+ </ErrorBoundary>
31
+ );
32
+ }}
28
33
  />
29
34
  );
30
35
  };
@@ -4,7 +4,9 @@ import React, {
4
4
  useState,
5
5
  Dispatch,
6
6
  SetStateAction,
7
+ useEffect,
7
8
  } from "react";
9
+ import { useLocation, useRoutes } from "react-router-dom";
8
10
 
9
11
  type LoadingContext = {
10
12
  isLoading: boolean;
@@ -18,6 +20,11 @@ export const GlobalLoadingContext = createContext<LoadingContext>({
18
20
 
19
21
  export const GlobalLoadingStateProvider = (props: { children: ReactNode }) => {
20
22
  const [isLoading, setIsLoading] = useState(false);
23
+ const location = useLocation();
24
+
25
+ useEffect(() => {
26
+ setIsLoading(false);
27
+ }, [location.pathname]);
21
28
 
22
29
  return (
23
30
  <GlobalLoadingContext.Provider value={{ isLoading, setIsLoading }}>
@@ -11,19 +11,22 @@ export const usePosts = (name: string = "", suspense?: boolean) => {
11
11
 
12
12
  let isLoading = !data && !error;
13
13
  const { setIsLoading } = useContext(GlobalLoadingContext);
14
- const titleList = isLoading
15
- ? []
16
- : data.map((p: any) => ({
17
- name: p.title,
18
- to: p.title,
19
- }));
14
+ const titleList =
15
+ isLoading || error
16
+ ? []
17
+ : data.map((p: any) => ({
18
+ name: p.title,
19
+ to: p.title,
20
+ }));
20
21
 
21
22
  useEffect(() => {
22
23
  setIsLoading(isLoading);
23
24
  }, [isLoading]);
24
25
 
25
26
  const posts =
26
- isLoading || name == "" ? data : data.find((p: any) => p.title == name);
27
+ isLoading || name == "" || error
28
+ ? data
29
+ : data.find((p: any) => p.title == name);
27
30
 
28
31
  return {
29
32
  posts: posts,
@@ -7,14 +7,14 @@ export const Cover = (props: { className: string }) => {
7
7
  links={[
8
8
  {
9
9
  to: "/projects",
10
- name: "ls *.png",
10
+ name: "cd ./projects",
11
11
  },
12
12
  {
13
13
  to: "/blog",
14
- name: "ls *.md",
14
+ name: "cd ./blog",
15
15
  },
16
16
  ]}
17
- title="history"
17
+ title=" "
18
18
  />
19
19
  );
20
20
  };
@@ -1,35 +1,17 @@
1
- import React, { useCallback, useEffect } from "react";
2
- import classnames from "classnames";
1
+ import React from "react";
3
2
  import { useProjects } from "@/hooks/use_projects";
4
- import { Link, Gallery, ImageRenderer } from "@bbki.ng/components";
3
+ import { Link, Gallery, ImageRenderer, LinkList } from "@bbki.ng/components";
5
4
  import { MySuspense } from "@/components";
6
- import { imageFormatter } from "@/utils";
7
5
 
8
6
  const Projects = () => {
9
7
  const { projects } = useProjects("", true);
10
- const renderImage: ImageRenderer = useCallback(
11
- (img, index, col) => {
12
- const project = projects[index];
13
- return (
14
- <div
15
- className={classnames("mb-128", {
16
- "md:mr-64": col === 0,
17
- "md:ml-64": col !== 0,
18
- })}
19
- >
20
- <Link to={`/projects/${project.name}`}>{img}</Link>
21
- </div>
22
- );
23
- },
24
- [projects]
25
- );
26
8
 
27
- return (
28
- <Gallery
29
- images={projects.map((p: any) => p.cover).map(imageFormatter)}
30
- imageRenderer={renderImage}
31
- />
32
- );
9
+ const links = projects.map((p: any) => ({
10
+ to: `/projects/${p.name}`,
11
+ name: p.name,
12
+ }));
13
+
14
+ return <LinkList links={links} title="图片" />;
33
15
  };
34
16
 
35
17
  export default () => {
@@ -1,4 +1,4 @@
1
- import React, { ReactElement } from "react";
1
+ import React, { ReactElement, useContext } from "react";
2
2
  import { MdxArticleList } from "@/articles";
3
3
  import { withArticleWrapper } from "@/components";
4
4
  import { MdxArticle } from "@/types/articles";
@@ -6,6 +6,7 @@ import { NotFound, Link } from "@bbki.ng/components";
6
6
  import { useParams } from "react-router-dom";
7
7
  import { usePosts } from "@/hooks/use_posts";
8
8
  import { ArticlePage } from "@/components/article";
9
+ import { GlobalLoadingContext } from "@/global_loading_state_provider";
9
10
 
10
11
  type TArticleMap = {
11
12
  [key: string]: ReactElement;
@@ -22,12 +23,14 @@ MdxArticleList.forEach((article: unknown) => {
22
23
  export default () => {
23
24
  const { title } = useParams();
24
25
  const { posts, isError, isLoading } = usePosts(title);
26
+ const { setIsLoading } = useContext(GlobalLoadingContext);
25
27
 
26
28
  if (!title) {
27
29
  return <NotFound />;
28
30
  }
29
31
 
30
32
  if (ArticleMap[title]) {
33
+ setIsLoading(false);
31
34
  return ArticleMap[title];
32
35
  }
33
36
 
@@ -67,7 +67,13 @@ export const getEnv = () => {
67
67
  };
68
68
 
69
69
  export const baseFetcher = (resource: string, init: RequestInit = {}) =>
70
- fetch(resource, init).then((res) => res.json());
70
+ fetch(resource, init).then((res) => {
71
+ if (!res.ok) {
72
+ throw new Error("An error occurred while fetching the data.");
73
+ }
74
+
75
+ return res.json();
76
+ });
71
77
 
72
78
  export const withToken =
73
79
  (fetcher: Fetcher) =>