@checkstack/theme-frontend 0.0.6 → 0.1.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @checkstack/theme-frontend
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7a23261: ## TanStack Query Integration
|
|
8
|
+
|
|
9
|
+
Migrated all frontend components to use `usePluginClient` hook with TanStack Query integration, replacing the legacy `forPlugin()` pattern.
|
|
10
|
+
|
|
11
|
+
### New Features
|
|
12
|
+
|
|
13
|
+
- **`usePluginClient` hook**: Provides type-safe access to plugin APIs with `.useQuery()` and `.useMutation()` methods
|
|
14
|
+
- **Automatic request deduplication**: Multiple components requesting the same data share a single network request
|
|
15
|
+
- **Built-in caching**: Configurable stale time and cache duration per query
|
|
16
|
+
- **Loading/error states**: TanStack Query provides `isLoading`, `error`, `isRefetching` states automatically
|
|
17
|
+
- **Background refetching**: Stale data is automatically refreshed when components mount
|
|
18
|
+
|
|
19
|
+
### Contract Changes
|
|
20
|
+
|
|
21
|
+
All RPC contracts now require `operationType: "query"` or `operationType: "mutation"` metadata:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
const getItems = proc()
|
|
25
|
+
.meta({ operationType: "query", access: [access.read] })
|
|
26
|
+
.output(z.array(itemSchema))
|
|
27
|
+
.query();
|
|
28
|
+
|
|
29
|
+
const createItem = proc()
|
|
30
|
+
.meta({ operationType: "mutation", access: [access.manage] })
|
|
31
|
+
.input(createItemSchema)
|
|
32
|
+
.output(itemSchema)
|
|
33
|
+
.mutation();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Migration
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// Before (forPlugin pattern)
|
|
40
|
+
const api = useApi(myPluginApiRef);
|
|
41
|
+
const [items, setItems] = useState<Item[]>([]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
api.getItems().then(setItems);
|
|
44
|
+
}, [api]);
|
|
45
|
+
|
|
46
|
+
// After (usePluginClient pattern)
|
|
47
|
+
const client = usePluginClient(MyPluginApi);
|
|
48
|
+
const { data: items, isLoading } = client.getItems.useQuery({});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Bug Fixes
|
|
52
|
+
|
|
53
|
+
- Fixed `rpc.test.ts` test setup for middleware type inference
|
|
54
|
+
- Fixed `SearchDialog` to use `setQuery` instead of deprecated `search` method
|
|
55
|
+
- Fixed null→undefined warnings in notification and queue frontends
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [7a23261]
|
|
60
|
+
- @checkstack/frontend-api@0.2.0
|
|
61
|
+
- @checkstack/common@0.3.0
|
|
62
|
+
- @checkstack/auth-frontend@0.3.0
|
|
63
|
+
- @checkstack/theme-common@0.1.0
|
|
64
|
+
- @checkstack/ui@0.2.1
|
|
65
|
+
|
|
3
66
|
## 0.0.6
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
|
-
import { useApi,
|
|
2
|
+
import { useApi, usePluginClient } from "@checkstack/frontend-api";
|
|
3
3
|
import { authApiRef } from "@checkstack/auth-frontend/api";
|
|
4
4
|
import { useTheme } from "@checkstack/ui";
|
|
5
5
|
import { ThemeApi } from "@checkstack/theme-common";
|
|
@@ -17,14 +17,22 @@ import { ThemeApi } from "@checkstack/theme-common";
|
|
|
17
17
|
export const ThemeSynchronizer = () => {
|
|
18
18
|
const { setTheme } = useTheme();
|
|
19
19
|
const authApi = useApi(authApiRef);
|
|
20
|
-
const
|
|
21
|
-
const themeClient = rpcApi.forPlugin(ThemeApi);
|
|
20
|
+
const themeClient = usePluginClient(ThemeApi);
|
|
22
21
|
const { data: session, isPending } = authApi.useSession();
|
|
23
22
|
|
|
24
23
|
// Track if we've already synced for this session to avoid repeated API calls
|
|
25
24
|
const hasSyncedRef = useRef(false);
|
|
26
25
|
const lastUserIdRef = useRef<string | undefined>(undefined);
|
|
27
26
|
|
|
27
|
+
// Fetch theme from backend - only enabled when user is logged in
|
|
28
|
+
const { data: themeData, isSuccess } = themeClient.getTheme.useQuery(
|
|
29
|
+
undefined,
|
|
30
|
+
{
|
|
31
|
+
enabled: !!session?.user && !isPending && !hasSyncedRef.current,
|
|
32
|
+
staleTime: Infinity, // Don't refetch automatically
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
28
36
|
useEffect(() => {
|
|
29
37
|
// Wait for session to load
|
|
30
38
|
if (isPending) {
|
|
@@ -44,24 +52,16 @@ export const ThemeSynchronizer = () => {
|
|
|
44
52
|
return;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
// For logged-in users,
|
|
48
|
-
if (session?.user) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
setTheme(theme);
|
|
53
|
-
hasSyncedRef.current = true;
|
|
54
|
-
})
|
|
55
|
-
.catch((error) => {
|
|
56
|
-
console.error("Failed to sync theme from backend:", error);
|
|
57
|
-
hasSyncedRef.current = true; // Still mark as synced to prevent retry loops
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
55
|
+
// For logged-in users, apply theme from backend when query succeeds
|
|
56
|
+
if (session?.user && isSuccess && themeData) {
|
|
57
|
+
setTheme(themeData.theme);
|
|
58
|
+
hasSyncedRef.current = true;
|
|
59
|
+
} else if (!session?.user) {
|
|
60
60
|
// For non-logged-in users, local storage theme is already applied
|
|
61
61
|
// by ThemeProvider, so nothing to do
|
|
62
62
|
hasSyncedRef.current = true;
|
|
63
63
|
}
|
|
64
|
-
}, [session, isPending, setTheme,
|
|
64
|
+
}, [session, isPending, setTheme, themeData, isSuccess]);
|
|
65
65
|
|
|
66
66
|
// Headless component - renders nothing
|
|
67
67
|
return <></>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { Moon, Sun } from "lucide-react";
|
|
3
3
|
import { Toggle, useTheme, useToast } from "@checkstack/ui";
|
|
4
|
-
import {
|
|
4
|
+
import { usePluginClient } from "@checkstack/frontend-api";
|
|
5
5
|
import { ThemeApi } from "@checkstack/theme-common";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -14,10 +14,9 @@ import { ThemeApi } from "@checkstack/theme-common";
|
|
|
14
14
|
*/
|
|
15
15
|
export const ThemeToggleMenuItem = () => {
|
|
16
16
|
const { theme, setTheme } = useTheme();
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const themeClient = usePluginClient(ThemeApi);
|
|
18
|
+
const setThemeMutation = themeClient.setTheme.useMutation();
|
|
19
19
|
|
|
20
|
-
const [saving, setSaving] = useState(false);
|
|
21
20
|
const [isDark, setIsDark] = useState(theme === "dark");
|
|
22
21
|
const toast = useToast();
|
|
23
22
|
|
|
@@ -34,9 +33,8 @@ export const ThemeToggleMenuItem = () => {
|
|
|
34
33
|
setTheme(newTheme); // Also updates local storage via ThemeProvider
|
|
35
34
|
|
|
36
35
|
// Save to backend
|
|
37
|
-
setSaving(true);
|
|
38
36
|
try {
|
|
39
|
-
await
|
|
37
|
+
await setThemeMutation.mutateAsync({ theme: newTheme });
|
|
40
38
|
} catch (error) {
|
|
41
39
|
const message =
|
|
42
40
|
error instanceof Error
|
|
@@ -47,8 +45,6 @@ export const ThemeToggleMenuItem = () => {
|
|
|
47
45
|
// Revert on error
|
|
48
46
|
setIsDark(!checked);
|
|
49
47
|
setTheme(checked ? "light" : "dark");
|
|
50
|
-
} finally {
|
|
51
|
-
setSaving(false);
|
|
52
48
|
}
|
|
53
49
|
};
|
|
54
50
|
|
|
@@ -61,7 +57,7 @@ export const ThemeToggleMenuItem = () => {
|
|
|
61
57
|
<Toggle
|
|
62
58
|
checked={isDark}
|
|
63
59
|
onCheckedChange={handleToggle}
|
|
64
|
-
disabled={
|
|
60
|
+
disabled={setThemeMutation.isPending}
|
|
65
61
|
aria-label="Toggle dark mode"
|
|
66
62
|
/>
|
|
67
63
|
</div>
|