Skip to content

Commit

Permalink
fix: types (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
oktapodia authored Sep 9, 2024
1 parent e323e17 commit 56fa9bb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/app/[lng]/quests/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function PartnerThemeLayout({
enableSystem
enableColorScheme
>
<ThemeProviderV2>
<ThemeProviderV2 themes={[]}>
<Layout>{children}</Layout>
</ThemeProviderV2>
</NextThemeProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[lng]/scan/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function PartnerThemeLayout({
enableSystem
enableColorScheme
>
<ThemeProviderV2>
<ThemeProviderV2 themes={[]}>
<Layout>{children}</Layout>
</ThemeProviderV2>
</NextThemeProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Widgets/Widget.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export interface WidgetProps extends Omit<BlogWidgetProps, 'allowChains'> {
widgetIntegrator?: string;
starterVariant: StarterVariantType;
activeThemeMode?: ThemeModesSupported;
activeTheme?: any; // TODO: Fix it
activeTheme?: string;
}
20 changes: 15 additions & 5 deletions src/providers/ThemeProviderV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import {
import { CssBaseline } from '@mui/material';
import { ThemeProvider as MuiThemeProvider } from '@mui/material/styles';
import { deepmerge } from '@mui/utils';
import type { PartnerThemesData } from '@/types/strapi';
import { useTheme } from 'next-themes';
import { useEffect, useState } from 'react';
import { useCookies } from 'react-cookie';
import { darkTheme, lightTheme } from 'src/theme';

function getPartnerTheme(themes: any[], activeTheme: string) {
function getPartnerTheme(themes: PartnerThemesData[], activeTheme?: string) {
return themes?.find((d) => d.attributes.uid === activeTheme)?.attributes;
}

function getMuiTheme(themes: any[], activeTheme: string) {
if (['dark', 'system'].includes(activeTheme)) {
function getMuiTheme(themes: PartnerThemesData[], activeTheme?: string) {
if (activeTheme && ['dark', 'system'].includes(activeTheme)) {
return darkTheme;
} else if (activeTheme === 'light') {
return lightTheme;
Expand All @@ -39,17 +40,26 @@ function getMuiTheme(themes: any[], activeTheme: string) {
return deepmerge(baseTheme, formattedTheme.activeMUITheme);
}

interface ThemeProviderV2Props {
children: React.ReactNode;
activeTheme?: string;
themes: PartnerThemesData[];
}

/**
* Your app's theme provider component.
* 'use client' is essential for next-themes to work with app-dir.
*/
export function ThemeProviderV2({ children, activeTheme, themes }: any) {
export function ThemeProviderV2({
children,
activeTheme,
themes,
}: ThemeProviderV2Props) {
const { resolvedTheme, forcedTheme, ...props2 } = useTheme();
const [cookie, setCookie] = useCookies(['theme']);
const [partnerThemes, setPartnerThemes] = useSettingsStore((state) => [
state.partnerThemes,
state.setPartnerThemes,
state.setActiveTheme,
]);
const [configTheme, setConfigTheme] = useSettingsStore((state) => [
state.configTheme,
Expand Down
5 changes: 0 additions & 5 deletions src/stores/settings/SettingsStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export const useSettingsStore = createWithEqualityFn(
...defaultSettings,

// Mode
setActiveTheme: (activeTheme: string) => {
set({
activeTheme: activeTheme,
});
},
setConfigTheme: (configTheme: PartnerThemeConfig) => {
set({
configTheme,
Expand Down
5 changes: 2 additions & 3 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ export interface SettingsState extends SettingsProps {
// Mode
setThemeMode: (mode: ThemeModesSupported) => void;

setActiveTheme: (activeTheme: any) => void;
setConfigTheme: (configTheme: any) => void;
setWidgetTheme: (widgetTheme: any) => void;
setConfigTheme: (configTheme: Partial<PartnerThemeConfig>) => void;
setWidgetTheme: (widgetTheme: { config: Partial<WidgetConfig> }) => void; // maybe config

// Installed Wallets
setClientWallets: (wallet: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formatTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function getLogoData(theme: PartnerThemesAttributes) {
}

export function formatConfig(
theme: PartnerThemesAttributes,
theme?: PartnerThemesAttributes,
): Partial<PartnerThemeConfig> {
if (!theme) {
return {
Expand Down

0 comments on commit 56fa9bb

Please sign in to comment.