Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ jobs:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- uses: actions/setup-node@v4
with:
node-version: '22.14.0'
registry-url: 'https://registry.npmjs.org'
- name: Download dist artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -152,8 +157,31 @@ jobs:
- run: git add dist badges/coverage.json --force
- run: git status
- uses: stefanzweifel/git-auto-commit-action@v4
id: dist_commit
with:
commit_message: 'chore(ci): update dist and coverage badge'
file_pattern: 'dist badges/coverage.json'
add_options: '--force'
branch: ${{ github.ref_name }}
- name: Upgrade npm for trusted publishing
if: steps.dist_commit.outputs.changes_detected == 'true'
run: npm install -g npm@11
- name: Check if package version already exists
if: steps.dist_commit.outputs.changes_detected == 'true'
id: check_npm_version
env:
NODE_AUTH_TOKEN: ''
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if npm view @bitsocial/bitsocial-react-hooks@$PACKAGE_VERSION version 2>/dev/null; then
echo "Version $PACKAGE_VERSION already exists on npm, skipping publish"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "Version $PACKAGE_VERSION not found on npm, will publish"
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: steps.dist_commit.outputs.changes_detected == 'true' && steps.check_npm_version.outputs.exists == 'false'
env:
NODE_AUTH_TOKEN: ''
run: npm publish --access public --provenance
Comment thread
cursor[bot] marked this conversation as resolved.
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Only record items that are repo-specific, likely to recur, and have a concrete m

## Project Overview

bitsocial-react-hooks (`@bitsocialnet/bitsocial-react-hooks`) is a React hooks library for the Bitsocial protocol. It provides React hooks and Zustand stores for interacting with decentralized communities — fetching comments, feeds, author data, publishing, account management, and more.
bitsocial-react-hooks (`@bitsocial/bitsocial-react-hooks`) is a React hooks library for the Bitsocial protocol. It provides React hooks and Zustand stores for interacting with decentralized communities — fetching comments, feeds, author data, publishing, account management, and more.

This repository is its own project under the bitsocialnet org. Use `pkc`, `community`, and `pkc-js` naming consistently in code, tests, docs, and file names.

Expand Down Expand Up @@ -95,6 +95,7 @@ src/
- If the user asks for a reviewable feature/fix/docs/chore and the current branch is `master`, create a short-lived task branch before making code changes unless the user explicitly asks to work directly on `master`.
- Name short-lived branches by intent: `feature/*`, `fix/*`, `docs/*`, `chore/*`.
- Open PRs from task branches into `master` so review bots and humans can inspect the actual change before merge.
- Never open draft PRs. PRs created by agents must be ready for review unless the user explicitly asks not to open a PR yet.
- Prefer short-lived task branches over a long-lived `develop` branch unless the user explicitly asks for a staging-branch workflow.
- Use worktrees only when parallel tasks need isolated checkouts. One active task branch per worktree.
- If a new task is unrelated to the currently checked out branch, do not stack it on that branch. Create a new worktree from `master` and create a separate short-lived task branch there.
Expand All @@ -111,7 +112,7 @@ src/

- Prefer `pkc`, `community`, and `pkc-js` naming in new or renamed code.
- Do not introduce or preserve older protocol naming in code, tests, docs, or migrations unless the user explicitly asks for a compatibility bridge.
- Package name and import path is `@bitsocialnet/bitsocial-react-hooks`. Use this in README examples and docs.
- Package name and import path is `@bitsocial/bitsocial-react-hooks`. Use this in README examples and docs.

### Bug Investigation Rules

Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

React hooks for the Bitsocial protocol. Build decentralized, serverless social apps with React using a familiar hooks API — fetch feeds, comments, author profiles, manage accounts, publish content, and more, all without a central server.

This package is currently consumed directly from [`bitsocialnet/bitsocial-react-hooks`](https://github.com/bitsocialnet/bitsocial-react-hooks) and is used by [5chan](https://github.com/bitsocialnet/5chan) and other Bitsocial clients.
This package is published as [`@bitsocial/bitsocial-react-hooks`](https://www.npmjs.com/package/@bitsocial/bitsocial-react-hooks) and is used by [5chan](https://github.com/bitsocialnet/5chan) and other Bitsocial clients.

## Installation

```bash
yarn add https://github.com/bitsocialnet/bitsocial-react-hooks.git#<commit-hash>
yarn add @bitsocial/bitsocial-react-hooks
```

Use a pinned commit hash (or tag) so installs are reproducible.
The published build is self-contained ESM, so consumers should not need postinstall import-rewrite patches.

## Development Setup
Expand Down Expand Up @@ -212,7 +211,7 @@ deleteCaches() // delete the cached comments, cached communities and cached page
#### Getting started

```jsx
import { useComment, useAccount } from "@bitsocialnet/bitsocial-react-hooks";
import { useComment, useAccount } from "@bitsocial/bitsocial-react-hooks";

const account = useAccount();
const comment = useComment({ commentCid });
Expand All @@ -232,7 +231,7 @@ import {
useAccounts,
createAccount,
setActiveAccount,
} from "@bitsocialnet/bitsocial-react-hooks";
} from "@bitsocial/bitsocial-react-hooks";

const account = useAccount();
const { accounts } = useAccounts();
Expand Down Expand Up @@ -718,7 +717,7 @@ await abandonPublish();
**2. Delete by index or CID** — remove any of your comments (pending or published):

```jsx
import { deleteComment, useAccountComments } from "@bitsocialnet/bitsocial-react-hooks";
import { deleteComment, useAccountComments } from "@bitsocial/bitsocial-react-hooks";

// By account comment index (from usePublishComment or useAccountComment)
const { index, publishComment } = usePublishComment(publishCommentOptions);
Expand All @@ -736,7 +735,7 @@ await deleteComment(accountComment.cid);
**Common cleanup pattern (remove failed UI clutter):**

```jsx
import { deleteComment, useAccountComments } from "@bitsocialnet/bitsocial-react-hooks";
import { deleteComment, useAccountComments } from "@bitsocial/bitsocial-react-hooks";

const { accountComments } = useAccountComments();
const failedComments = accountComments.filter((comment) => comment.state === "failed");
Expand Down Expand Up @@ -876,7 +875,7 @@ console.log(error);
#### Edit an account

```jsx
import {useAccount, setAccount, useResolvedAuthorAddress} from '@bitsocialnet/bitsocial-react-hooks'
import {useAccount, setAccount, useResolvedAuthorAddress} from '@bitsocial/bitsocial-react-hooks'
const account = useAccount() // or useAccount('Account 2') to use an account other than the active one

// `account.author.wallets` only auto-generates an `eth` wallet by default.
Expand Down Expand Up @@ -924,7 +923,7 @@ if (state === 'resolving' && nameResolver) {
> Note: deleting account is unrecoverable, warn the user to export/backup his account before deleting

```jsx
import { deleteAccount } from "@bitsocialnet/bitsocial-react-hooks";
import { deleteAccount } from "@bitsocial/bitsocial-react-hooks";

// delete active account
await deleteAccount();
Expand Down Expand Up @@ -1181,7 +1180,7 @@ import {
importAccount,
setActiveAccount,
setAccountsOrder,
} from "@bitsocialnet/bitsocial-react-hooks";
} from "@bitsocial/bitsocial-react-hooks";

// get active account 'Account 1'
const activeAccount = useAccount();
Expand Down Expand Up @@ -1276,7 +1275,7 @@ const { accountEdits } = useAccountEdits({ filter });
#### Get replies to a post (nested or flat)

```jsx
import { useReplies, useComment, useAccountComment } from "@bitsocialnet/bitsocial-react-hooks";
import { useReplies, useComment, useAccountComment } from "@bitsocial/bitsocial-react-hooks";

// NOTE: recommended to use the same replies options for all depths, or will load slower
const useRepliesOptions = {
Expand Down Expand Up @@ -1339,7 +1338,7 @@ const repliesComponents = replies.map((reply, index) => (
#### Format short CIDs and addresses

```jsx
import { useShortAddress, useShortCid } from "@bitsocialnet/bitsocial-react-hooks";
import { useShortAddress, useShortCid } from "@bitsocial/bitsocial-react-hooks";

const shortParentCid = useShortCid(comment.parentCid);
const shortAddress = useShortAddress(address);
Expand Down
4 changes: 2 additions & 2 deletions docs/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

```js
import { useMemo } from "react";
import { useClientsStates } from "@bitsocialnet/bitsocial-react-hooks";
import { useClientsStates } from "@bitsocial/bitsocial-react-hooks";

const clientHosts = {};
const getClientHost = (clientUrl) => {
Expand Down Expand Up @@ -129,7 +129,7 @@ if (errorString) {

```js
import { useMemo } from "react";
import { useCommunity, useCommunitiesStates } from "@bitsocialnet/bitsocial-react-hooks";
import { useCommunity, useCommunitiesStates } from "@bitsocial/bitsocial-react-hooks";

const clientHosts = {};
const getClientHost = (clientUrl) => {
Expand Down
4 changes: 2 additions & 2 deletions docs/mock-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT_LOADING_TIME=1000
#### Get a mock feed

```js
import { useFeed } from "@bitsocialnet/bitsocial-react-hooks";
import { useFeed } from "@bitsocial/bitsocial-react-hooks";

function App() {
const { feed, hasMore, loadMore } = useFeed({
Expand All @@ -41,7 +41,7 @@ REACT_APP_BITSOCIAL_REACT_HOOKS_NO_CACHE=1
#### Delete databases and caches

```js
import { deleteCaches, deleteDatabases } from "@bitsocialnet/bitsocial-react-hooks";
import { deleteCaches, deleteDatabases } from "@bitsocial/bitsocial-react-hooks";

// delete all databases, including all caches and accounts data
await deleteDatabases();
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "@bitsocialnet/bitsocial-react-hooks",
"name": "@bitsocial/bitsocial-react-hooks",
"type": "module",
"author": "Bitsocial Forge",
"keywords": [
"bitsocial"
],
"repository": "github:bitsocialnet/bitsocial-react-hooks",
"repository": {
"type": "git",
"url": "git+https://github.com/bitsocialnet/bitsocial-react-hooks.git"
},
"license": "GPL-3.0-or-later",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -42,8 +45,8 @@
},
"dependencies": {
"@bitsocial/bso-resolver": "0.0.6",
"@pkc/pkc-logger": "https://github.com/pkcprotocol/pkc-logger.git",
"@pkcprotocol/pkc-js": "0.0.18",
"@pkcprotocol/pkc-logger": "0.1.0",
"assert": "2.0.0",
"ethers": "5.8.0",
"localforage": "1.10.0",
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/accounts/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo, useState, useEffect } from "react";
import isEqual from "lodash.isequal";
import useAccountsStore from "../../stores/accounts";
import useCommunitiesStore from "../../stores/communities";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:accounts:hooks");
import assert from "assert";
import { useListCommunities, useCommunities } from "../communities";
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/accounts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useMemo, useState, useEffect } from "react";
import memoize from "memoizee";
import utils from "../../lib/utils";
import PkcJs from "../../lib/pkc-js";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:accounts:hooks");

export const useCalculatedNotifications = (
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/actions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo, useRef, useState } from "react";
import type { Dispatch, SetStateAction } from "react";
import useAccountsStore from "../../stores/accounts";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:actions:hooks");
import assert from "assert";
import { useAccount, useAccountId } from "../accounts";
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/authors/author-avatars.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState, useMemo } from "react";
import { useAccount } from "../accounts";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:authors:hooks");
import assert from "assert";
import { Nft, ChainProviders, Author } from "../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/authors/authors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState, useMemo } from "react";
import useInterval from "../utils/use-interval";
import { useAccount } from "../accounts";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:authors:hooks");
import assert from "assert";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/comments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useAccount } from "./accounts";
import validator from "../lib/validator";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:comments:hooks");
import assert from "assert";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/communities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState, useMemo } from "react";
import { useAccount } from "./accounts";
import validator from "../lib/validator";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:communities:hooks");
import assert from "assert";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/feeds/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useState } from "react";
import { useAccount } from "../accounts";
import validator from "../../lib/validator";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:feeds:hooks");
import assert from "assert";
import { deriveFeedSortType } from "../../lib/feed-sort-type";
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/replies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState, useMemo } from "react";
import { useAccount } from "./accounts";
import validator from "../lib/validator";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:replies:hooks");
import assert from "assert";
import { UseRepliesOptions, UseRepliesResult } from "../types";
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/states.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from "react";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:states:hooks");
import assert from "assert";
import validator from "../lib/validator";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/localforage-lru/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ try {
if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_NO_CACHE) {
// @ts-ignore
localForageLru.createInstance = () => {
console.warn("@bitsocialnet/bitsocial-react-hooks cache is disabled for testing");
console.warn("@bitsocial/bitsocial-react-hooks cache is disabled for testing");
return {
getItem: async function (key: string) {},
setItem: async function (key: string, value: any) {},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pkc-js/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NOTE: don't import pkc-js directly to be able to replace the implementation

import PkcJsMockContent from "./pkc-js-mock-content";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
import assert from "assert";
const log = Logger("bitsocial-react-hooks:pkc-js");

Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from "assert";
import QuickLru from "quick-lru";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
import PkcJs from "../pkc-js";
import { Comment } from "../../types";
import { areEquivalentCommunityAddresses } from "../community-address";
Expand Down
2 changes: 1 addition & 1 deletion src/stores/accounts/account-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
normalizeAccountProtocolConfig,
withProtocolAliases,
} from "../../lib/pkc-compat";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:accounts:stores");

export const DEFAULT_ETH_RPC_URL = "https://ethereum-rpc.publicnode.com";
Expand Down
2 changes: 1 addition & 1 deletion src/stores/accounts/accounts-actions-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import accountsStore, { listeners } from "./accounts-store";
import accountsDatabase from "./accounts-database";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
import assert from "assert";
import isEqual from "lodash.isequal";
const log = Logger("bitsocial-react-hooks:accounts:stores");
Expand Down
2 changes: 1 addition & 1 deletion src/stores/accounts/accounts-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import accountsStore, { listeners } from "./accounts-store";
import communitiesStore from "../communities";
import accountsDatabase from "./accounts-database";
import accountGenerator from "./account-generator";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
import validator from "../../lib/validator";
import chain from "../../lib/chain";
import assert from "assert";
Expand Down
2 changes: 1 addition & 1 deletion src/stores/accounts/accounts-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
normalizeAccountProtocolConfig,
withProtocolAliases,
} from "../../lib/pkc-compat";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:accounts:stores");
// Storage keeps the existing namespace so current installs reuse the same IndexedDB data.
const accountsDatabaseNamespace = "bitsocialReactHooks";
Expand Down
2 changes: 1 addition & 1 deletion src/stores/accounts/accounts-store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import Logger from "@pkc/pkc-logger";
import Logger from "@pkcprotocol/pkc-logger";
const log = Logger("bitsocial-react-hooks:accounts:stores");
import accountsDatabase from "./accounts-database";
import accountGenerator from "./account-generator";
Expand Down
Loading
Loading