-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(social): link extraction prompt fix
- Loading branch information
Showing
46 changed files
with
480 additions
and
104 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
apps/kyb-app/src/common/components/molecules/ProgressBar/ProgressBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 35 additions & 9 deletions
44
apps/kyb-app/src/common/providers/ThemeProvider/ThemeProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
import { useLayoutEffect } from 'react'; | ||
import { transformThemeToInlineStyles } from '@/utils/transform-theme-to-inline-styles'; | ||
import { APP_LANGUAGE_QUERY_KEY } from '@/common/consts/consts'; | ||
import { IThemeContext } from '@/common/providers/ThemeProvider/types'; | ||
import { ITheme } from '@/common/types/settings'; | ||
import { useUISchemasQuery } from '@/hooks/useUISchemasQuery'; | ||
import { transformThemeToInlineStyles } from '@/utils/transform-theme-to-inline-styles'; | ||
import { useLayoutEffect, useMemo } from 'react'; | ||
import defaultTheme from '../../../../theme.json'; | ||
import { themeContext } from './theme.context'; | ||
|
||
const { Provider } = themeContext; | ||
interface Props { | ||
theme: ITheme; | ||
children: React.ReactNode | React.ReactNode[]; | ||
} | ||
|
||
export const ThemeProvider = ({ theme, children }: Props) => { | ||
export const ThemeProvider = ({ children }: Props) => { | ||
const language = new URLSearchParams(window.location.search).get(APP_LANGUAGE_QUERY_KEY) || 'en'; | ||
const { data: uiSchema, isLoading, error } = useUISchemasQuery(language); | ||
|
||
const theme = useMemo(() => { | ||
if (isLoading) return null; | ||
|
||
if (error) { | ||
console.warn('Failed to load theme', error); | ||
|
||
return defaultTheme.theme; | ||
} | ||
|
||
if (!uiSchema?.uiSchema?.theme) return defaultTheme.theme; | ||
|
||
return uiSchema.uiSchema.theme; | ||
}, [uiSchema, isLoading, error]); | ||
|
||
const context = useMemo(() => ({ themeDefinition: theme } as IThemeContext), [theme]); | ||
|
||
useLayoutEffect(() => { | ||
document | ||
.getElementsByTagName('html')[0] | ||
?.setAttribute('style', transformThemeToInlineStyles(theme)); | ||
}); | ||
if (theme) { | ||
document | ||
.getElementsByTagName('html')[0] | ||
?.setAttribute('style', transformThemeToInlineStyles(theme as ITheme)); | ||
} | ||
}, [theme]); | ||
|
||
return <>{children}</>; | ||
return <Provider value={context}>{children}</Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './ThemeProvider'; | ||
export * from './useTheme'; |
4 changes: 4 additions & 0 deletions
4
apps/kyb-app/src/common/providers/ThemeProvider/theme.context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { IThemeContext } from '@/common/providers/ThemeProvider/types'; | ||
import { createContext } from 'react'; | ||
|
||
export const themeContext = createContext({} as IThemeContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { ISettings } from '@/common/types/settings'; | ||
import { ITheme } from '@/common/types/settings'; | ||
|
||
export type ThemeContext = ISettings['theme']; | ||
export interface IThemeContext { | ||
themeDefinition: ITheme; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { themeContext } from '@/common/providers/ThemeProvider/theme.context'; | ||
import { useContext } from 'react'; | ||
|
||
export const useTheme = () => useContext(themeContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.