@c-rex/templates 0.0.4 → 0.0.6
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 +3 -2
- package/src/home/layout.tsx +61 -0
- package/src/home/page.tsx +65 -0
- package/src/info/page.tsx +66 -0
- package/src/layout.tsx +26 -0
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { informationUnits } from "@c-rex/interfaces";
|
|
2
|
+
import { InformationUnitsService } from "@c-rex/services";
|
|
3
|
+
import { SearchStateWrapper } from "@c-rex/components/providers/search-state-wrapper";
|
|
4
|
+
import { HomePage } from "./page";
|
|
5
|
+
|
|
6
|
+
interface SearchParams {
|
|
7
|
+
search?: string;
|
|
8
|
+
page?: string;
|
|
9
|
+
language?: string;
|
|
10
|
+
}
|
|
11
|
+
interface HomeProps {
|
|
12
|
+
searchParams: SearchParams;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const loadData = async ({
|
|
16
|
+
search,
|
|
17
|
+
page,
|
|
18
|
+
language,
|
|
19
|
+
}: SearchParams): Promise<any> => {
|
|
20
|
+
const service = new InformationUnitsService();
|
|
21
|
+
const pageAux = page != undefined ? Number(page) : 0;
|
|
22
|
+
const searchValue = search != undefined ? (search as string) : "";
|
|
23
|
+
const availableLanguages = await service.getLanguages();
|
|
24
|
+
|
|
25
|
+
let data = { items: [] } as unknown as informationUnits;
|
|
26
|
+
let selectedLanguages: string[] = [];
|
|
27
|
+
|
|
28
|
+
if (language != undefined) {
|
|
29
|
+
const aux = language as string;
|
|
30
|
+
selectedLanguages = aux.split(",");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (searchValue) {
|
|
34
|
+
data = await service.getList(
|
|
35
|
+
searchValue,
|
|
36
|
+
pageAux,
|
|
37
|
+
selectedLanguages,
|
|
38
|
+
[],
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
data: data,
|
|
44
|
+
filters: {
|
|
45
|
+
searchValue: searchValue,
|
|
46
|
+
page: pageAux,
|
|
47
|
+
selectedLanguage: selectedLanguages,
|
|
48
|
+
availableLanguages: availableLanguages,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const HomeLayout = async ({ searchParams }: HomeProps) => {
|
|
54
|
+
const { data, filters } = await loadData(searchParams);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<SearchStateWrapper filters={filters}>
|
|
58
|
+
<HomePage data={data} />
|
|
59
|
+
</SearchStateWrapper>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { FC } from "react";
|
|
4
|
+
import { informationUnits } from "@c-rex/interfaces";
|
|
5
|
+
import { InformationUnitsService } from "@c-rex/services";
|
|
6
|
+
import { updateUrlWithParams } from "@c-rex/utils";
|
|
7
|
+
import { useRouter } from "next/navigation";
|
|
8
|
+
import { Button } from "@c-rex/ui/button";
|
|
9
|
+
import { AutoComplete } from "@c-rex/components/autocomplete";
|
|
10
|
+
import { ResultList } from "@c-rex/components/result-list";
|
|
11
|
+
|
|
12
|
+
//import { useSearchContext } from '@/contexts/search'; TODO: replace for a lib how manage states from URL
|
|
13
|
+
|
|
14
|
+
interface HomePageProps {
|
|
15
|
+
data: informationUnits;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const HomePage: FC<HomePageProps> = ({ data }) => {
|
|
19
|
+
const router = useRouter();
|
|
20
|
+
const initialValue = null;
|
|
21
|
+
|
|
22
|
+
const onSearch = (value: string): Promise<string[]> => {
|
|
23
|
+
const service = new InformationUnitsService();
|
|
24
|
+
return service.getSuggestions(value);
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const onSelect = (value: string) => {
|
|
29
|
+
updateUrlWithParams(router, [
|
|
30
|
+
{
|
|
31
|
+
key: "search",
|
|
32
|
+
value: value.split(" ").join(","),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "operator",
|
|
36
|
+
value: "OR",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: "page",
|
|
40
|
+
value: "1",
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div className="container">
|
|
47
|
+
<div className="grid grid-cols-12 gap-4 py-6">
|
|
48
|
+
<div className="col-span-12 sm:col-span-9 md:col-span-10">
|
|
49
|
+
<AutoComplete
|
|
50
|
+
initialValue={initialValue ?? ""}
|
|
51
|
+
onSearch={onSearch}
|
|
52
|
+
onSelect={onSelect}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
<div className="col-span-12 sm:col-span-3 md:col-span-2">
|
|
56
|
+
<div className="flex justify-end">
|
|
57
|
+
<Button variant="default">Filters</Button>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<ResultList items={data.items} />
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { FC, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { InformationUnitsService } from "@c-rex/services";
|
|
5
|
+
import { TreeOfContent } from "@c-rex/interfaces";
|
|
6
|
+
import { SidebarInset, SidebarProvider, SidebarTrigger } from "@c-rex/ui/sidebar";
|
|
7
|
+
import { Separator } from "@c-rex/ui/separator";
|
|
8
|
+
import { AppSidebar } from "@c-rex/components/sidebar";
|
|
9
|
+
import { Breadcrumb } from "@c-rex/components/breadcrumb";
|
|
10
|
+
//import { generateTreeOfContent } from "@c-rex/utils";
|
|
11
|
+
//import { generateBreadcrumbItems } from "@c-rex/utils";
|
|
12
|
+
|
|
13
|
+
interface InfoPageTemplateProps {
|
|
14
|
+
htmlContent: string;
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const InfoPageTemplate: FC<InfoPageTemplateProps> = ({ htmlContent, id }) => {
|
|
19
|
+
const [breadcrumbItems, setBreadcrumbItems] = useState<TreeOfContent[]>([]);
|
|
20
|
+
const [sidebarItems, setSidebarItems] = useState<TreeOfContent[]>([]);
|
|
21
|
+
const [loading, setLoading] = useState(true);
|
|
22
|
+
const effectRan = useRef(false);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (effectRan.current) return;
|
|
26
|
+
effectRan.current = true;
|
|
27
|
+
|
|
28
|
+
const loadNavigationData = async () => {
|
|
29
|
+
const service = new InformationUnitsService();
|
|
30
|
+
const informationUnitsItem = await service.getItem(id);
|
|
31
|
+
|
|
32
|
+
if (informationUnitsItem?.directoryNodes != undefined) {
|
|
33
|
+
/*
|
|
34
|
+
const treeOfContent = await generateTreeOfContent(
|
|
35
|
+
informationUnitsItem.directoryNodes,
|
|
36
|
+
);
|
|
37
|
+
const breadcrumbItems = generateBreadcrumbItems(treeOfContent);
|
|
38
|
+
|
|
39
|
+
setBreadcrumbItems(breadcrumbItems);
|
|
40
|
+
setSidebarItems(treeOfContent);
|
|
41
|
+
*/
|
|
42
|
+
setLoading(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
loadNavigationData();
|
|
47
|
+
}, [id]);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<SidebarProvider>
|
|
51
|
+
<AppSidebar data={sidebarItems} loading={loading} />
|
|
52
|
+
<SidebarInset>
|
|
53
|
+
<header className="flex h-16 shrink-0 items-center">
|
|
54
|
+
<SidebarTrigger className="-ml-1" />
|
|
55
|
+
<Separator orientation="vertical" className="mr-2 h-4" />
|
|
56
|
+
<Breadcrumb items={breadcrumbItems} loading={loading} />
|
|
57
|
+
</header>
|
|
58
|
+
|
|
59
|
+
<div
|
|
60
|
+
className="flex"
|
|
61
|
+
dangerouslySetInnerHTML={{ __html: htmlContent }}
|
|
62
|
+
/>
|
|
63
|
+
</SidebarInset>
|
|
64
|
+
</SidebarProvider>
|
|
65
|
+
);
|
|
66
|
+
};
|
package/src/layout.tsx
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//import "@/styles/global.css";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { NavBar } from "@c-rex/components/navbar";
|
|
5
|
+
|
|
6
|
+
interface DefaultRootLayoutProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const DefaultRootLayout = ({
|
|
11
|
+
children,
|
|
12
|
+
}: DefaultRootLayoutProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<html lang="en" suppressHydrationWarning>
|
|
15
|
+
<head />
|
|
16
|
+
<body className="min-h-screen bg-background font-sans antialiased">
|
|
17
|
+
<div className="items-center flex flex-col">
|
|
18
|
+
|
|
19
|
+
<NavBar />
|
|
20
|
+
|
|
21
|
+
<div className="container pt-6">{children}</div>
|
|
22
|
+
</div>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
25
|
+
);
|
|
26
|
+
}
|