power-compass 0.0.1-alpha.1 → 0.0.1-alpha.2

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.
@@ -1,7 +0,0 @@
1
- export type Notification = {
2
- id: string
3
- createdAt: string
4
- title: string
5
- body: string
6
- url?: string
7
- }
@@ -1,31 +0,0 @@
1
- import { useState } from "react"
2
-
3
- const loadFromStorage = <T>(key: string, initialValue: T) => {
4
- try {
5
- const item = window.localStorage.getItem(key)
6
- return item ? JSON.parse(item) : initialValue
7
- } catch (error) {
8
- return initialValue
9
- }
10
- }
11
-
12
- const updateStorage = <T>(key: string, value: T) => {
13
- try {
14
- window.localStorage.setItem(key, JSON.stringify(value))
15
- } catch (error) {
16
- console.debug(error) // eslint-disable-line no-console
17
- }
18
- }
19
-
20
- export const useLocalStorage = <T>(key: string, initialValue: T) => {
21
- const [stateValue, updateStateValue] = useState(() =>
22
- loadFromStorage(key, initialValue),
23
- )
24
- const setValue = (value: T) => {
25
- updateStateValue(value)
26
- updateStorage(key, value)
27
- }
28
- const reset = () => setValue(initialValue)
29
-
30
- return [stateValue, setValue, reset]
31
- }
@@ -1,69 +0,0 @@
1
- import { useEffect, useState } from "react"
2
-
3
- import { fetchBackend } from "../http/fetch"
4
-
5
- import { type Notification } from "./types"
6
- import { useLocalStorage } from "./useLocalStorage"
7
-
8
- interface Props {
9
- contextId?: string | number
10
- }
11
-
12
- interface NotificationProvider {
13
- label: string
14
- notifications: Notification[]
15
- }
16
-
17
- interface UseNotificationCenterReturn {
18
- notifications: Notification[]
19
- loading: boolean
20
- error: Error | null
21
- }
22
-
23
- export function useNotificationCenter({
24
- contextId,
25
- }: Props): UseNotificationCenterReturn {
26
- const [notifications, updateNotifications] = useLocalStorage(
27
- "notification_center.notifications",
28
- [],
29
- )
30
- const [loading, setLoading] = useState(true)
31
- const [error, setError] = useState<Error | null>(null)
32
-
33
- useEffect(() => {
34
- if (!contextId) {
35
- setLoading(false)
36
- return
37
- }
38
-
39
- const fetchNotifications = async (): Promise<void> => {
40
- try {
41
- setLoading(true)
42
- setError(null)
43
-
44
- const data = await fetchBackend<NotificationProvider[]>(
45
- "compass",
46
- String(contextId),
47
- "notifications",
48
- {},
49
- )
50
- const fetchedNotifications: Notification[] = data
51
- .map((provider: NotificationProvider) => provider.notifications)
52
- .flat()
53
- .map((notification: any) => ({
54
- ...notification,
55
- createdAt: notification.date || notification.createdAt,
56
- }))
57
- updateNotifications(fetchedNotifications)
58
- } catch (err) {
59
- setError(err instanceof Error ? err : new Error("Unknown error"))
60
- } finally {
61
- setLoading(false)
62
- }
63
- }
64
-
65
- fetchNotifications()
66
- }, [contextId, updateNotifications])
67
-
68
- return { notifications, loading, error }
69
- }
package/tsconfig.app.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
- "target": "ES2022",
5
- "useDefineForClassFields": true,
6
- "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
- "module": "ESNext",
8
- "types": ["vite/client"],
9
- "skipLibCheck": true,
10
-
11
- /* Bundler mode */
12
- "moduleResolution": "bundler",
13
- "allowImportingTsExtensions": true,
14
- "verbatimModuleSyntax": true,
15
- "moduleDetection": "force",
16
- "noEmit": true,
17
- "jsx": "react-jsx",
18
-
19
- /* Linting */
20
- "strict": true,
21
- "noUnusedLocals": true,
22
- "noUnusedParameters": true,
23
- "erasableSyntaxOnly": true,
24
- "noFallthroughCasesInSwitch": true,
25
- "noUncheckedSideEffectImports": true
26
- },
27
- "include": ["src"]
28
- }
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "files": [],
3
- "references": [
4
- { "path": "./tsconfig.app.json" },
5
- { "path": "./tsconfig.node.json" }
6
- ]
7
- }
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
- "target": "ES2023",
5
- "lib": ["ES2023"],
6
- "module": "ESNext",
7
- "types": ["node"],
8
- "skipLibCheck": true,
9
-
10
- /* Bundler mode */
11
- "moduleResolution": "bundler",
12
- "allowImportingTsExtensions": true,
13
- "verbatimModuleSyntax": true,
14
- "moduleDetection": "force",
15
- "noEmit": true,
16
-
17
- /* Linting */
18
- "strict": true,
19
- "noUnusedLocals": true,
20
- "noUnusedParameters": true,
21
- "erasableSyntaxOnly": true,
22
- "noFallthroughCasesInSwitch": true,
23
- "noUncheckedSideEffectImports": true
24
- },
25
- "include": ["vite.config.ts"]
26
- }
package/vite.config.ts DELETED
@@ -1,34 +0,0 @@
1
- import path from "path"
2
- import { defineConfig } from "vite"
3
- import react from "@vitejs/plugin-react"
4
- import dts from "vite-plugin-dts"
5
-
6
- export default defineConfig({
7
- plugins: [react(), dts({ insertTypesEntry: true })],
8
- resolve: {
9
- dedupe: ["trix", "trix-toolbar"],
10
- },
11
- build: {
12
- target: ["es2018"],
13
- lib: {
14
- entry: path.resolve(__dirname, "src/index.ts"),
15
- name: "compass",
16
- formats: ["es", "cjs"],
17
- fileName: (format) => `compass.${format}.js`,
18
- },
19
- outDir: path.resolve(__dirname, "dist"),
20
- emptyOutDir: true,
21
- rollupOptions: {
22
- external: [
23
- "react",
24
- "react-dom",
25
- "playbook-ui",
26
- "react-trix",
27
- "react/jsx-runtime",
28
- ],
29
- },
30
- },
31
- define: {
32
- "process.env.NODE_ENV": JSON.stringify("production"),
33
- },
34
- })
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from "vitest/config"
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: "jsdom",
6
- setupFiles: ["./vitest.fetch-mock.ts"],
7
- },
8
- })
@@ -1,7 +0,0 @@
1
- import createFetchMock from "vitest-fetch-mock"
2
- import { vi } from "vitest"
3
-
4
- const fetchMocker = createFetchMock(vi)
5
-
6
- // sets globalThis.fetch and globalThis.fetchMock to our mocked version
7
- fetchMocker.enableMocks()