@quoll/client-lib
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -6,2 +6,6 @@ # Change Log | ||
## [0.8.2](https://github.com/mzogheib/quoll/compare/@quoll/client-lib@0.8.1...@quoll/client-lib@0.8.2) (2024-08-16) | ||
**Note:** Version bump only for package @quoll/client-lib | ||
## [0.8.1](https://github.com/mzogheib/quoll/compare/@quoll/client-lib@0.8.0...@quoll/client-lib@0.8.1) (2024-08-12) | ||
@@ -8,0 +12,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useFeedsModel = void 0; | ||
const react_1 = require("react"); | ||
const useFeedsModel = (useStore, feedsService) => { | ||
const { setProperty, state: feeds, reset } = useStore(); | ||
const isOneConnected = (0, react_1.useMemo)(() => Object.values(feeds).some((feed) => feed.isConnected), [feeds]); | ||
const updateFeed = (0, react_1.useCallback)((feedName, newValue) => { | ||
console.log({ feeds }); | ||
const isOneConnected = Object.values(feeds).some((feed) => feed.isConnected); | ||
const updateFeed = (feedName, newValue) => { | ||
const newFeed = { | ||
@@ -14,7 +14,7 @@ ...feeds[feedName], | ||
setProperty(feedName, newFeed); | ||
}, [feeds, setProperty]); | ||
const setConnected = (0, react_1.useCallback)((name, value) => { | ||
}; | ||
const setConnected = (name, value) => { | ||
updateFeed(name, { isConnected: value }); | ||
}, [updateFeed]); | ||
const connect = (0, react_1.useCallback)(async (name) => { | ||
}; | ||
const connect = async (name) => { | ||
try { | ||
@@ -31,4 +31,4 @@ updateFeed(name, { isAuthenticating: true }); | ||
} | ||
}, [updateFeed]); | ||
const disconnect = (0, react_1.useCallback)(async (name) => { | ||
}; | ||
const disconnect = async (name) => { | ||
try { | ||
@@ -43,8 +43,8 @@ updateFeed(name, { isAuthenticating: true }); | ||
} | ||
}, [updateFeed]); | ||
const authenticate = (0, react_1.useCallback)(async (name, code) => { | ||
}; | ||
const authenticate = async (name, code) => { | ||
updateFeed(name, { isAuthenticating: true }); | ||
await feedsService.authenticate(name, { code }); | ||
updateFeed(name, { isConnected: true, isAuthenticating: false }); | ||
}, [updateFeed]); | ||
}; | ||
return { | ||
@@ -51,0 +51,0 @@ feeds: Object.values(feeds), |
{ | ||
"name": "@quoll/client-lib", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Shared code for client side packages", | ||
@@ -15,7 +15,6 @@ "repository": "https://github.com/mzogheib/quoll", | ||
"type-check": "tsc --noEmit", | ||
"prepare": "yarn build", | ||
"postinstall": "yarn build" | ||
"prepare": "yarn build" | ||
}, | ||
"dependencies": { | ||
"@quoll/lib": "^0.5.5", | ||
"@quoll/lib": "^0.5.6", | ||
"react-redux": "^7.2.1", | ||
@@ -33,3 +32,3 @@ "redux": "^4.0.5" | ||
}, | ||
"gitHead": "798c2155705346b1766f67a1f52b21e196c20a7f" | ||
"gitHead": "a8cb58a51772cd4c388f1eb3ad2645770ecc8de0" | ||
} |
@@ -1,2 +0,1 @@ | ||
import { useMemo, useCallback } from "react"; | ||
import { FeedConnectionConfig, FeedName } from "@quoll/lib"; | ||
@@ -31,65 +30,49 @@ | ||
const isOneConnected = useMemo( | ||
() => Object.values(feeds).some((feed) => feed.isConnected), | ||
[feeds], | ||
); | ||
console.log({ feeds }); | ||
const updateFeed = useCallback( | ||
(feedName: FeedName, newValue: Partial<FeedState>) => { | ||
const newFeed = { | ||
...feeds[feedName], | ||
...newValue, | ||
}; | ||
const isOneConnected = Object.values(feeds).some((feed) => feed.isConnected); | ||
setProperty(feedName, newFeed); | ||
}, | ||
[feeds, setProperty], | ||
); | ||
const updateFeed = (feedName: FeedName, newValue: Partial<FeedState>) => { | ||
const newFeed = { | ||
...feeds[feedName], | ||
...newValue, | ||
}; | ||
const setConnected = useCallback( | ||
(name: FeedName, value: boolean) => { | ||
updateFeed(name, { isConnected: value }); | ||
}, | ||
[updateFeed], | ||
); | ||
setProperty(feedName, newFeed); | ||
}; | ||
const connect = useCallback( | ||
async (name: FeedName) => { | ||
try { | ||
updateFeed(name, { isAuthenticating: true }); | ||
const config = await feedsService.connect(name); | ||
const setConnected = (name: FeedName, value: boolean) => { | ||
updateFeed(name, { isConnected: value }); | ||
}; | ||
return config; | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
updateFeed(name, { isAuthenticating: false }); | ||
} | ||
}, | ||
[updateFeed], | ||
); | ||
const connect = async (name: FeedName) => { | ||
try { | ||
updateFeed(name, { isAuthenticating: true }); | ||
const config = await feedsService.connect(name); | ||
const disconnect = useCallback( | ||
async (name: FeedName) => { | ||
try { | ||
updateFeed(name, { isAuthenticating: true }); | ||
await feedsService.deauthorize(name); | ||
updateFeed(name, { isConnected: false, isAuthenticating: false }); | ||
} catch (error) { | ||
updateFeed(name, { isConnected: true, isAuthenticating: false }); | ||
throw error; | ||
} | ||
}, | ||
[updateFeed], | ||
); | ||
return config; | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
updateFeed(name, { isAuthenticating: false }); | ||
} | ||
}; | ||
const authenticate = useCallback( | ||
async (name: FeedName, code: string) => { | ||
const disconnect = async (name: FeedName) => { | ||
try { | ||
updateFeed(name, { isAuthenticating: true }); | ||
await feedsService.authenticate(name, { code }); | ||
await feedsService.deauthorize(name); | ||
updateFeed(name, { isConnected: false, isAuthenticating: false }); | ||
} catch (error) { | ||
updateFeed(name, { isConnected: true, isAuthenticating: false }); | ||
}, | ||
[updateFeed], | ||
); | ||
throw error; | ||
} | ||
}; | ||
const authenticate = async (name: FeedName, code: string) => { | ||
updateFeed(name, { isAuthenticating: true }); | ||
await feedsService.authenticate(name, { code }); | ||
updateFeed(name, { isConnected: true, isAuthenticating: false }); | ||
}; | ||
return { | ||
@@ -96,0 +79,0 @@ feeds: Object.values(feeds), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
0
111247
1389
Updated@quoll/lib@^0.5.6