@c-rex/components 0.1.17 → 0.1.19
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/bookmark-button.tsx +1 -1
- package/src/info/info-table.tsx +20 -2
- package/src/navbar/language-switcher/content-language-switch.tsx +3 -1
- package/src/navbar/language-switcher/ui-language-switch.tsx +4 -2
- package/src/right-sidebar.tsx +4 -4
- package/src/stores/favorites-store.ts +10 -2
- package/src/stores/language-store.ts +0 -22
package/package.json
CHANGED
package/src/bookmark-button.tsx
CHANGED
|
@@ -48,7 +48,7 @@ export const BookmarkButton: FC<{ markersList: Favorite[], trigger?: ReactNode }
|
|
|
48
48
|
<FaRegBookmark className={cn("w-5", `text-${item.color}`)} />
|
|
49
49
|
</TableCell>
|
|
50
50
|
<TableCell>
|
|
51
|
-
<Link href={
|
|
51
|
+
<Link href={`${window.location.origin}/topics/${item.id}`}>
|
|
52
52
|
{item.label}
|
|
53
53
|
</Link>
|
|
54
54
|
</TableCell>
|
package/src/info/info-table.tsx
CHANGED
|
@@ -21,6 +21,8 @@ import { Flag } from "../flag";
|
|
|
21
21
|
import { Button } from "@c-rex/ui/button";
|
|
22
22
|
import { useLanguageStore } from "../stores/language-store";
|
|
23
23
|
import { FileIcon } from "../file-icon";
|
|
24
|
+
import { BookmarkButton } from "../bookmark-button";
|
|
25
|
+
import { FaRegBookmark } from "react-icons/fa6";
|
|
24
26
|
|
|
25
27
|
type Props = {
|
|
26
28
|
title: string;
|
|
@@ -31,7 +33,7 @@ type Props = {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
|
|
34
|
-
export const InfoTable: FC<Props> = ({ title, items, files, availableVersions }) => {
|
|
36
|
+
export const InfoTable: FC<Props> = ({ title, items, files, availableVersions, markersList }) => {
|
|
35
37
|
const t = useTranslations();
|
|
36
38
|
const uiLang = useLanguageStore(state => state.uiLang);
|
|
37
39
|
const newItems = filteredItems(items)
|
|
@@ -39,8 +41,24 @@ export const InfoTable: FC<Props> = ({ title, items, files, availableVersions })
|
|
|
39
41
|
return (
|
|
40
42
|
<Card className="p-0 !pt-4">
|
|
41
43
|
<CardHeader>
|
|
42
|
-
<CardTitle className="text-lg flex justify-between">
|
|
44
|
+
<CardTitle className="text-lg flex justify-between items-end">
|
|
43
45
|
{title}
|
|
46
|
+
|
|
47
|
+
{(markersList && markersList.length > 0) && (
|
|
48
|
+
<BookmarkButton
|
|
49
|
+
markersList={markersList.filter(item => item.label.length > 0)}
|
|
50
|
+
trigger={
|
|
51
|
+
<Button variant="outline" size="icon" className="relative">
|
|
52
|
+
<FaRegBookmark className="!w-5 color-primary" />
|
|
53
|
+
<span
|
|
54
|
+
className="absolute -top-[10px] -right-[10px] min-w-5 min-h-5 bg-primary text-white rounded-full"
|
|
55
|
+
>
|
|
56
|
+
{markersList.length}
|
|
57
|
+
</span>
|
|
58
|
+
</Button>
|
|
59
|
+
}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
44
62
|
</CardTitle>
|
|
45
63
|
</CardHeader>
|
|
46
64
|
<CardContent className="space-y-3 !p-0">
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { startTransition } from "react";
|
|
4
4
|
import { SharedLanguageSwitch } from "./shared";
|
|
5
|
-
import { BLOG_TYPE_AND_LINK, DOCUMENTS_TYPE_AND_LINK, TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
5
|
+
import { BLOG_TYPE_AND_LINK, CONTENT_LANG_KEY, DOCUMENTS_TYPE_AND_LINK, TOPICS_TYPE_AND_LINK } from "@c-rex/constants";
|
|
6
6
|
import { useQueryState } from "nuqs"
|
|
7
7
|
import { useAppConfig } from "@c-rex/contexts/config-provider";
|
|
8
8
|
import { useTranslations } from "next-intl";
|
|
9
9
|
import { toast } from "sonner"
|
|
10
10
|
import { useLanguageStore } from "../../stores/language-store";
|
|
11
11
|
import { useSearchSettingsStore } from "../../stores/search-settings-store";
|
|
12
|
+
import { setCookie } from "@c-rex/utils/cookies";
|
|
12
13
|
|
|
13
14
|
export const ContentLanguageSwitch = () => {
|
|
14
15
|
const t = useTranslations();
|
|
@@ -41,6 +42,7 @@ export const ContentLanguageSwitch = () => {
|
|
|
41
42
|
const changeContentLanguage = (locale: string) => {
|
|
42
43
|
startTransition(() => {
|
|
43
44
|
setContentLang(locale)
|
|
45
|
+
setCookie(CONTENT_LANG_KEY, locale);
|
|
44
46
|
updatePreferences({ language: [locale] })
|
|
45
47
|
|
|
46
48
|
if (queryLanguage != null) {
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { FC, startTransition } from "react";
|
|
4
4
|
import { SharedLanguageSwitch } from "./shared";
|
|
5
|
-
import { UI_LANG_OPTIONS } from "@c-rex/constants";
|
|
6
|
-
import { getCountryCodeByLang } from "@c-rex/utils";
|
|
5
|
+
import { UI_LANG_KEY, UI_LANG_OPTIONS } from "@c-rex/constants";
|
|
6
|
+
import { getCountryCodeByLang, } from "@c-rex/utils";
|
|
7
|
+
import { setCookie } from "@c-rex/utils/cookies";
|
|
7
8
|
import { useLanguageStore } from "../../stores/language-store";
|
|
8
9
|
|
|
9
10
|
export const UILanguageSwitch: FC = () => {
|
|
@@ -21,6 +22,7 @@ export const UILanguageSwitch: FC = () => {
|
|
|
21
22
|
const setUILanguage = (locale: string) => {
|
|
22
23
|
startTransition(() => {
|
|
23
24
|
setUiLang(locale)
|
|
25
|
+
setCookie(UI_LANG_KEY, locale);
|
|
24
26
|
|
|
25
27
|
window.location.reload()
|
|
26
28
|
});
|
package/src/right-sidebar.tsx
CHANGED
|
@@ -32,10 +32,10 @@ export function RightSidebar({
|
|
|
32
32
|
const t = useTranslations();
|
|
33
33
|
const favoritesDocuments = useFavoritesStore((state) => state.documents);
|
|
34
34
|
const isFavoriteDocument = Object.keys(favoritesDocuments).some((docId) => docId === documentId);
|
|
35
|
-
let
|
|
35
|
+
let favoritesList: Favorite[] = []
|
|
36
36
|
|
|
37
|
-
if (
|
|
38
|
-
|
|
37
|
+
if (favoritesDocuments && favoritesDocuments[documentId]) {
|
|
38
|
+
favoritesList = favoritesDocuments[documentId].topics;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return (
|
|
@@ -50,7 +50,7 @@ export function RightSidebar({
|
|
|
50
50
|
items={documentInfo}
|
|
51
51
|
files={files}
|
|
52
52
|
availableVersions={documentAvailableVersions}
|
|
53
|
-
markersList={isFavoriteDocument ?
|
|
53
|
+
markersList={isFavoriteDocument ? favoritesList : []}
|
|
54
54
|
/>
|
|
55
55
|
)}
|
|
56
56
|
|
|
@@ -43,9 +43,17 @@ export const useFavoritesStore = create<FavoritesStore>()(
|
|
|
43
43
|
}),
|
|
44
44
|
unfavoriteDocument: (id: string) =>
|
|
45
45
|
set((state) => {
|
|
46
|
+
let newFavorites = [...state.favorites];
|
|
46
47
|
const documentsCopy = { ...state.documents };
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
if (documentsCopy[id]) {
|
|
50
|
+
const favoritesToRemove = documentsCopy[id].topics.map(topic => topic.id);
|
|
51
|
+
newFavorites = newFavorites.filter(fav => fav.id !== id && !favoritesToRemove.includes(fav.id));
|
|
52
|
+
|
|
53
|
+
delete documentsCopy[id];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { documents: documentsCopy, favorites: newFavorites };
|
|
49
57
|
}),
|
|
50
58
|
}), {
|
|
51
59
|
name: "c-rex-favorites",
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { UI_LANG_KEY } from "@c-rex/constants";
|
|
2
|
-
import { AVAILABLE_CONTENT_LANG_KEY } from "@c-rex/constants";
|
|
3
|
-
import { CONTENT_LANG_KEY } from "@c-rex/constants";
|
|
4
1
|
import { LanguageAndCountries } from "@c-rex/interfaces";
|
|
5
|
-
import { getCookie, setCookie } from "@c-rex/utils";
|
|
6
2
|
import { create } from "zustand";
|
|
7
3
|
|
|
8
4
|
type LanguageStoreType = {
|
|
@@ -12,7 +8,6 @@ type LanguageStoreType = {
|
|
|
12
8
|
setContentLang: (v: string) => void;
|
|
13
9
|
setUiLang: (v: string) => void;
|
|
14
10
|
setAvailableLanguages: (list: LanguageAndCountries[]) => void;
|
|
15
|
-
hydrate: () => void;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
13
|
export const useLanguageStore = create<LanguageStoreType>((set) => ({
|
|
@@ -21,28 +16,11 @@ export const useLanguageStore = create<LanguageStoreType>((set) => ({
|
|
|
21
16
|
availableLanguages: [],
|
|
22
17
|
setContentLang: (v) => {
|
|
23
18
|
set({ contentLang: v });
|
|
24
|
-
setCookie(CONTENT_LANG_KEY, v, 7);
|
|
25
19
|
},
|
|
26
20
|
setUiLang: (v) => {
|
|
27
21
|
set({ uiLang: v });
|
|
28
|
-
setCookie(UI_LANG_KEY, v, 7);
|
|
29
22
|
},
|
|
30
23
|
setAvailableLanguages: (list) => {
|
|
31
24
|
set({ availableLanguages: list });
|
|
32
|
-
setCookie(AVAILABLE_CONTENT_LANG_KEY, JSON.stringify(list), 7);
|
|
33
|
-
},
|
|
34
|
-
hydrate: () => {
|
|
35
|
-
set({
|
|
36
|
-
uiLang: getCookie(UI_LANG_KEY),
|
|
37
|
-
contentLang: getCookie(CONTENT_LANG_KEY),
|
|
38
|
-
availableLanguages: (() => {
|
|
39
|
-
const raw = getCookie(AVAILABLE_CONTENT_LANG_KEY);
|
|
40
|
-
try {
|
|
41
|
-
return raw ? JSON.parse(raw) : [];
|
|
42
|
-
} catch {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
})(),
|
|
46
|
-
});
|
|
47
25
|
},
|
|
48
26
|
}));
|