@c-rex/templates 0.1.6 → 0.1.8
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/package.json +1 -1
- package/src/articles/blog/page.tsx +24 -38
- package/src/articles/documents/page.tsx +4 -3
- package/src/articles/topics/page.tsx +36 -4
- package/src/articles/utils.ts +74 -9
- package/src/articles/wrapper.tsx +18 -35
- package/src/home/layout.tsx +25 -26
- package/src/home/page.tsx +21 -39
package/package.json
CHANGED
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
1
|
+
import { extractHtmlContent, getInfoWithCache, getPrimaryInfo } from "../utils";
|
|
2
|
+
import { BLOG_TYPE_AND_LINK } from "@c-rex/constants";
|
|
4
3
|
import { PageWrapper } from "@c-rex/components/page-wrapper";
|
|
5
|
-
import { Breadcrumb } from "@c-rex/components/breadcrumb";
|
|
6
|
-
import * as cheerio from 'cheerio'
|
|
7
4
|
import { Metadata } from "next";
|
|
8
5
|
import { RenderArticle } from "@c-rex/components/render-article";
|
|
6
|
+
import { AppSidebar } from "@c-rex/components/sidebar";
|
|
7
|
+
import { SidebarInset, SidebarProvider } from "@c-rex/ui/sidebar";
|
|
8
|
+
import { CheckArticleLangToast } from "@c-rex/components/check-article-lang";
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
const $ = cheerio.load(htmlString)
|
|
10
|
+
const infoCache = new Map<string, Awaited<ReturnType<typeof getPrimaryInfo>>>();
|
|
12
11
|
|
|
13
|
-
const metaTags = $('meta').map((_, el) => {
|
|
14
|
-
const name = $(el).attr('name')
|
|
15
|
-
const content = $(el).attr('content')
|
|
16
|
-
return name && content ? { name, content } : null
|
|
17
|
-
}).get().filter(Boolean)
|
|
18
|
-
|
|
19
|
-
const articleHtml = $('body').html() || ''
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
metaTags,
|
|
23
|
-
articleHtml,
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
12
|
|
|
27
13
|
export const generateMetadata = async (
|
|
28
14
|
{ params }: { params: { id: string } }
|
|
29
15
|
): Promise<Metadata> => {
|
|
30
|
-
const { htmlContent, title } = await
|
|
16
|
+
const { htmlContent, title } = await getInfoWithCache(params.id, BLOG_TYPE_AND_LINK, infoCache);
|
|
31
17
|
const { metaTags } = extractHtmlContent(htmlContent)
|
|
32
18
|
|
|
33
19
|
const other: Record<string, string[]> = {}
|
|
@@ -44,26 +30,26 @@ export const generateMetadata = async (
|
|
|
44
30
|
}
|
|
45
31
|
|
|
46
32
|
export const BlogPageTemplate = async ({ params }: { params: { id: string } }) => {
|
|
47
|
-
const { htmlContent,
|
|
33
|
+
const { htmlContent, lang, availableVersions } = await getInfoWithCache(params.id, BLOG_TYPE_AND_LINK, infoCache);
|
|
48
34
|
const { articleHtml } = extractHtmlContent(htmlContent)
|
|
49
35
|
|
|
50
|
-
const breadcrumbItems = [{
|
|
51
|
-
link: "/",
|
|
52
|
-
label: title,
|
|
53
|
-
id: "home",
|
|
54
|
-
active: false,
|
|
55
|
-
children: [],
|
|
56
|
-
}]
|
|
57
|
-
|
|
58
36
|
return (
|
|
59
|
-
<PageWrapper title="">
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
37
|
+
<PageWrapper title="" showInput={false}>
|
|
38
|
+
<SidebarProvider>
|
|
39
|
+
|
|
40
|
+
<CheckArticleLangToast availableVersions={availableVersions} />
|
|
41
|
+
|
|
42
|
+
<AppSidebar
|
|
43
|
+
lang={lang}
|
|
44
|
+
data={[]}
|
|
45
|
+
availableVersions={availableVersions}
|
|
46
|
+
/>
|
|
47
|
+
<SidebarInset>
|
|
48
|
+
<div className="container flex flex-col">
|
|
49
|
+
<RenderArticle htmlContent={articleHtml} contentLang={lang} />
|
|
50
|
+
</div>
|
|
51
|
+
</SidebarInset>
|
|
52
|
+
</SidebarProvider>
|
|
67
53
|
</PageWrapper>
|
|
68
54
|
);
|
|
69
55
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { getPrimaryInfo } from "../utils";
|
|
3
2
|
import { ArticleWrapper } from "../wrapper";
|
|
4
3
|
import { PageWrapper } from "@c-rex/components/page-wrapper";
|
|
5
4
|
import { DOCUMENTS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
6
5
|
|
|
7
6
|
export const DocumentsPageTemplate = async ({ params }: { params: { id: string } }) => {
|
|
8
|
-
const { htmlContent, title, lang } = await getPrimaryInfo(params.id, DOCUMENTS_TYPE_AND_LINK);
|
|
7
|
+
const { htmlContent, title, lang, availableVersions, packageId } = await getPrimaryInfo(params.id, DOCUMENTS_TYPE_AND_LINK);
|
|
9
8
|
|
|
10
9
|
return (
|
|
11
|
-
<PageWrapper title={title}>
|
|
10
|
+
<PageWrapper title={title} showInput>
|
|
12
11
|
<ArticleWrapper
|
|
12
|
+
packageId={packageId}
|
|
13
13
|
title={title}
|
|
14
|
+
availableVersions={availableVersions}
|
|
14
15
|
htmlContent={htmlContent}
|
|
15
16
|
lang={lang}
|
|
16
17
|
id={params.id}
|
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { getPrimaryInfo } from "../utils";
|
|
2
|
+
import { extractHtmlContent, getInfoWithCache, getPrimaryInfo } from "../utils";
|
|
3
3
|
import { TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
4
4
|
import { ArticleWrapper } from "../wrapper";
|
|
5
5
|
import { PageWrapper } from "@c-rex/components/page-wrapper";
|
|
6
|
+
import { Metadata } from "next";
|
|
7
|
+
|
|
8
|
+
const infoCache = new Map<string, Awaited<ReturnType<typeof getPrimaryInfo>>>();
|
|
9
|
+
|
|
10
|
+
export const generateMetadata = async (
|
|
11
|
+
{ params }: { params: { id: string } }
|
|
12
|
+
): Promise<Metadata> => {
|
|
13
|
+
const { htmlContent, title } = await getInfoWithCache(params.id, TOPICS_TYPE_AND_LINK, infoCache);
|
|
14
|
+
const { metaTags } = extractHtmlContent(htmlContent)
|
|
15
|
+
|
|
16
|
+
const other: Record<string, string[]> = {}
|
|
17
|
+
|
|
18
|
+
for (const { name, content } of metaTags) {
|
|
19
|
+
if (Object.keys(other).includes(name)) {
|
|
20
|
+
other[name]?.push(content)
|
|
21
|
+
} else {
|
|
22
|
+
other[name] = [content]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { ...other, title }
|
|
27
|
+
}
|
|
6
28
|
|
|
7
29
|
export const TopicsPageTemplate = async ({ params }: { params: { id: string } }) => {
|
|
8
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
htmlContent,
|
|
32
|
+
title,
|
|
33
|
+
lang,
|
|
34
|
+
availableVersions,
|
|
35
|
+
packageId
|
|
36
|
+
} = await getInfoWithCache(params.id, TOPICS_TYPE_AND_LINK, infoCache);
|
|
37
|
+
|
|
38
|
+
const { articleHtml } = extractHtmlContent(htmlContent)
|
|
9
39
|
|
|
10
40
|
return (
|
|
11
|
-
<PageWrapper title={title}>
|
|
41
|
+
<PageWrapper title={title} showInput>
|
|
12
42
|
<ArticleWrapper
|
|
13
43
|
title={title}
|
|
14
44
|
lang={lang}
|
|
15
|
-
|
|
45
|
+
packageId={packageId}
|
|
46
|
+
availableVersions={availableVersions}
|
|
47
|
+
htmlContent={articleHtml}
|
|
16
48
|
id={params.id}
|
|
17
49
|
type={TOPICS_TYPE_AND_LINK}
|
|
18
50
|
/>
|
package/src/articles/utils.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DirectoryNodesService, InformationUnitsService, RenditionsService } from "@c-rex/services";
|
|
2
2
|
import { DOCUMENTS_TYPE_AND_LINK, TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
3
|
-
import { DirectoryNodes } from "@c-rex/interfaces";
|
|
3
|
+
import { DirectoryNodes, informationUnitsResponseItem, SidebarAvailableVersionsInterface } from "@c-rex/interfaces";
|
|
4
|
+
import * as cheerio from 'cheerio'
|
|
5
|
+
import { BLOG_TYPE_AND_LINK } from "@c-rex/constants";
|
|
4
6
|
|
|
5
7
|
/*
|
|
6
8
|
* Get primary info for a given information unit
|
|
@@ -11,7 +13,9 @@ import { DirectoryNodes } from "@c-rex/interfaces";
|
|
|
11
13
|
export const getPrimaryInfo = async (id: string, type: string): Promise<{
|
|
12
14
|
htmlContent: string,
|
|
13
15
|
title: string,
|
|
14
|
-
lang: string
|
|
16
|
+
lang: string,
|
|
17
|
+
packageId: string,
|
|
18
|
+
availableVersions: SidebarAvailableVersionsInterface[]
|
|
15
19
|
}> => {
|
|
16
20
|
const renditionService = new RenditionsService();
|
|
17
21
|
const informationService = new InformationUnitsService();
|
|
@@ -19,29 +23,65 @@ export const getPrimaryInfo = async (id: string, type: string): Promise<{
|
|
|
19
23
|
|
|
20
24
|
let title = informationUnitsItem.labels[0]?.value
|
|
21
25
|
const lang = informationUnitsItem.languages[0];
|
|
22
|
-
const
|
|
23
|
-
|
|
26
|
+
const versionOf = informationUnitsItem.versionOf.shortId
|
|
27
|
+
|
|
28
|
+
const promiseList: any = [
|
|
29
|
+
informationService.getList({
|
|
30
|
+
restrict: [`versionOf.shortId=${versionOf}`], // TODO: replace from filter to restrict
|
|
31
|
+
fields: ["renditions", "class", "languages", "labels"],
|
|
32
|
+
}),
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
const rootNode = await getRootNode(informationUnitsItem.directoryNodes)
|
|
24
36
|
|
|
25
37
|
if (rootNode != null) {
|
|
26
38
|
title = rootNode.informationUnits[0]?.labels[0]?.value;
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
if (type
|
|
30
|
-
|
|
41
|
+
if ([TOPICS_TYPE_AND_LINK, BLOG_TYPE_AND_LINK].includes(type)) {
|
|
42
|
+
promiseList.push(
|
|
43
|
+
renditionService.getHTMLRendition({ renditions: informationUnitsItem.renditions })
|
|
44
|
+
)
|
|
45
|
+
|
|
31
46
|
} else if (rootNode != null && type == DOCUMENTS_TYPE_AND_LINK) {
|
|
32
|
-
|
|
47
|
+
|
|
33
48
|
const service = new DirectoryNodesService();
|
|
49
|
+
|
|
50
|
+
const directoryId = rootNode.childNodes[0]?.shortId as string;
|
|
51
|
+
|
|
34
52
|
const response = await service.getItem(directoryId);
|
|
53
|
+
|
|
35
54
|
const infoId = response.informationUnits[0]?.shortId;
|
|
36
55
|
|
|
37
56
|
const childInformationUnit = await informationService.getItem({ id: infoId as string });
|
|
38
|
-
|
|
57
|
+
|
|
58
|
+
promiseList.push(
|
|
59
|
+
renditionService.getHTMLRendition({ renditions: childInformationUnit.renditions })
|
|
60
|
+
)
|
|
39
61
|
}
|
|
40
62
|
|
|
63
|
+
const [versions, htmlContent] = await Promise.all(promiseList)
|
|
64
|
+
|
|
65
|
+
const availableVersions = versions.items.map((item: informationUnitsResponseItem) => {
|
|
66
|
+
return {
|
|
67
|
+
shortId: item.shortId,
|
|
68
|
+
link: `/${type}/${item.shortId}`,
|
|
69
|
+
lang: item.language,
|
|
70
|
+
country: item.language.split("-")[1],
|
|
71
|
+
active: item.language === lang,
|
|
72
|
+
}
|
|
73
|
+
}).sort((a: SidebarAvailableVersionsInterface, b: SidebarAvailableVersionsInterface) => {
|
|
74
|
+
if (a.lang < b.lang) return -1;
|
|
75
|
+
if (a.lang > b.lang) return 1;
|
|
76
|
+
return 0;
|
|
77
|
+
}) as SidebarAvailableVersionsInterface[];
|
|
78
|
+
|
|
41
79
|
return {
|
|
42
80
|
htmlContent,
|
|
81
|
+
packageId: informationUnitsItem.packages[0]?.shortId as string,
|
|
43
82
|
title: title as string,
|
|
44
83
|
lang: lang as string,
|
|
84
|
+
availableVersions
|
|
45
85
|
}
|
|
46
86
|
}
|
|
47
87
|
|
|
@@ -70,4 +110,29 @@ export const getRootNode = async (directoryNodes: DirectoryNodes[]): Promise<Dir
|
|
|
70
110
|
}
|
|
71
111
|
|
|
72
112
|
return response;
|
|
73
|
-
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const getInfoWithCache = async (id: string, type: string, infoCache: any): Promise<Awaited<ReturnType<typeof getPrimaryInfo>>> => {
|
|
116
|
+
if (!infoCache.has(id)) {
|
|
117
|
+
const info = await getPrimaryInfo(id, type);
|
|
118
|
+
infoCache.set(id, info);
|
|
119
|
+
}
|
|
120
|
+
return infoCache.get(id)!;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const extractHtmlContent = (htmlString: string) => {
|
|
124
|
+
const $ = cheerio.load(htmlString)
|
|
125
|
+
|
|
126
|
+
const metaTags = $('meta').map((_, el) => {
|
|
127
|
+
const name = $(el).attr('name')
|
|
128
|
+
const content = $(el).attr('content')
|
|
129
|
+
return name && content ? { name, content } : null
|
|
130
|
+
}).get().filter(Boolean)
|
|
131
|
+
|
|
132
|
+
const articleHtml = $('main').html() || ''
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
metaTags,
|
|
136
|
+
articleHtml,
|
|
137
|
+
}
|
|
138
|
+
}
|
package/src/articles/wrapper.tsx
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
4
|
import { SidebarInset, SidebarProvider } from "@c-rex/ui/sidebar";
|
|
5
5
|
import { AppSidebar } from "@c-rex/components/sidebar";
|
|
6
6
|
import { CheckArticleLangToast } from "@c-rex/components/check-article-lang";
|
|
7
7
|
import { Breadcrumb } from "@c-rex/components/breadcrumb";
|
|
8
8
|
import { RenderArticle } from "@c-rex/components/render-article";
|
|
9
9
|
import { CloudDownload, Eye } from "lucide-react";
|
|
10
|
-
import { informationUnitsItems,
|
|
10
|
+
import { informationUnitsItems, SidebarAvailableVersionsInterface, TreeOfContent } from "@c-rex/interfaces";
|
|
11
11
|
import { DOCUMENTS_TYPE_AND_LINK, TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
12
|
-
import { call, generateBreadcrumbItems, generateTreeOfContent } from "@c-rex/utils";
|
|
12
|
+
import { call, generateBreadcrumbItems, generateTreeOfContent, getFileRenditions } from "@c-rex/utils";
|
|
13
13
|
import { DropdownMenu } from "@c-rex/components/dropdown-menu";
|
|
14
14
|
import { FileRenditionType } from "@c-rex/types";
|
|
15
|
+
import { useAppConfig } from "@c-rex/contexts/config-provider";
|
|
15
16
|
|
|
16
17
|
type Props = {
|
|
17
18
|
htmlContent: string,
|
|
@@ -19,38 +20,20 @@ type Props = {
|
|
|
19
20
|
id: string,
|
|
20
21
|
type: string,
|
|
21
22
|
lang: string,
|
|
23
|
+
availableVersions: SidebarAvailableVersionsInterface[],
|
|
24
|
+
packageId: string,
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
filesToDownload: FileRenditionType[],
|
|
25
|
-
filesToOpen: FileRenditionType[]
|
|
26
|
-
}
|
|
26
|
+
|
|
27
27
|
const loadArticleData = async (id: string, type: string, title: string) => {
|
|
28
28
|
const informationUnitsItem = await call<informationUnitsItems>('InformationUnitsService.getItem', { id: id });
|
|
29
|
-
|
|
30
29
|
const { rootNode, result: treeOfContent } = await generateTreeOfContent(informationUnitsItem.directoryNodes);
|
|
31
30
|
|
|
32
31
|
const articleLanguage = informationUnitsItem.languages[0]
|
|
33
|
-
const versionOf = informationUnitsItem.versionOf.shortId
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
const availableVersions = versions.items.map((item) => {
|
|
40
|
-
return {
|
|
41
|
-
shortId: item.shortId,
|
|
42
|
-
link: `/${type}/${item.shortId}`,
|
|
43
|
-
lang: item.language,
|
|
44
|
-
country: item.language.split("-")[1],
|
|
45
|
-
active: item.language === articleLanguage,
|
|
46
|
-
}
|
|
47
|
-
}).sort((a, b) => {
|
|
48
|
-
if (a.lang < b.lang) return -1;
|
|
49
|
-
if (a.lang > b.lang) return 1;
|
|
50
|
-
return 0;
|
|
51
|
-
}) as SidebarAvailableVersionsInterface[];
|
|
52
|
-
|
|
53
|
-
let documents = await call<filesRenditions>("RenditionsService.getFileRenditions", { renditions: informationUnitsItem.renditions });
|
|
33
|
+
let documents: {
|
|
34
|
+
filesToDownload: FileRenditionType[];
|
|
35
|
+
filesToOpen: FileRenditionType[];
|
|
36
|
+
}
|
|
54
37
|
let rootNodeInfoID = "";
|
|
55
38
|
let breadcrumbItems: TreeOfContent[] = [];
|
|
56
39
|
|
|
@@ -58,7 +41,9 @@ const loadArticleData = async (id: string, type: string, title: string) => {
|
|
|
58
41
|
rootNodeInfoID = rootNode.informationUnits[0]?.shortId as string;
|
|
59
42
|
|
|
60
43
|
const childInformationUnit = await call<informationUnitsItems>('InformationUnitsService.getItem', { id: rootNodeInfoID });
|
|
61
|
-
documents =
|
|
44
|
+
documents = getFileRenditions({ renditions: childInformationUnit.renditions });
|
|
45
|
+
} else {
|
|
46
|
+
documents = getFileRenditions({ renditions: informationUnitsItem.renditions });
|
|
62
47
|
}
|
|
63
48
|
|
|
64
49
|
if (type == TOPICS_TYPE_AND_LINK) {
|
|
@@ -80,15 +65,14 @@ const loadArticleData = async (id: string, type: string, title: string) => {
|
|
|
80
65
|
return {
|
|
81
66
|
treeOfContent,
|
|
82
67
|
breadcrumbItems,
|
|
83
|
-
availableVersions,
|
|
84
68
|
documents,
|
|
85
69
|
articleLanguage
|
|
86
70
|
}
|
|
87
71
|
};
|
|
88
72
|
|
|
89
|
-
export const ArticleWrapper = ({ htmlContent, title, id, type, lang }: Props) => {
|
|
73
|
+
export const ArticleWrapper = ({ htmlContent, title, id, type, lang, availableVersions, packageId }: Props) => {
|
|
74
|
+
const { setPackageID } = useAppConfig()
|
|
90
75
|
const [loading, setLoading] = useState<boolean>(true)
|
|
91
|
-
const [availableVersions, setAvailableVersions] = useState<SidebarAvailableVersionsInterface[]>([])
|
|
92
76
|
|
|
93
77
|
|
|
94
78
|
//set available versions on confgi context so will be possible to get the link when change contant language
|
|
@@ -109,16 +93,15 @@ export const ArticleWrapper = ({ htmlContent, title, id, type, lang }: Props) =>
|
|
|
109
93
|
})
|
|
110
94
|
|
|
111
95
|
useEffect(() => {
|
|
112
|
-
|
|
96
|
+
setPackageID(packageId)
|
|
113
97
|
|
|
98
|
+
const fetchData = async () => {
|
|
114
99
|
const {
|
|
115
|
-
availableVersions,
|
|
116
100
|
treeOfContent,
|
|
117
101
|
documents,
|
|
118
102
|
breadcrumbItems,
|
|
119
103
|
} = await loadArticleData(id, type, title)
|
|
120
104
|
|
|
121
|
-
setAvailableVersions(availableVersions)
|
|
122
105
|
setTreeOfContent(treeOfContent)
|
|
123
106
|
setDocuments(documents)
|
|
124
107
|
setBreadcrumbItems(breadcrumbItems)
|
package/src/home/layout.tsx
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { informationUnitsResponse } from "@c-rex/interfaces";
|
|
3
2
|
import { InformationUnitsService } from "@c-rex/services";
|
|
4
3
|
import { HomePage } from "./page";
|
|
5
4
|
import { PageWrapper } from "@c-rex/components/page-wrapper";
|
|
5
|
+
import { WildCardType } from "@c-rex/types";
|
|
6
6
|
|
|
7
7
|
interface HomeProps {
|
|
8
8
|
searchParams: {
|
|
9
9
|
search?: string;
|
|
10
|
-
page
|
|
11
|
-
language
|
|
10
|
+
page: string;
|
|
11
|
+
language: string;
|
|
12
|
+
wildcard: string;
|
|
13
|
+
operator: string;
|
|
14
|
+
like: string;
|
|
15
|
+
package?: string;
|
|
12
16
|
};
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export const HomeLayout = async ({ searchParams }: HomeProps) => {
|
|
16
|
-
const { search, page, language } = searchParams;
|
|
20
|
+
const { search, page, language, wildcard, operator, like, package: packageParam } = searchParams;
|
|
17
21
|
|
|
18
22
|
let data = {
|
|
19
23
|
items: [],
|
|
@@ -22,35 +26,30 @@ export const HomeLayout = async ({ searchParams }: HomeProps) => {
|
|
|
22
26
|
pageNumber: 0
|
|
23
27
|
}
|
|
24
28
|
} as unknown as informationUnitsResponse;
|
|
25
|
-
let selectedLanguages: string[] = [];
|
|
26
29
|
|
|
27
30
|
if (search !== undefined) {
|
|
28
|
-
const pageAux = Number(page);
|
|
29
|
-
const searchValue = search;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (searchValue) {
|
|
37
|
-
const service = new InformationUnitsService();
|
|
38
|
-
|
|
39
|
-
data = await service.getList({
|
|
40
|
-
queries: searchValue.split(" ").join(","),
|
|
41
|
-
page: pageAux,
|
|
42
|
-
fields: ["renditions", "class", "languages", "labels"],
|
|
43
|
-
languages: selectedLanguages
|
|
44
|
-
});
|
|
32
|
+
const filters: string[] = []
|
|
33
|
+
if (packageParam && packageParam.length > 0) {
|
|
34
|
+
filters.push(`packages.shortId=${packageParam}`)
|
|
45
35
|
}
|
|
36
|
+
const service = new InformationUnitsService();
|
|
37
|
+
|
|
38
|
+
data = await service.getList({
|
|
39
|
+
queries: search,
|
|
40
|
+
page: Number(page),
|
|
41
|
+
fields: ["renditions", "class", "languages", "labels"],
|
|
42
|
+
languages: language.split(","),
|
|
43
|
+
wildcard: wildcard as WildCardType,
|
|
44
|
+
operator: operator,
|
|
45
|
+
like: Boolean(like === "true"),
|
|
46
|
+
filters: filters
|
|
47
|
+
});
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
return (
|
|
49
|
-
<PageWrapper title="">
|
|
50
|
-
<HomePage
|
|
51
|
-
data={data}
|
|
52
|
-
selectedLanguages={selectedLanguages}
|
|
53
|
-
/>
|
|
51
|
+
<PageWrapper title="" showInput={false}>
|
|
52
|
+
<HomePage data={data} />
|
|
54
53
|
</PageWrapper>
|
|
55
54
|
);
|
|
56
55
|
};
|
package/src/home/page.tsx
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import React, { FC } from "react";
|
|
3
|
+
import React, { FC, useEffect, useState } from "react";
|
|
4
4
|
import { informationUnitsResponse } from "@c-rex/interfaces";
|
|
5
|
-
import { call } from "@c-rex/utils";
|
|
5
|
+
import { call, getFromCookieString } from "@c-rex/utils";
|
|
6
6
|
import { Button } from "@c-rex/ui/button";
|
|
7
|
-
import { AutoComplete } from "@c-rex/components/autocomplete";
|
|
8
7
|
import { ResultList } from "@c-rex/components/result-list";
|
|
9
8
|
import { useTranslations } from 'next-intl'
|
|
10
|
-
import { parseAsInteger, parseAsString, useQueryStates } from 'nuqs'
|
|
9
|
+
import { parseAsBoolean, parseAsInteger, parseAsString, useQueryStates } from 'nuqs'
|
|
11
10
|
import { DialogFilter } from "@c-rex/components/dialog-filter";
|
|
12
|
-
import {
|
|
13
|
-
import { CONTENT_LANG_KEY } from "@c-rex/constants";
|
|
11
|
+
import { CONTENT_LANG_KEY, WILD_CARD_OPTIONS } from "@c-rex/constants";
|
|
14
12
|
import { useAppConfig } from "@c-rex/contexts/config-provider";
|
|
13
|
+
import { AutoComplete } from "@c-rex/components/autocomplete";
|
|
15
14
|
|
|
16
15
|
interface HomePageProps {
|
|
17
16
|
data: informationUnitsResponse;
|
|
18
|
-
selectedLanguages: string[];
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
export const HomePage: FC<HomePageProps> = ({ data
|
|
22
|
-
const { configs, availableLanguagesAndCountries: availableLanguages, contentLang } = useAppConfig()
|
|
19
|
+
export const HomePage: FC<HomePageProps> = ({ data }) => {
|
|
23
20
|
const t = useTranslations();
|
|
21
|
+
const { configs } = useAppConfig()
|
|
22
|
+
const [disabled, setDisabled] = useState<boolean>(false)
|
|
24
23
|
const [params, setParams] = useQueryStates({
|
|
25
24
|
search: {
|
|
26
25
|
defaultValue: "",
|
|
@@ -28,51 +27,34 @@ export const HomePage: FC<HomePageProps> = ({ data, selectedLanguages }) => {
|
|
|
28
27
|
return value
|
|
29
28
|
},
|
|
30
29
|
},
|
|
31
|
-
operator: parseAsString,
|
|
32
|
-
language: parseAsString,
|
|
33
|
-
page: parseAsInteger,
|
|
34
30
|
}, {
|
|
35
31
|
history: 'push',
|
|
36
32
|
shallow: false,
|
|
37
33
|
});
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//show loading
|
|
47
|
-
getCookie(CONTENT_LANG_KEY)
|
|
48
|
-
.then((cookie) => cookie.value)
|
|
49
|
-
.then((cookie) => {
|
|
50
|
-
setParams({
|
|
51
|
-
search: value,
|
|
52
|
-
operator: "OR",
|
|
53
|
-
page: 1,
|
|
54
|
-
language: cookie,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
};
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (params.search.length > 0) {
|
|
37
|
+
setDisabled(false)
|
|
38
|
+
} else {
|
|
39
|
+
setDisabled(true)
|
|
40
|
+
}
|
|
41
|
+
}, [params])
|
|
58
42
|
|
|
59
43
|
return (
|
|
60
44
|
<div className="container">
|
|
61
45
|
<div className="grid grid-cols-12 gap-4 py-6">
|
|
62
|
-
<div className="col-span-12 sm:col-span-
|
|
46
|
+
<div className="col-span-12 sm:col-span-10 md:col-span-10">
|
|
63
47
|
<AutoComplete
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
embedded={false}
|
|
49
|
+
initialValue={params.search}
|
|
50
|
+
searchByPackage={false}
|
|
67
51
|
/>
|
|
68
52
|
</div>
|
|
69
|
-
<div className="col-span-12 sm:col-span-
|
|
53
|
+
<div className="col-span-12 sm:col-span-2 md:col-span-2">
|
|
70
54
|
<div className="flex justify-end">
|
|
71
55
|
<DialogFilter
|
|
72
|
-
startSelectedLanguages={selectedLanguages}
|
|
73
|
-
availableLanguages={availableLanguages}
|
|
74
56
|
trigger={(
|
|
75
|
-
<Button variant="default">{t("filters")}</Button>
|
|
57
|
+
<Button variant="default" disabled={disabled}>{t("filter.filters")}</Button>
|
|
76
58
|
)}
|
|
77
59
|
/>
|
|
78
60
|
</div>
|