Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Aug 17, 2024
0 parents commit adef43e
Show file tree
Hide file tree
Showing 22 changed files with 2,966 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
# Upload dist repository
path: "./dist"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Jim Index

An index of [Alby Jim](https://github.com/getAlby/jim) instances that have been published on Nostr relays. Choose a Jim and get a 1-click wallet!

[Try it now](https://getAlby.gethub.io/jim-index)

## Jim Event

The Jim event, type `38177` is based on [NIP-87](https://github.com/nostr-protocol/nips/pull/1110/files)

```json
{
"kind": 38177,
"pubkey": "<user-pubkey>",
"content": "",
"tags": [["d", "https://jim.example.com"]]
}
```
28 changes: 28 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html data-theme="bumblebee" lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/jim.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Jim Index</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "jim-index",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@nostr-dev-kit/ndk": "^2.10.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zustand": "^4.5.5"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"daisyui": "^4.12.10",
"eslint": "^9.9.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"postcss": "^8.4.41",
"prettier": "^3.3.3",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
}
}
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
30 changes: 30 additions & 0 deletions public/jim.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { NDKEvent } from "@nostr-dev-kit/ndk";
import jimLogo from "./assets/jim.svg";
import { useStore } from "./store";
import { JIM_INSTANCE_KIND } from "./types";

export default function App() {
const store = useStore();

async function addJim() {
const promptResponse = prompt("Enter your Jim URL");
if (!promptResponse) {
return;
}
let jimUrl: string;
try {
const url = new URL(promptResponse);
jimUrl = url.toString();
if (jimUrl.endsWith("/")) {
jimUrl = jimUrl.substring(0, jimUrl.length - 1);
}
if (!confirm("Confirm publish new Jim: " + url)) {
return;
}
} catch (error) {
alert("Invalid URL: " + error);
return;
}
const event = new NDKEvent(store.ndk);
event.kind = JIM_INSTANCE_KIND;
event.dTag = jimUrl.toString();

try {
const publishedRelays = await event.publish(undefined, undefined, 1);

alert(
"Published to " +
Array.from(publishedRelays)
.map((relay) => relay.url)
.join(", "),
);
} catch (error) {
alert("Publish failed: " + error);
}
}

async function recommend(eventId: string) {
const event = new NDKEvent(store.ndk);
event.kind = 38000;
event.tags.push(["k", JIM_INSTANCE_KIND.toString()]);
event.dTag = eventId;
try {
if (!confirm("Confirm publish recommendation for event " + eventId)) {
return;
}
const publishedRelays = await event.publish(undefined, undefined, 1);
alert(
"Published to " +
Array.from(publishedRelays)
.map((relay) => relay.url)
.join(", "),
);
} catch (error) {
alert("Publish failed: " + error);
}
}

return (
<div className="">
<div className="flex justify-between items-center p-4">
<div className="flex items-center gap-2">
<img src={jimLogo} className="w-6 h-6" />
Jim Index
</div>
<div className="flex items-center justify-end gap-2">
{!store.hasLoaded && (
<span className="loading loading-spinner loading-md"></span>
)}
<button onClick={addJim} className="btn btn-primary">
Add Jim
</button>
</div>
</div>

<div className="flex gap-4">
{store.jims.map((jim) => (
<div key={jim.url} className="card bg-base-100 w-96 shadow-xl">
<div className="card-body">
<h2 className="card-title">
<a
href={jim.url}
target="_blank"
className="w-full link font-semibold"
>
{jim.url}
</a>
</h2>
<p className="text-sm">
{jim.recommendedByUsers.length} recommendations (
{jim.recommendedByUsers.filter((r) => r.mutual).length} mutual)
</p>
<div className="card-actions justify-end mt-2">
<button
onClick={() => recommend(jim.eventId)}
className="btn btn-primary btn-sm"
>
Recommend
</button>
</div>
</div>
</div>
))}
</div>
</div>
);
}
30 changes: 30 additions & 0 deletions src/assets/jim.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
10 changes: 10 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App.tsx'
import './index.css'

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
Loading

0 comments on commit adef43e

Please sign in to comment.