@c-rex/components 0.1.5 → 0.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-rex/components",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "files": [
5
5
  "src"
6
6
  ],
@@ -21,9 +21,7 @@ export const CheckArticleLangToast: FC<Props> = ({ availableVersions }) => {
21
21
  if (activeArticle == undefined || activeArticle.lang == contentLang) return
22
22
 
23
23
  const articleAvailable = availableVersions.find((item) => item.lang === contentLang)
24
- if (articleAvailable == undefined) {
25
- articleNotAvailableToast()
26
- } else {
24
+ if (articleAvailable != undefined) {
27
25
  articleAvailableInToast(articleAvailable.lang, articleAvailable.link)
28
26
  }
29
27
  }, [])
@@ -39,12 +37,5 @@ export const CheckArticleLangToast: FC<Props> = ({ availableVersions }) => {
39
37
  })
40
38
  }
41
39
 
42
- const articleNotAvailableToast = () => {
43
- toast(t('sorry'), {
44
- description: t('toast.articleNotAvailable'),
45
- duration: 10000,
46
- })
47
- }
48
-
49
40
  return null
50
41
  }
@@ -1,15 +1,19 @@
1
1
  "use client"
2
2
 
3
- import React, { startTransition } from "react";
3
+ import { startTransition } from "react";
4
4
  import { SharedLanguageSwitch } from "./shared";
5
5
  import { getFromCookieString, setCookie } from "@c-rex/utils";
6
6
  import { CONTENT_LANG_KEY } from "@c-rex/constants";
7
7
  import { useQueryState } from "nuqs"
8
8
  import { useAppConfig } from "@c-rex/contexts/config-provider";
9
+ import { useTranslations } from "next-intl";
10
+ import { toast } from "sonner"
9
11
 
10
12
  export const ContentLanguageSwitch = () => {
11
- const { availableLanguagesAndCountries, setContentLang, availableVersions } = useAppConfig()
13
+ const t = useTranslations();
12
14
  const contentLang = getFromCookieString(document.cookie, CONTENT_LANG_KEY)
15
+ const { availableLanguagesAndCountries, setContentLang, availableVersions } = useAppConfig()
16
+
13
17
  const [queryLanguage, setContentLanguage] = useQueryState('language', {
14
18
  history: 'push',
15
19
  shallow: false,
@@ -28,11 +32,20 @@ export const ContentLanguageSwitch = () => {
28
32
 
29
33
  if (filteredList.length > 0 && filteredList[0]) {
30
34
  window.location.href = filteredList[0].link as string;
35
+ } else {
36
+ articleNotAvailableToast()
31
37
  }
32
38
  }
33
39
  });
34
40
  };
35
41
 
42
+ const articleNotAvailableToast = () => {
43
+ toast(t('sorry'), {
44
+ description: t('toast.articleNotAvailable'),
45
+ duration: 10000,
46
+ })
47
+ }
48
+
36
49
  return (
37
50
  <SharedLanguageSwitch
38
51
  availableLanguagesAndCountries={availableLanguagesAndCountries}