@bbki.ng/site 1.0.14 → 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,7 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 1.0.15
4
+
3
5
  ## 1.0.14
4
6
 
5
7
  ## 1.0.13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.0.14",
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",
@@ -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,
@@ -11,7 +11,7 @@ export const Cover = (props: { className: string }) => {
11
11
  },
12
12
  {
13
13
  to: "/blog",
14
- name: "ls *.md",
14
+ name: "cd ./blog",
15
15
  },
16
16
  ]}
17
17
  title=" "
@@ -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) =>