The is a free template for anyone who wants to make a nostr app in react using a dashboard (admin) - style UI. It relies on the open source nostr-hooks by osty, as well as ndk and nostr-tools.
This repo was created using the following steps:
- Fork of CoreUI Free React.js Admin Template
- Navigation reformatted, extraneous pages removed, to create this template
- Nostr functionality added, as described below
npm install @nostr-dev-kit/ndk
npm install @nostr-dev-kit/ndk-cache-dexie
npm install @noble/hashes
npm install nostr-tools
npm install nostr-hooks@2.8.4
- added
src/helpers/nip19.js - added
src/helpers/relays.js - added
src/helpers/ndk.jswith the functionasyncFetchProfile(see below) - enabled nostr login
- added
src/constfolder - Persistence of login: currently using either
useAutoLoginor(reL)(l)oginFromLocalStorageinApp.js, without whichactiveUseris null - profile page will download user information when ?npub or ?pubkey is included in the url
- "Hello World" pages to demonstrate usage of:
- useSubscribe
- useActiveUser
- useProfile
- useNdk
- useNewEvent, useSigner
Data persistence: So far, I am not making use of ndk's caching adapters (ndk-cache-redis or ndk-cache-dexie) and have not used redux, although it should be noted that redux is utilized by the underyling CoreUI template. I'm probably going to avoid any specialized caching for the sake of the NRD template.
Hello World test page 1 illustrates one of the pitfalls of using react and nostr at the same time: rerenders. See comments in the relevant script.
-
nostr-hooks v2.9.11 has problems with persistence of login using secret keys. It seems to forget it was logged in when refreshing the page. Maybe I need to switch back from
useAutoLoginback to(reL)(l)oginFromLocalStorage? nostr-hooks v2.8.4 does not have this persistence of data problem, but does not have useProfile which is in v2.9.11 -
Remote signer login has not yet been tested.
-
Secret Key login gives incorrect error messages and currently only supports nsec. Plan to support hex.
-
useProfile (Hello World page 3) seems to create persistent rerenders and I don't know why. For now, my customized
asyncFetchProfilewhich uses ndk (Hello World page 4) seems to work better. -
still not decided whether to use
useAutoLoginor(reL)(l)oginFromLocalStorageor what the difference is -
Have not decided whether to store logged-in user data at the point of login for a better UX, i.e. to prevent avatar image from flickering whenever you change pages.
-
read / write from individual relays
- Clone the repo:
git clone https://github.com/PrettyGoodFreedomTech/grapevine-brainstorm.git - cd into the folder you just created
$ npm install
or
$ yarn install
# dev server with hot reload at http://localhost:3000
$ npm start
or
# dev server with hot reload at http://localhost:3000
$ yarn start
Navigate to http://localhost:3000. The app will automatically reload if you change any of the source files.
Run build to build the project. The build artifacts will be stored in the build/ directory.
# build for production with minification
$ npm run build
or
# build for production with minification
$ yarn build