@bitsocial/bitsocial-react-hooks 0.1.41 → 0.1.42
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 +9 -0
- package/README.md +15 -0
- package/dist/hooks/actions/actions.d.ts +2 -1
- package/dist/hooks/actions/actions.d.ts.map +1 -1
- package/dist/hooks/actions/actions.js +39 -0
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/stores/accounts/account-generator.d.ts +3 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -1
- package/dist/stores/accounts/account-generator.js +1 -0
- package/dist/stores/accounts/account-generator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts +2 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +56 -0
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-database.js +13 -2
- package/dist/stores/accounts/accounts-database.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -36,6 +36,8 @@ export declare const blockAddress: (address: string, accountName?: string) => Pr
|
|
|
36
36
|
export declare const unblockAddress: (address: string, accountName?: string) => Promise<void>;
|
|
37
37
|
export declare const blockCid: (cid: string, accountName?: string) => Promise<void>;
|
|
38
38
|
export declare const unblockCid: (cid: string, accountName?: string) => Promise<void>;
|
|
39
|
+
export declare const saveComment: (commentCid: string, accountName?: string) => Promise<void>;
|
|
40
|
+
export declare const unsaveComment: (commentCid: string, accountName?: string) => Promise<void>;
|
|
39
41
|
export declare const publishComment: (publishCommentOptions: PublishCommentOptions, accountName?: string) => Promise<any>;
|
|
40
42
|
export declare const deleteComment: (commentCidOrAccountCommentIndex: string | number, accountName?: string) => Promise<void>;
|
|
41
43
|
export declare const publishVote: (publishVoteOptions: PublishVoteOptions, accountName?: string) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts-actions.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-actions.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,OAAO,EAEP,qBAAqB,EAGrB,kBAAkB,EAClB,yBAAyB,EACzB,+BAA+B,EAC/B,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAGhB,MAAM,aAAa,CAAC;AAmPrB,sGAAsG;AACtG,eAAO,MAAM,yBAAyB,GACpC,kBAAkB,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EACvC,WAAW,MAAM,EACjB,OAAO,MAAM,EACb,SAAS,CAAC,eAAe,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,GAAG,KAAK,IAAI;;;;;;CAO/D,CAAC;AA2BF,eAAO,MAAM,0BAA0B,GAAI,mBAAmB,GAAG,EAAE,yBAAyB,GAAG,YAGtC,CAAC;AAE1D,eAAO,MAAM,yBAAyB,GAAI,mBAAmB,GAAG,QAK/D,CAAC;AAuCF,eAAO,MAAM,kCAAkC,GAC7C,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3D,WAAW,MAAM,EACjB,mBAAmB,GAAG;;CAsCvB,CAAC;AAEF,eAAO,MAAM,uCAAuC,GAClD,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3D,eAAe,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EACpD,WAAW,MAAM,EACjB,mBAAmB,GAAG;;CA6BvB,CAAC;AAEF,eAAO,MAAM,qCAAqC,GAAI,uBAAuB,GAAG,YAY/E,CAAC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,MAAM,kBAAkB,GAC7B,2BAA2B,yBAAyB,EACpD,cAAc,MAAM,kBA4IrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,iCAAiC,+BAA+B,EAChE,cAAc,MAAM,kBAyJrB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,kBAAkB,MAAM,EACxB,6BAA6B,2BAA2B,EACxD,cAAc,MAAM,kBAmKrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,wBAAwB,sBAAsB,EAC9C,cAAc,MAAM,iBAkBrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,kBAAkB,MAAM,EAAE,cAAc,MAAM,kBAcnF,CAAC"}
|
|
@@ -782,6 +782,62 @@ export const unblockCid = (cid, accountName) => __awaiter(void 0, void 0, void 0
|
|
|
782
782
|
log("accountsActions.unblockCid", { account: updatedAccount, accountName, cid });
|
|
783
783
|
accountsStore.setState({ accounts: updatedAccounts });
|
|
784
784
|
});
|
|
785
|
+
const savedCommentMutationQueues = new Map();
|
|
786
|
+
const updateSavedComments = (commentCid, accountName, shouldSave) => __awaiter(void 0, void 0, void 0, function* () {
|
|
787
|
+
var _a, _b;
|
|
788
|
+
const { accounts, accountNamesToAccountIds, activeAccountId } = accountsStore.getState();
|
|
789
|
+
assert(commentCid && typeof commentCid === "string", `accountsActions.${shouldSave ? "saveComment" : "unsaveComment"} invalid commentCid '${commentCid}'`);
|
|
790
|
+
assert(accounts && accountNamesToAccountIds && activeAccountId, `can't use accountsStore.accountActions before initialized`);
|
|
791
|
+
const accountId = accountName ? accountNamesToAccountIds[accountName] : activeAccountId;
|
|
792
|
+
assert((_a = accounts[accountId]) === null || _a === void 0 ? void 0 : _a.id, `accountsActions.${shouldSave ? "saveComment" : "unsaveComment"} account.id '${(_b = accounts[accountId]) === null || _b === void 0 ? void 0 : _b.id}' doesn't exist, activeAccountId '${activeAccountId}' accountName '${accountName}'`);
|
|
793
|
+
const previousMutation = savedCommentMutationQueues.get(accountId) || Promise.resolve();
|
|
794
|
+
const mutation = previousMutation
|
|
795
|
+
.catch(() => { })
|
|
796
|
+
.then(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
797
|
+
const currentAccounts = accountsStore.getState().accounts;
|
|
798
|
+
const account = currentAccounts[accountId];
|
|
799
|
+
assert(account === null || account === void 0 ? void 0 : account.id, `accountsActions.${shouldSave ? "saveComment" : "unsaveComment"} account.id '${account === null || account === void 0 ? void 0 : account.id}' doesn't exist, activeAccountId '${activeAccountId}' accountName '${accountName}'`);
|
|
800
|
+
const isSaved = account.savedComments.includes(commentCid);
|
|
801
|
+
if (shouldSave && isSaved) {
|
|
802
|
+
throw Error(`account '${account.id}' already saved comment '${commentCid}'`);
|
|
803
|
+
}
|
|
804
|
+
if (!shouldSave && !isSaved) {
|
|
805
|
+
throw Error(`account '${account.id}' already unsaved comment '${commentCid}'`);
|
|
806
|
+
}
|
|
807
|
+
const savedComments = shouldSave
|
|
808
|
+
? [commentCid, ...account.savedComments]
|
|
809
|
+
: account.savedComments.filter((savedCommentCid) => savedCommentCid !== commentCid);
|
|
810
|
+
const updatedAccount = Object.assign(Object.assign({}, account), { savedComments });
|
|
811
|
+
yield accountsDatabase.addAccount(updatedAccount);
|
|
812
|
+
const latestAccounts = accountsStore.getState().accounts;
|
|
813
|
+
const latestAccount = latestAccounts[accountId];
|
|
814
|
+
assert(latestAccount === null || latestAccount === void 0 ? void 0 : latestAccount.id, `account '${accountId}' was removed while updating saved comments`);
|
|
815
|
+
const mergedAccount = Object.assign(Object.assign({}, latestAccount), { savedComments });
|
|
816
|
+
const updatedAccounts = Object.assign(Object.assign({}, latestAccounts), { [accountId]: mergedAccount });
|
|
817
|
+
const actionName = shouldSave ? "saveComment" : "unsaveComment";
|
|
818
|
+
log(`accountsActions.${actionName}`, {
|
|
819
|
+
accountId,
|
|
820
|
+
accountName,
|
|
821
|
+
commentCid,
|
|
822
|
+
});
|
|
823
|
+
accountsStore.setState({ accounts: updatedAccounts });
|
|
824
|
+
}));
|
|
825
|
+
savedCommentMutationQueues.set(accountId, mutation);
|
|
826
|
+
try {
|
|
827
|
+
yield mutation;
|
|
828
|
+
}
|
|
829
|
+
finally {
|
|
830
|
+
if (savedCommentMutationQueues.get(accountId) === mutation) {
|
|
831
|
+
savedCommentMutationQueues.delete(accountId);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
export const saveComment = (commentCid, accountName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
836
|
+
yield updateSavedComments(commentCid, accountName, true);
|
|
837
|
+
});
|
|
838
|
+
export const unsaveComment = (commentCid, accountName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
839
|
+
yield updateSavedComments(commentCid, accountName, false);
|
|
840
|
+
});
|
|
785
841
|
export const publishComment = (publishCommentOptions, accountName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
786
842
|
var _a, _b, _c;
|
|
787
843
|
const { accounts, accountsComments, accountNamesToAccountIds, activeAccountId } = accountsStore.getState();
|