Skip to content

Commit abdbcb8

Browse files
authored
Merge pull request xch-dev#650 from dkackman/theme-lib
switch to lib
2 parents bb2d9b1 + ed54541 commit abdbcb8

20 files changed

+76
-2073
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"tailwindcss-animate": "^1.0.7",
7575
"tauri-plugin-safe-area-insets": "^0.1.0",
7676
"tauri-plugin-sage": "file:./tauri-plugin-sage",
77+
"theme-o-rama": "0.1.0-beta.9",
7778
"usehooks-ts": "^3.1.0",
7879
"zod": "^3.23.8",
7980
"zustand": "^4.5.5"

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { discoverThemes, resolveThemeImage } from '@/lib/themes';
12
import { i18n } from '@lingui/core';
23
import { I18nProvider } from '@lingui/react';
34
import { useEffect, useState } from 'react';
@@ -9,6 +10,7 @@ import {
910
} from 'react-router-dom';
1011
import { Slide, ToastContainer } from 'react-toastify';
1112
import 'react-toastify/dist/ReactToastify.css';
13+
import { ThemeProvider, useTheme } from 'theme-o-rama';
1214
import { useLocalStorage } from 'usehooks-ts';
1315
import { BiometricProvider } from './contexts/BiometricContext';
1416
import { ErrorProvider } from './contexts/ErrorContext';
@@ -21,7 +23,6 @@ import {
2123
import { PeerProvider } from './contexts/PeerContext';
2224
import { PriceProvider } from './contexts/PriceContext';
2325
import { SafeAreaProvider } from './contexts/SafeAreaContext';
24-
import { ThemeProvider, useTheme } from './contexts/ThemeContext';
2526
import { WalletConnectProvider } from './contexts/WalletConnectContext';
2627
import { WalletProvider } from './contexts/WalletContext';
2728
import useInitialization from './hooks/useInitialization';
@@ -151,7 +152,10 @@ export default function App() {
151152

152153
return (
153154
<LanguageProvider locale={locale} setLocale={setLocale}>
154-
<ThemeProvider>
155+
<ThemeProvider
156+
discoverThemes={discoverThemes}
157+
imageResolver={resolveThemeImage}
158+
>
155159
<SafeAreaProvider>
156160
<ErrorProvider>
157161
<BiometricProvider>

src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useInsets } from '@/contexts/SafeAreaContext';
2-
import { useTheme } from '@/contexts/ThemeContext';
32
import { useWallet } from '@/contexts/WalletContext';
43
import iconDark from '@/icon-dark.png';
54
import iconLight from '@/icon-light.png';
@@ -10,6 +9,7 @@ import { AnimatePresence, motion } from 'framer-motion';
109
import { ChevronLeft, Menu } from 'lucide-react';
1110
import { PropsWithChildren, ReactNode } from 'react';
1211
import { Link, useLocation, useNavigate } from 'react-router-dom';
12+
import { useTheme } from 'theme-o-rama';
1313
import { BottomNav, TopNav } from './Nav';
1414
import { Button } from './ui/button';
1515
import { Sheet, SheetContent, SheetTrigger } from './ui/sheet';

src/components/Layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
TooltipTrigger,
77
} from '@/components/ui/tooltip';
88
import { useInsets } from '@/contexts/SafeAreaContext';
9-
import { useTheme } from '@/contexts/ThemeContext';
109
import { useWallet } from '@/contexts/WalletContext';
1110
import iconDark from '@/icon-dark.png';
1211
import iconLight from '@/icon-light.png';
1312
import { t } from '@lingui/core/macro';
1413
import { PanelLeft, PanelLeftClose } from 'lucide-react';
1514
import { PropsWithChildren } from 'react';
1615
import { Link, useLocation } from 'react-router-dom';
16+
import { useTheme } from 'theme-o-rama';
1717
import { useLocalStorage } from 'usehooks-ts';
1818
import { BottomNav, TopNav } from './Nav';
1919

src/components/ThemeCard.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { commands } from '@/bindings';
2-
import { useTheme } from '@/contexts/ThemeContext';
32
import { useErrors } from '@/hooks/useErrors';
4-
import { applyThemeIsolated, isUserTheme } from '@/lib/theme';
5-
import { Theme } from '@/lib/theme.type';
3+
import { hasTag } from '@/lib/themes';
64
import { t } from '@lingui/core/macro';
75
import { Trans } from '@lingui/react/macro';
86
import { Check, Trash2 } from 'lucide-react';
97
import { useEffect, useRef, useState } from 'react';
108
import { toast } from 'react-toastify';
9+
import { applyThemeIsolated, Theme, useTheme } from 'theme-o-rama';
1110
import { Button } from './ui/button';
1211
import {
1312
Dialog,
@@ -47,7 +46,7 @@ export function ThemeCard({
4746
};
4847

4948
const handleDeleteTheme = async () => {
50-
if (isUserTheme(theme)) {
49+
if (hasTag(theme, 'user')) {
5150
setIsDeleting(true);
5251
try {
5352
await commands.deleteUserTheme({ nft_id: theme.name });
@@ -96,7 +95,7 @@ export function ThemeCard({
9695
</h3>
9796
<div className='flex items-center gap-2'>
9897
{isSelected && <Check className='h-4 w-4' style={checkStyles} />}
99-
{isUserTheme(theme) && (
98+
{hasTag(theme, 'user') && (
10099
<Button
101100
onClick={handleDeleteClick}
102101
disabled={isDeleting}
@@ -155,7 +154,7 @@ export function ThemeCard({
155154
aria-label={t`Theme selected`}
156155
/>
157156
)}
158-
{isUserTheme(theme) && (
157+
{hasTag(theme, 'user') && (
159158
<Button
160159
onClick={handleDeleteClick}
161160
disabled={isDeleting}

src/components/ThemeSelector.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { useTheme } from '@/contexts/ThemeContext';
2-
import { isFeaturedTheme, isUserTheme } from '@/lib/theme';
3-
import { Theme } from '@/lib/theme.type';
1+
import { hasTag } from '@/lib/themes';
42
import { Trans } from '@lingui/react/macro';
53
import { Loader2 } from 'lucide-react';
4+
import { Theme, useTheme } from 'theme-o-rama';
65
import { ThemeCard } from './ThemeCard';
76

87
export function ThemeSelector() {
@@ -40,15 +39,20 @@ export function ThemeSelector() {
4039

4140
// Group themes by isUserTheme and isFeatured, sort alphabetically within each group
4241
const featuredThemes: Theme[] = availableThemes
43-
.filter((theme) => !isUserTheme(theme) && isFeaturedTheme(theme))
42+
.filter((theme) => !hasTag(theme, 'user') && hasTag(theme, 'featured'))
4443
.sort((a, b) => a.displayName.localeCompare(b.displayName));
4544

4645
const defaultThemes = availableThemes
47-
.filter((theme) => !isUserTheme(theme) && !isFeaturedTheme(theme))
46+
.filter(
47+
(theme) =>
48+
!hasTag(theme, 'user') &&
49+
!hasTag(theme, 'featured') &&
50+
!hasTag(theme, 'hidden'),
51+
)
4852
.sort((a, b) => a.displayName.localeCompare(b.displayName));
4953

5054
const userThemes = availableThemes
51-
.filter((theme) => isUserTheme(theme))
55+
.filter((theme) => hasTag(theme, 'user'))
5256
.sort((a, b) => a.displayName.localeCompare(b.displayName));
5357

5458
return (

src/components/WalletCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from '@/components/ui/dropdown-menu';
2020
import { Input } from '@/components/ui/input';
2121
import { Label } from '@/components/ui/label';
22-
import { useTheme } from '@/contexts/ThemeContext';
2322
import { useBiometric } from '@/hooks/useBiometric';
2423
import { useErrors } from '@/hooks/useErrors';
2524
import { useSortable } from '@dnd-kit/sortable';
@@ -44,6 +43,7 @@ import { useEffect, useState } from 'react';
4443
import { useNavigate } from 'react-router-dom';
4544
import { toast } from 'react-toastify';
4645
import { Spoiler } from 'spoiled';
46+
import { useTheme } from 'theme-o-rama';
4747
import { commands, KeyInfo, SecretKeyInfo } from '../bindings';
4848
import { CustomError } from '../contexts/ErrorContext';
4949
import { useWallet } from '../contexts/WalletContext';

src/components/ui/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
22
import { Cross2Icon } from '@radix-ui/react-icons';
33
import * as React from 'react';
44

5-
import { useTheme } from '@/contexts/ThemeContext';
65
import { cn } from '@/lib/utils';
6+
import { useTheme } from 'theme-o-rama';
77

88
const Dialog = DialogPrimitive.Root;
99

src/contexts/ThemeContext.tsx

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)