feat: solve conflicts
This commit is contained in:
@ -1,2 +1,2 @@
|
||||
/*
|
||||
Content-Security-Policy: default-src 'self'; manifest-src *; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.com https://embed.tidal.com https://w.soundcloud.com https://www.mixcloud.com https://open.spotify.com https://player.twitch.tv https://embed.music.apple.com https://nostrnests.com https://embed.wavlake.com; style-src 'self' 'unsafe-inline'; connect-src *; img-src * data: blob:; font-src 'self'; media-src * blob:; script-src 'self' 'wasm-unsafe-eval' https://static.cloudflareinsights.com https://platform.twitter.com https://embed.tidal.com;
|
||||
Content-Security-Policy: default-src 'self'; manifest-src *; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.com https://embed.tidal.com https://w.soundcloud.com https://www.mixcloud.com https://open.spotify.com https://player.twitch.tv https://embed.music.apple.com https://nostrnests.com https://embed.wavlake.com; style-src 'self' 'unsafe-inline'; connect-src *; img-src * data: blob:; font-src 'self'; media-src * blob:; script-src 'self' 'wasm-unsafe-eval' https://analytics.v0l.io https://platform.twitter.com https://embed.tidal.com;
|
1
packages/app/config/README.md
Normal file
1
packages/app/config/README.md
Normal file
@ -0,0 +1 @@
|
||||
Choose config with NODE_CONFIG_ENV: `NODE_CONFIG_ENV=iris yarn start`
|
7
packages/app/config/default.json
Normal file
7
packages/app/config/default.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"appName": "Snort",
|
||||
"appNameCapitalized": "Snort",
|
||||
"appTitle": "Snort - Nostr",
|
||||
"nip05Domain": "snort.social",
|
||||
"favicon": "public/favicon.ico"
|
||||
}
|
7
packages/app/config/iris.json
Normal file
7
packages/app/config/iris.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"appName": "iris",
|
||||
"appNameCapitalized": "Iris",
|
||||
"appTitle": "iris",
|
||||
"nip05Domain": "iris.to",
|
||||
"favicon": "public/iris.ico"
|
||||
}
|
@ -6,14 +6,15 @@
|
||||
"@lightninglabs/lnc-web": "^0.2.3-alpha",
|
||||
"@noble/curves": "^1.0.0",
|
||||
"@noble/hashes": "^1.2.0",
|
||||
"@reduxjs/toolkit": "^1.9.1",
|
||||
"@scure/base": "^1.1.1",
|
||||
"@scure/bip32": "^1.3.0",
|
||||
"@scure/bip39": "^1.1.1",
|
||||
"@snort/shared": "workspace:*",
|
||||
"@snort/system": "workspace:*",
|
||||
"@snort/system-react": "workspace:*",
|
||||
"@snort/system-wasm": "workspace:*",
|
||||
"@szhsin/react-menu": "^3.3.1",
|
||||
"@types/use-sync-external-store": "^0.0.4",
|
||||
"@void-cat/api": "^1.0.4",
|
||||
"debug": "^4.3.4",
|
||||
"dexie": "^3.2.4",
|
||||
@ -26,11 +27,11 @@
|
||||
"react-dom": "^18.2.0",
|
||||
"react-intersection-observer": "^9.4.1",
|
||||
"react-intl": "^6.4.4",
|
||||
"react-redux": "^8.0.5",
|
||||
"react-router-dom": "^6.5.0",
|
||||
"react-textarea-autosize": "^8.4.0",
|
||||
"react-twitter-embed": "^4.0.4",
|
||||
"use-long-press": "^2.0.3",
|
||||
"use-sync-external-store": "^1.2.0",
|
||||
"uuid": "^9.0.0",
|
||||
"workbox-core": "^6.4.2",
|
||||
"workbox-precaching": "^7.0.0",
|
||||
@ -43,9 +44,7 @@
|
||||
"test": "jest --runInBand",
|
||||
"intl-extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file src/lang.json --flatten true",
|
||||
"intl-compile": "formatjs compile src/lang.json --out-file src/translations/en.json",
|
||||
"format": "prettier --write .",
|
||||
"eslint": "eslint .",
|
||||
"prepare": "cd ../.. && husky install"
|
||||
"eslint": "eslint ."
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
@ -89,6 +88,7 @@
|
||||
"@webpack-cli/generators": "^3.0.4",
|
||||
"@webscopeio/react-textarea-autocomplete": "^4.9.2",
|
||||
"babel-loader": "^9.1.3",
|
||||
"config": "^3.3.9",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"css-loader": "^6.7.3",
|
||||
"css-minimizer-webpack-plugin": "^5.0.0",
|
||||
@ -102,6 +102,7 @@
|
||||
"prop-types": "^15.8.1",
|
||||
"source-map-loader": "^4.0.1",
|
||||
"terser-webpack-plugin": "^5.3.9",
|
||||
"tinybench": "^2.5.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-loader": "^9.4.4",
|
||||
"typescript": "^5.2.2",
|
||||
@ -110,8 +111,5 @@
|
||||
"webpack-cli": "^5.1.4",
|
||||
"webpack-dev-server": "^4.15.1",
|
||||
"workbox-webpack-plugin": "^6.5.4"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,jsx,ts,tsx,css,md}": "prettier --write"
|
||||
}
|
||||
}
|
||||
|
10
packages/app/public/bench.html
Normal file
10
packages/app/public/bench.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Snort Benchmarks</title>
|
||||
</head>
|
||||
<body>
|
||||
Check console
|
||||
</body>
|
||||
</html>
|
@ -176,7 +176,7 @@
|
||||
<path d="M22.1328 5.76872C22.3174 5.64092 22.4097 5.57702 22.4664 5.47424C22.5104 5.39443 22.5356 5.26804 22.5255 5.17745C22.5125 5.06079 22.463 4.98377 22.3638 4.82973C21.9839 4.23964 21.4373 3.75256 20.816 3.43598C20.3306 3.18868 19.8139 3.09012 19.2518 3.04419C18.7106 2.99998 18.0463 2.99999 17.2413 3H6.7587C5.95374 2.99999 5.28937 2.99998 4.74818 3.04419C4.18608 3.09012 3.66937 3.18868 3.18404 3.43598C2.62501 3.72082 2.1418 4.1326 1.77436 4.63335C1.65877 4.79089 1.60097 4.86966 1.58192 4.98921C1.56703 5.08269 1.58783 5.21257 1.63116 5.29674C1.68657 5.40436 1.78269 5.47302 1.97493 5.61033L10.75 11.8783C11.4773 12.3977 11.6316 12.4881 11.7681 12.5233C11.9272 12.5644 12.0939 12.5656 12.2535 12.5269C12.3906 12.4937 12.5463 12.4056 13.281 11.8969L22.1328 5.76872Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="bell-v2" viewBox="0 0 24 24" fill="none">
|
||||
<symbol id="bell-02" viewBox="0 0 24 24" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.99974 21C8.99974 20.4477 9.44745 20 9.99974 20H13.9997C14.552 20 14.9997 20.4477 14.9997 21C14.9997 21.5523 14.552 22 13.9997 22H9.99974C9.44745 22 8.99974 21.5523 8.99974 21Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.04999 3.05025C8.36275 1.7375 10.1432 1 11.9997 1C13.8563 1 15.6367 1.7375 16.9495 3.05025C18.2622 4.36301 18.9997 6.14349 18.9997 8C18.9997 10.9127 19.7317 12.8439 20.4991 14.0771L20.511 14.0962C20.8683 14.6704 21.1507 15.1243 21.3411 15.4547C21.4366 15.6202 21.5235 15.7797 21.5879 15.9215C21.62 15.9922 21.6559 16.079 21.684 16.1733C21.7073 16.2515 21.7517 16.4187 21.7351 16.6223C21.7239 16.7591 21.696 16.9928 21.5618 17.2343C21.4277 17.4758 21.244 17.623 21.1337 17.7047C20.8834 17.8904 20.596 17.9329 20.5001 17.947L20.4957 17.9477C20.3482 17.9695 20.181 17.9804 20.0122 17.9869C19.677 18 19.2128 18 18.6356 18H5.36388C4.78666 18 4.32252 18 3.98726 17.9869C3.81851 17.9804 3.65123 17.9695 3.50382 17.9477L3.49939 17.947C3.40347 17.9329 3.11604 17.8904 2.86574 17.7047C2.7555 17.623 2.57178 17.4758 2.43762 17.2343C2.30347 16.9928 2.27558 16.7591 2.26439 16.6223C2.24774 16.4187 2.29214 16.2515 2.31545 16.1733C2.34354 16.079 2.37948 15.9922 2.41161 15.9215C2.47598 15.7797 2.56291 15.6202 2.65833 15.4547C2.84876 15.1243 3.13124 14.6703 3.48856 14.0961L3.50035 14.0771C4.26773 12.8439 4.99974 10.9127 4.99974 8C4.99974 6.14348 5.73724 4.36301 7.04999 3.05025Z" fill="currentColor"/>
|
||||
@ -296,6 +296,52 @@
|
||||
<path d="M20 2C20 1.44772 19.5523 1 19 1C18.4477 1 18 1.44772 18 2V4H16C15.4477 4 15 4.44772 15 5C15 5.55228 15.4477 6 16 6H18V8C18 8.55228 18.4477 9 19 9C19.5523 9 20 8.55228 20 8V6H22C22.5523 6 23 5.55228 23 5C23 4.44772 22.5523 4 22 4H20V2Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="grid-01" viewBox="0 0 24 24" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.56811 2C5.85605 2.00016 7.1465 2.00016 8.4319 2C8.68429 1.99997 8.93008 1.99994 9.13824 2.01695C9.36683 2.03563 9.63656 2.07969 9.90799 2.21799C10.2843 2.40974 10.5903 2.7157 10.782 3.09202C10.9203 3.36345 10.9644 3.63318 10.9831 3.86178C11.0001 4.06994 11 4.31574 11 4.56813V8.43189C11 8.68427 11.0001 8.93007 10.9831 9.13824C10.9644 9.36683 10.9203 9.63656 10.782 9.90799C10.5903 10.2843 10.2843 10.5903 9.90799 10.782C9.63656 10.9203 9.36683 10.9644 9.13824 10.9831C8.93007 11.0001 8.68427 11 8.43189 11H4.56812C4.31574 11 4.06994 11.0001 3.86178 10.9831C3.63318 10.9644 3.36345 10.9203 3.09202 10.782C2.7157 10.5903 2.40974 10.2843 2.21799 9.90799C2.07969 9.63656 2.03563 9.36683 2.01695 9.13824C1.99994 8.93008 1.99997 8.68429 2 8.4319C2 8.42128 2.00001 8.41065 2.00001 8.40001V4.60001C2.00001 4.58936 2 4.57873 2 4.56811C1.99997 4.31572 1.99994 4.06993 2.01695 3.86178C2.03563 3.63318 2.07969 3.36345 2.21799 3.09202C2.40974 2.7157 2.7157 2.40974 3.09202 2.21799C3.36345 2.07969 3.63318 2.03563 3.86178 2.01695C4.06993 1.99994 4.31572 1.99997 4.56811 2Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.56811 13C5.85605 13.0002 7.1465 13.0002 8.4319 13C8.68429 13 8.93008 12.9999 9.13824 13.017C9.36683 13.0356 9.63656 13.0797 9.90799 13.218C10.2843 13.4097 10.5903 13.7157 10.782 14.092C10.9203 14.3634 10.9644 14.6332 10.9831 14.8618C11.0001 15.0699 11 15.3157 11 15.5681V19.4319C11 19.6843 11.0001 19.9301 10.9831 20.1382C10.9644 20.3668 10.9203 20.6366 10.782 20.908C10.5903 21.2843 10.2843 21.5903 9.90799 21.782C9.63656 21.9203 9.36683 21.9644 9.13824 21.9831C8.93007 22.0001 8.68427 22 8.43189 22H4.56812C4.31574 22 4.06994 22.0001 3.86178 21.9831C3.63318 21.9644 3.36345 21.9203 3.09202 21.782C2.7157 21.5903 2.40974 21.2843 2.21799 20.908C2.07969 20.6366 2.03563 20.3668 2.01695 20.1382C1.99994 19.9301 1.99997 19.6843 2 19.4319C2 19.4213 2.00001 19.4106 2.00001 19.4V15.6C2.00001 15.5894 2 15.5787 2 15.5681C1.99997 15.3157 1.99994 15.0699 2.01695 14.8618C2.03563 14.6332 2.07969 14.3634 2.21799 14.092C2.40974 13.7157 2.7157 13.4097 3.09202 13.218C3.36345 13.0797 3.63318 13.0356 3.86178 13.017C4.06993 12.9999 4.31572 13 4.56811 13Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.5681 2C16.856 2.00016 18.1465 2.00016 19.4319 2C19.6843 1.99997 19.9301 1.99994 20.1382 2.01695C20.3668 2.03563 20.6366 2.07969 20.908 2.21799C21.2843 2.40974 21.5903 2.7157 21.782 3.09202C21.9203 3.36345 21.9644 3.63318 21.9831 3.86178C22.0001 4.06994 22 4.31574 22 4.56813V8.43189C22 8.68427 22.0001 8.93007 21.9831 9.13824C21.9644 9.36683 21.9203 9.63656 21.782 9.90799C21.5903 10.2843 21.2843 10.5903 20.908 10.782C20.6366 10.9203 20.3668 10.9644 20.1382 10.9831C19.9301 11.0001 19.6843 11 19.4319 11H15.5681C15.3157 11 15.0699 11.0001 14.8618 10.9831C14.6332 10.9644 14.3634 10.9203 14.092 10.782C13.7157 10.5903 13.4097 10.2843 13.218 9.90799C13.0797 9.63656 13.0356 9.36683 13.017 9.13824C12.9999 8.93008 13 8.68429 13 8.4319C13 8.42128 13 8.41065 13 8.40001V4.60001C13 4.58936 13 4.57873 13 4.56811C13 4.31572 12.9999 4.06993 13.017 3.86178C13.0356 3.63318 13.0797 3.36345 13.218 3.09202C13.4097 2.7157 13.7157 2.40974 14.092 2.21799C14.3634 2.07969 14.6332 2.03563 14.8618 2.01695C15.0699 1.99994 15.3157 1.99997 15.5681 2Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.5681 13C16.856 13.0002 18.1465 13.0002 19.4319 13C19.6843 13 19.9301 12.9999 20.1382 13.017C20.3668 13.0356 20.6366 13.0797 20.908 13.218C21.2843 13.4097 21.5903 13.7157 21.782 14.092C21.9203 14.3634 21.9644 14.6332 21.9831 14.8618C22.0001 15.0699 22 15.3157 22 15.5681V19.4319C22 19.6843 22.0001 19.9301 21.9831 20.1382C21.9644 20.3668 21.9203 20.6366 21.782 20.908C21.5903 21.2843 21.2843 21.5903 20.908 21.782C20.6366 21.9203 20.3668 21.9644 20.1382 21.9831C19.9301 22.0001 19.6843 22 19.4319 22H15.5681C15.3157 22 15.0699 22.0001 14.8618 21.9831C14.6332 21.9644 14.3634 21.9203 14.092 21.782C13.7157 21.5903 13.4097 21.2843 13.218 20.908C13.0797 20.6366 13.0356 20.3668 13.017 20.1382C12.9999 19.9301 13 19.6843 13 19.4319C13 19.4213 13 19.4106 13 19.4V15.6C13 15.5894 13 15.5787 13 15.5681C13 15.3157 12.9999 15.0699 13.017 14.8618C13.0356 14.6332 13.0797 14.3634 13.218 14.092C13.4097 13.7157 13.7157 13.4097 14.092 13.218C14.3634 13.0797 14.6332 13.0356 14.8618 13.017C15.0699 12.9999 15.3157 13 15.5681 13Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="settings-02" viewBox="0 0 24 24" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.74225 21.5541L9.08973 20.1082C8.85724 19.5922 8.4646 19.1621 7.9683 18.8799C7.47171 18.5977 6.89723 18.4774 6.32708 18.5364L4.73053 18.7039C4.25532 18.7531 3.77581 18.6656 3.35002 18.4519C2.92423 18.2383 2.57041 17.9076 2.33135 17.5C2.09223 17.0924 1.97831 16.6252 2.00341 16.1551C2.02851 15.6849 2.19156 15.2321 2.47277 14.8514L3.41805 13.5718C3.75516 13.115 3.9367 12.5648 3.93659 12C3.9367 11.4352 3.75516 10.885 3.41805 10.4282L2.47277 9.14855C2.19156 8.76793 2.02851 8.31508 2.00341 7.84494C1.97831 7.3748 2.09223 6.90759 2.33135 6.5C2.57017 6.09216 2.92395 5.76134 3.3498 5.54765C3.77565 5.33396 4.25528 5.24658 4.73053 5.29611L6.33205 5.46356C6.90219 5.52255 7.47667 5.40233 7.97326 5.12011C8.46771 4.83708 8.85854 4.40709 9.08973 3.89178L9.74225 2.44589C9.93622 2.01549 10.2528 1.64979 10.6535 1.39314C11.0543 1.13649 11.522 0.999923 12 1C12.478 0.999923 12.9457 1.13649 13.3465 1.39314C13.7472 1.64979 14.0638 2.01549 14.2578 2.44589L14.9152 3.89178C15.1464 4.40709 15.5372 4.83708 16.0317 5.12011C16.5283 5.40233 17.1028 5.52255 17.6729 5.46356L19.2695 5.29611C19.7447 5.24658 20.2243 5.33396 20.6502 5.54765C21.076 5.76134 21.4298 6.09216 21.6686 6.5C21.9078 6.90759 22.0217 7.3748 21.9966 7.84494C21.9715 8.31508 21.8084 8.76793 21.5272 9.14855L20.5819 10.4282C20.2448 10.885 20.0633 11.4352 20.0634 12C20.0605 12.5663 20.2404 13.1188 20.577 13.5779L21.5223 14.8576C21.8035 15.2382 21.9665 15.691 21.9916 16.1612C22.0167 16.6313 21.9028 17.0985 21.6637 17.5061C21.4249 17.914 21.0711 18.2448 20.6452 18.4585C20.2194 18.6722 19.7398 18.7595 19.2645 18.71L17.668 18.5426C17.0978 18.4836 16.5233 18.6038 16.0267 18.886C15.5333 19.1674 15.1425 19.5952 14.9103 20.1082L14.2578 21.5541C14.0638 21.9845 13.7472 22.3502 13.3465 22.6069C12.9457 22.8635 12.478 23.0001 12 23C11.522 23.0001 11.0543 22.8635 10.6535 22.6069C10.2528 22.3502 9.93622 21.9845 9.74225 21.5541ZM15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12C9 10.3431 10.3431 9 12 9C13.6569 9 15 10.3431 15 12Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="rows-01" viewBox="0 0 24 24" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M22 17.1615V17.8385C22 18.3657 22 18.8205 21.9694 19.195C21.9371 19.5904 21.8658 19.9836 21.673 20.362C21.3854 20.9265 20.9265 21.3854 20.362 21.673C19.9836 21.8658 19.5904 21.9371 19.195 21.9694C18.8205 22 18.3657 22 17.8385 22H6.16148C5.63432 22 5.17955 22 4.80497 21.9694C4.40963 21.9371 4.01641 21.8658 3.63803 21.673C3.07354 21.3854 2.6146 20.9265 2.32698 20.362C2.13419 19.9836 2.06287 19.5904 2.03057 19.195C1.99997 18.8205 1.99998 18.3657 2 17.8386L2 17.1614C1.99998 16.6343 1.99997 16.1795 2.03057 15.805C2.06287 15.4096 2.13419 15.0164 2.32698 14.638C2.6146 14.0735 3.07354 13.6146 3.63803 13.327C4.01641 13.1342 4.40963 13.0629 4.80497 13.0306C5.17955 13 5.63431 13 6.16146 13L17.8385 13C18.3657 13 18.8205 13 19.195 13.0306C19.5904 13.0629 19.9836 13.1342 20.362 13.327C20.9265 13.6146 21.3854 14.0735 21.673 14.638C21.8658 15.0164 21.9371 15.4096 21.9694 15.805C22 16.1795 22 16.6343 22 17.1615Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M22 6.16146V6.83855C22 7.36569 22 7.82046 21.9694 8.19503C21.9371 8.59038 21.8658 8.98359 21.673 9.36197C21.3854 9.92646 20.9265 10.3854 20.362 10.673C19.9836 10.8658 19.5904 10.9371 19.195 10.9694C18.8205 11 18.3657 11 17.8385 11L6.16148 11C5.63432 11 5.17955 11 4.80497 10.9694C4.40963 10.9371 4.01641 10.8658 3.63803 10.673C3.07354 10.3854 2.6146 9.92646 2.32698 9.36197C2.13419 8.98359 2.06287 8.59037 2.03057 8.19503C1.99997 7.82046 1.99998 7.36571 2 6.83857L2 6.16144C1.99998 5.6343 1.99997 5.17954 2.03057 4.80497C2.06287 4.40963 2.13419 4.01641 2.32698 3.63803C2.6146 3.07354 3.07354 2.6146 3.63803 2.32698C4.01641 2.13419 4.40963 2.06287 4.80497 2.03057C5.17955 1.99997 5.63431 1.99998 6.16146 2L17.8385 2C18.3657 1.99998 18.8205 1.99997 19.195 2.03057C19.5904 2.06287 19.9836 2.13419 20.362 2.32698C20.9265 2.6146 21.3854 3.07354 21.673 3.63803C21.8658 4.01641 21.9371 4.40963 21.9694 4.80497C22 5.17955 22 5.63431 22 6.16146Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="camera-lens" viewBox="0 0 24 24" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.7782 4.22183C24.0739 8.5176 24.0739 15.4824 19.7782 19.7782C15.4824 24.0739 8.51757 24.0739 4.22183 19.7782C-0.073941 15.4824 -0.0739439 8.51757 4.22183 4.22183C8.5176 -0.0739412 15.4824 -0.0739441 19.7782 4.22183ZM18.3639 5.63604C16.9457 4.21783 15.172 3.37188 13.3296 3.09818C15.1903 4.84851 16.3469 7.26042 16.5131 9.84459C16.7413 10.3224 16.8892 10.8289 16.957 11.344C18.1231 9.82019 18.7436 7.89858 18.6289 5.91225C18.5429 5.81878 18.4546 5.72668 18.3639 5.63604ZM13.9108 7.37813C13.1743 5.60658 11.8204 4.10837 10.0429 3.21421C8.42788 3.57237 6.89244 4.37965 5.63604 5.63604C5.39169 5.88039 5.16433 6.13529 4.95396 6.39928C7.40123 5.66183 10.0699 5.86592 12.3924 7.01533C12.9104 7.05586 13.4233 7.17679 13.9108 7.37813ZM8.95317 8.03485C7.04977 7.78701 5.07457 8.21117 3.4111 9.30482C2.79889 11.2616 2.87046 13.3861 3.62582 15.3036C4.21048 12.8157 5.72136 10.6067 7.87702 9.16982C8.04787 8.92153 8.24369 8.68524 8.46446 8.46446C8.62007 8.30886 8.78338 8.16566 8.95317 8.03485ZM7.04296 12.656C5.87684 14.1797 5.25622 16.1012 5.37085 18.0874C5.4569 18.181 5.5453 18.2732 5.63604 18.3639C7.05418 19.7821 8.82785 20.628 10.6701 20.9018C8.80942 19.1513 7.65282 16.7393 7.48676 14.1551C7.25866 13.6774 7.11073 13.1709 7.04296 12.656ZM10.089 16.6218C10.8255 18.3934 12.1794 19.8916 13.9569 20.7858C15.572 20.4277 17.1075 19.6204 18.3639 18.3639C18.6084 18.1195 18.8358 17.8646 19.0462 17.6005C16.599 18.338 13.9303 18.134 11.6079 16.9847C11.0897 16.9442 10.5766 16.8232 10.089 16.6218ZM15.047 15.965C15.2167 15.8343 15.38 15.6911 15.5355 15.5355C15.7563 15.3148 15.952 15.0786 16.1228 14.8304C18.2786 13.3934 19.7895 11.1842 20.3741 8.69606C21.1295 10.6136 21.2011 12.7381 20.589 14.6949C18.9255 15.7886 16.9504 16.2128 15.047 15.965Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="file-06" viewBox="0 0 24 24" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M13 2.01558C13 1.98928 13 1.97612 12.9989 1.95227C12.9753 1.4585 12.541 1.02448 12.0473 1.00112C12.0234 0.999992 12.0156 0.999995 12 1H12H8.75866H8.75862C7.95369 0.99999 7.28935 0.999981 6.74818 1.0442C6.18608 1.09012 5.66938 1.18869 5.18404 1.43598C4.43139 1.81947 3.81947 2.43139 3.43598 3.18404C3.18869 3.66938 3.09012 4.18608 3.0442 4.74818C2.99998 5.28936 2.99999 5.95372 3 6.75867V6.75869V17.2413V17.2413C2.99999 18.0463 2.99998 18.7106 3.0442 19.2518C3.09012 19.8139 3.18869 20.3306 3.43598 20.816C3.81947 21.5686 4.43139 22.1805 5.18404 22.564C5.66938 22.8113 6.18608 22.9099 6.74818 22.9558C7.28937 23 7.95372 23 8.75868 23H15.2413C16.0463 23 16.7106 23 17.2518 22.9558C17.8139 22.9099 18.3306 22.8113 18.816 22.564C19.5686 22.1805 20.1805 21.5686 20.564 20.816C20.8113 20.3306 20.9099 19.8139 20.9558 19.2518C21 18.7106 21 18.0463 21 17.2413V9.99994C21 9.98441 21 9.97664 20.9989 9.95282C20.9756 9.45899 20.5415 9.02471 20.0477 9.00115C20.0238 9.00001 20.0107 9.00001 19.9845 9.00001L15.5681 9.00001C15.3157 9.00004 15.0699 9.00007 14.8618 8.98307C14.6332 8.96439 14.3634 8.92032 14.092 8.78202C13.7157 8.59028 13.4097 8.28432 13.218 7.90799C13.0797 7.63657 13.0356 7.36683 13.017 7.13824C12.9999 6.93008 13 6.68429 13 6.43191L13 2.01558ZM18.908 6.99999C19.2016 7 19.3484 7 19.4686 6.92627C19.6385 6.82215 19.74 6.57684 19.6935 6.38313C19.6605 6.24598 19.5648 6.15033 19.3733 5.95904L16.041 2.62672C15.8497 2.43523 15.754 2.33949 15.6169 2.30652C15.4232 2.25996 15.1779 2.3615 15.0737 2.53134C15 2.65161 15 2.79842 15 3.09204L15 6.19996C15 6.47998 15 6.61999 15.0545 6.72694C15.1024 6.82102 15.1789 6.89751 15.273 6.94545C15.38 6.99995 15.52 6.99995 15.8 6.99995L18.908 6.99999ZM8 9C7.44772 9 7 9.44772 7 10C7 10.5523 7.44772 11 8 11H10C10.5523 11 11 10.5523 11 10C11 9.44772 10.5523 9 10 9H8ZM7 14C7 13.4477 7.44772 13 8 13H16C16.5523 13 17 13.4477 17 14C17 14.5523 16.5523 15 16 15H8C7.44772 15 7 14.5523 7 14ZM7 18C7 17.4477 7.44772 17 8 17H16C16.5523 17 17 17.4477 17 18C17 18.5523 16.5523 19 16 19H8C7.44772 19 7 18.5523 7 18Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="alert-circle" viewBox="0 0 18 19" fill="none">
|
||||
<g>
|
||||
<path d="M9 6.5V9.5M9 12.5H9.0075M16.5 9.5C16.5 13.6421 13.1421 17 9 17C4.85786 17 1.5 13.6421 1.5 9.5C1.5 5.35786 4.85786 2 9 2C13.1421 2 16.5 5.35786 16.5 9.5Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="signal-01" viewBox="0 0 24 25" fill="none">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.5355 7.55101C15.9261 7.16048 16.5592 7.16048 16.9497 7.55101C19.6834 10.2847 19.6834 14.7168 16.9497 17.4505C16.5592 17.841 15.9261 17.841 15.5355 17.4505C15.145 17.06 15.145 16.4268 15.5355 16.0363C17.4882 14.0837 17.4882 10.9178 15.5355 8.96522C15.145 8.5747 15.145 7.94153 15.5355 7.55101Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.46447 7.55097C8.85499 7.9415 8.85499 8.57466 8.46447 8.96519C6.51184 10.9178 6.51184 14.0836 8.46447 16.0363C8.85499 16.4268 8.85499 17.0599 8.46447 17.4505C8.07394 17.841 7.44078 17.841 7.05025 17.4505C4.31658 14.7168 4.31658 10.2846 7.05025 7.55097C7.44078 7.16045 8.07394 7.16045 8.46447 7.55097Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.63604 4.72258C6.02656 5.11311 6.02656 5.74627 5.63604 6.13679C2.12132 9.65151 2.12132 15.35 5.63604 18.8647C6.02656 19.2552 6.02656 19.8884 5.63604 20.2789C5.24551 20.6695 4.61235 20.6695 4.22183 20.2789C-0.0739419 15.9832 -0.0739419 9.01835 4.22183 4.72258C4.61235 4.33206 5.24551 4.33206 5.63604 4.72258Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M18.364 4.72263C18.7545 4.3321 19.3877 4.3321 19.7782 4.72263C24.0739 9.01839 24.0739 15.9832 19.7782 20.279C19.3877 20.6695 18.7545 20.6695 18.364 20.279C17.9734 19.8885 17.9734 19.2553 18.364 18.8648C21.8787 15.35 21.8787 9.65156 18.364 6.13684C17.9734 5.74632 17.9734 5.11315 18.364 4.72263Z" fill="currentColor"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M9 12.5008C9 10.8439 10.3431 9.50076 12 9.50076C13.6569 9.50076 15 10.8439 15 12.5008C15 14.1576 13.6569 15.5008 12 15.5008C10.3431 15.5008 9 14.1576 9 12.5008Z" fill="currentColor"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<symbol id="shield-tick" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M9 11.5L11 13.5L15.5 8.99999M20 12C20 16.9084 14.646 20.4784 12.698 21.6149C12.4766 21.744 12.3659 21.8086 12.2097 21.8421C12.0884 21.8681 11.9116 21.8681 11.7903 21.8421C11.6341 21.8086 11.5234 21.744 11.302 21.6149C9.35396 20.4784 4 16.9084 4 12V7.21759C4 6.41808 4 6.01833 4.13076 5.6747C4.24627 5.37113 4.43398 5.10027 4.67766 4.88552C4.9535 4.64243 5.3278 4.50207 6.0764 4.22134L11.4382 2.21067C11.6461 2.13271 11.75 2.09373 11.857 2.07827C11.9518 2.06457 12.0482 2.06457 12.143 2.07827C12.25 2.09373 12.3539 2.13271 12.5618 2.21067L17.9236 4.22134C18.6722 4.50207 19.0465 4.64243 19.3223 4.88552C19.566 5.10027 19.7537 5.37113 19.8692 5.6747C20 6.01833 20 6.41808 20 7.21759V12Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</symbol>
|
||||
|
||||
</defs>
|
||||
</svg>
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 91 KiB |
@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@ -11,7 +11,7 @@
|
||||
<link rel="preconnect" href="https://imgproxy.snort.social" />
|
||||
<link rel="apple-touch-icon" href="/nostrich_512.png" />
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<title>Snort - Nostr</title>
|
||||
<title><%= htmlWebpackPlugin.options.templateParameters.appTitle %></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
BIN
packages/app/public/iris.ico
Normal file
BIN
packages/app/public/iris.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
126
packages/app/src/Cache/FollowsFeed.ts
Normal file
126
packages/app/src/Cache/FollowsFeed.ts
Normal file
@ -0,0 +1,126 @@
|
||||
import debug from "debug";
|
||||
import { EventKind, RequestBuilder, SystemInterface, TaggedNostrEvent } from "@snort/system";
|
||||
import { unixNow, unixNowMs } from "@snort/shared";
|
||||
|
||||
import { db } from "Db";
|
||||
import { RefreshFeedCache, TWithCreated } from "./RefreshFeedCache";
|
||||
import { LoginSession } from "Login";
|
||||
import { Day, Hour } from "Const";
|
||||
|
||||
const WindowSize = Hour * 6;
|
||||
const MaxCacheWindow = Day * 7;
|
||||
|
||||
export class FollowsFeedCache extends RefreshFeedCache<TaggedNostrEvent> {
|
||||
#kinds = [EventKind.TextNote, EventKind.Repost, EventKind.Polls];
|
||||
#oldest?: number;
|
||||
|
||||
constructor() {
|
||||
super("FollowsFeedCache", db.followsFeed);
|
||||
}
|
||||
|
||||
key(of: TWithCreated<TaggedNostrEvent>): string {
|
||||
return of.id;
|
||||
}
|
||||
|
||||
takeSnapshot(): TWithCreated<TaggedNostrEvent>[] {
|
||||
return [...this.cache.values()];
|
||||
}
|
||||
|
||||
buildSub(session: LoginSession, rb: RequestBuilder): void {
|
||||
const since = this.newest();
|
||||
rb.withFilter()
|
||||
.kinds(this.#kinds)
|
||||
.authors(session.follows.item)
|
||||
.since(since === 0 ? unixNow() - WindowSize : since);
|
||||
}
|
||||
|
||||
async onEvent(evs: readonly TaggedNostrEvent[]): Promise<void> {
|
||||
const filtered = evs.filter(a => this.#kinds.includes(a.kind));
|
||||
if (filtered.length > 0) {
|
||||
await this.bulkSet(filtered);
|
||||
this.notifyChange(filtered.map(a => this.key(a)));
|
||||
}
|
||||
}
|
||||
|
||||
override async preload() {
|
||||
const start = unixNowMs();
|
||||
const keys = (await this.table?.toCollection().primaryKeys()) ?? [];
|
||||
this.onTable = new Set<string>(keys.map(a => a as string));
|
||||
|
||||
// load only latest 10 posts, rest can be loaded on-demand
|
||||
const latest = await this.table?.orderBy("created_at").reverse().limit(50).toArray();
|
||||
latest?.forEach(v => this.cache.set(this.key(v), v));
|
||||
|
||||
// cleanup older than 7 days
|
||||
await this.table
|
||||
?.where("created_at")
|
||||
.below(unixNow() - MaxCacheWindow)
|
||||
.delete();
|
||||
|
||||
const oldest = await this.table?.orderBy("created_at").first();
|
||||
this.#oldest = oldest?.created_at;
|
||||
this.notifyChange(latest?.map(a => this.key(a)) ?? []);
|
||||
|
||||
debug(this.name)(`Loaded %d/%d in %d ms`, latest?.length ?? 0, keys.length, (unixNowMs() - start).toLocaleString());
|
||||
}
|
||||
|
||||
async loadMore(system: SystemInterface, session: LoginSession, before: number) {
|
||||
if (this.#oldest && before <= this.#oldest) {
|
||||
const rb = new RequestBuilder(`${this.name}-loadmore`);
|
||||
rb.withFilter()
|
||||
.kinds(this.#kinds)
|
||||
.authors(session.follows.item)
|
||||
.until(before)
|
||||
.since(before - WindowSize);
|
||||
await system.Fetch(rb, async evs => {
|
||||
await this.bulkSet(evs);
|
||||
});
|
||||
} else {
|
||||
const latest = await this.table
|
||||
?.where("created_at")
|
||||
.between(before - WindowSize, before)
|
||||
.reverse()
|
||||
.sortBy("created_at");
|
||||
latest?.forEach(v => {
|
||||
const k = this.key(v);
|
||||
this.cache.set(k, v);
|
||||
this.onTable.add(k);
|
||||
});
|
||||
|
||||
this.notifyChange(latest?.map(a => this.key(a)) ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Backfill cache with new follows
|
||||
*/
|
||||
async backFill(system: SystemInterface, keys: Array<string>) {
|
||||
if (keys.length === 0) return;
|
||||
|
||||
const rb = new RequestBuilder(`${this.name}-backfill`);
|
||||
rb.withFilter()
|
||||
.kinds(this.#kinds)
|
||||
.authors(keys)
|
||||
.until(unixNow())
|
||||
.since(this.#oldest ?? unixNow() - MaxCacheWindow);
|
||||
await system.Fetch(rb, async evs => {
|
||||
await this.bulkSet(evs);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Backfill cache based on follows list
|
||||
*/
|
||||
async backFillIfMissing(system: SystemInterface, keys: Array<string>) {
|
||||
if (!this.#oldest) return;
|
||||
|
||||
const start = unixNowMs();
|
||||
const everything = await this.table?.toArray();
|
||||
if ((everything?.length ?? 0) > 0) {
|
||||
const allKeys = new Set(everything?.map(a => a.pubkey));
|
||||
const missingKeys = keys.filter(a => !allKeys.has(a));
|
||||
await this.backFill(system, missingKeys);
|
||||
debug(this.name)(`Backfilled %d keys in %d ms`, missingKeys.length, (unixNowMs() - start).toLocaleString());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import { FeedCache } from "@snort/shared";
|
||||
import { EventKind, EventPublisher, TaggedNostrEvent } from "@snort/system";
|
||||
import { EventKind, EventPublisher, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { UnwrappedGift, db } from "Db";
|
||||
import { findTag, unwrap } from "SnortUtils";
|
||||
import { RefreshFeedCache } from "./RefreshFeedCache";
|
||||
import { LoginSession, LoginSessionType } from "Login";
|
||||
|
||||
export class GiftWrapCache extends FeedCache<UnwrappedGift> {
|
||||
export class GiftWrapCache extends RefreshFeedCache<UnwrappedGift> {
|
||||
constructor() {
|
||||
super("GiftWrapCache", db.gifts);
|
||||
}
|
||||
@ -12,22 +13,20 @@ export class GiftWrapCache extends FeedCache<UnwrappedGift> {
|
||||
return of.id;
|
||||
}
|
||||
|
||||
override async preload(): Promise<void> {
|
||||
await super.preload();
|
||||
await this.buffer([...this.onTable]);
|
||||
}
|
||||
|
||||
newest(): number {
|
||||
let ret = 0;
|
||||
this.cache.forEach(v => (ret = v.created_at > ret ? v.created_at : ret));
|
||||
return ret;
|
||||
buildSub(session: LoginSession, rb: RequestBuilder): void {
|
||||
const pubkey = session.publicKey;
|
||||
if (pubkey && session.type === LoginSessionType.PrivateKey) {
|
||||
rb.withFilter().kinds([EventKind.GiftWrap]).tag("p", [pubkey]).since(this.newest());
|
||||
}
|
||||
}
|
||||
|
||||
takeSnapshot(): Array<UnwrappedGift> {
|
||||
return [...this.cache.values()];
|
||||
}
|
||||
|
||||
async onEvent(evs: Array<TaggedNostrEvent>, pub: EventPublisher) {
|
||||
override async onEvent(evs: Array<TaggedNostrEvent>, pub?: EventPublisher) {
|
||||
if (!pub) return;
|
||||
|
||||
const unwrapped = (
|
||||
await Promise.all(
|
||||
evs.map(async v => {
|
||||
@ -41,7 +40,7 @@ export class GiftWrapCache extends FeedCache<UnwrappedGift> {
|
||||
} catch (e) {
|
||||
console.debug(e, v);
|
||||
}
|
||||
})
|
||||
}),
|
||||
)
|
||||
)
|
||||
.filter(a => a !== undefined)
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { EventKind, NostrEvent, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { RefreshFeedCache, TWithCreated } from "./RefreshFeedCache";
|
||||
import { LoginSession } from "Login";
|
||||
import { unixNow } from "SnortUtils";
|
||||
import { db } from "Db";
|
||||
import { Day } from "Const";
|
||||
import { unixNow } from "@snort/shared";
|
||||
|
||||
export class NotificationsCache extends RefreshFeedCache<NostrEvent> {
|
||||
#kinds = [EventKind.TextNote, EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt];
|
||||
@ -17,7 +18,7 @@ export class NotificationsCache extends RefreshFeedCache<NostrEvent> {
|
||||
rb.withFilter()
|
||||
.kinds(this.#kinds)
|
||||
.tag("p", [session.publicKey])
|
||||
.since(newest === 0 ? unixNow() - 60 * 60 * 24 * 30 : newest);
|
||||
.since(newest === 0 ? unixNow() - Day * 30 : newest);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { FeedCache } from "@snort/shared";
|
||||
import { RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { EventPublisher, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { LoginSession } from "Login";
|
||||
|
||||
export type TWithCreated<T> = T & { created_at: number };
|
||||
export type TWithCreated<T> = (T | Readonly<T>) & { created_at: number };
|
||||
|
||||
export abstract class RefreshFeedCache<T> extends FeedCache<TWithCreated<T>> {
|
||||
abstract buildSub(session: LoginSession, rb: RequestBuilder): void;
|
||||
abstract onEvent(evs: Readonly<Array<TaggedNostrEvent>>): void;
|
||||
abstract onEvent(evs: Readonly<Array<TaggedNostrEvent>>, pub?: EventPublisher): void;
|
||||
|
||||
/**
|
||||
* Get latest event
|
||||
|
@ -4,6 +4,7 @@ import { ChatCache } from "./ChatCache";
|
||||
import { Payments } from "./PaymentsCache";
|
||||
import { GiftWrapCache } from "./GiftWrapCache";
|
||||
import { NotificationsCache } from "./Notifications";
|
||||
import { FollowsFeedCache } from "./FollowsFeed";
|
||||
|
||||
export const UserCache = new UserProfileCache();
|
||||
export const UserRelays = new UserRelaysCache();
|
||||
@ -13,6 +14,7 @@ export const PaymentsCache = new Payments();
|
||||
export const InteractionCache = new EventInteractionCache();
|
||||
export const GiftsCache = new GiftWrapCache();
|
||||
export const Notifications = new NotificationsCache();
|
||||
export const FollowsFeed = new FollowsFeedCache();
|
||||
|
||||
export async function preload(follows?: Array<string>) {
|
||||
const preloads = [
|
||||
@ -23,6 +25,7 @@ export async function preload(follows?: Array<string>) {
|
||||
RelayMetrics.preload(),
|
||||
GiftsCache.preload(),
|
||||
Notifications.preload(),
|
||||
FollowsFeed.preload(),
|
||||
];
|
||||
await Promise.all(preloads);
|
||||
}
|
||||
|
@ -1,5 +1,15 @@
|
||||
import { RelaySettings } from "@snort/system";
|
||||
|
||||
/**
|
||||
* 1 Hour in seconds
|
||||
*/
|
||||
export const Hour = 60 * 60;
|
||||
|
||||
/**
|
||||
* 1 Day in seconds
|
||||
*/
|
||||
export const Day = Hour * 24;
|
||||
|
||||
/**
|
||||
* Add-on api for snort features
|
||||
*/
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Dexie, { Table } from "dexie";
|
||||
import { HexKey, NostrEvent, u256 } from "@snort/system";
|
||||
import { HexKey, NostrEvent, TaggedNostrEvent, u256 } from "@snort/system";
|
||||
|
||||
export const NAME = "snortDB";
|
||||
export const VERSION = 13;
|
||||
export const VERSION = 14;
|
||||
|
||||
export interface SubCache {
|
||||
id: string;
|
||||
@ -41,6 +41,7 @@ const STORES = {
|
||||
payments: "++url",
|
||||
gifts: "++id",
|
||||
notifications: "++id",
|
||||
followsFeed: "++id, created_at, kind",
|
||||
};
|
||||
|
||||
export class SnortDB extends Dexie {
|
||||
@ -50,6 +51,7 @@ export class SnortDB extends Dexie {
|
||||
payments!: Table<Payment>;
|
||||
gifts!: Table<UnwrappedGift>;
|
||||
notifications!: Table<NostrEvent>;
|
||||
followsFeed!: Table<TaggedNostrEvent>;
|
||||
|
||||
constructor() {
|
||||
super(NAME);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import "./AsyncButton.css";
|
||||
import { useState } from "react";
|
||||
import React, { useState, ForwardedRef } from "react";
|
||||
import Spinner from "../Icons/Spinner";
|
||||
|
||||
interface AsyncButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
@ -8,7 +8,7 @@ interface AsyncButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export default function AsyncButton(props: AsyncButtonProps) {
|
||||
const AsyncButton = React.forwardRef<HTMLButtonElement, AsyncButtonProps>((props, ref) => {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
async function handle(e: React.MouseEvent) {
|
||||
@ -28,7 +28,13 @@ export default function AsyncButton(props: AsyncButtonProps) {
|
||||
}
|
||||
|
||||
return (
|
||||
<button className="spinner-button" type="button" disabled={loading || props.disabled} {...props} onClick={handle}>
|
||||
<button
|
||||
ref={ref as ForwardedRef<HTMLButtonElement>}
|
||||
className="spinner-button"
|
||||
type="button"
|
||||
disabled={loading || props.disabled}
|
||||
{...props}
|
||||
onClick={handle}>
|
||||
<span style={{ visibility: loading ? "hidden" : "visible" }}>{props.children}</span>
|
||||
{loading && (
|
||||
<span className="spinner-wrapper">
|
||||
@ -37,4 +43,6 @@ export default function AsyncButton(props: AsyncButtonProps) {
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default AsyncButton;
|
||||
|
@ -1,20 +0,0 @@
|
||||
.avatar {
|
||||
border-radius: 50%;
|
||||
height: 210px;
|
||||
width: 210px;
|
||||
background-image: var(--img-url);
|
||||
border: 1px solid transparent;
|
||||
background-origin: border-box;
|
||||
background-clip: content-box, border-box;
|
||||
background-size: cover;
|
||||
box-sizing: border-box;
|
||||
background-color: var(--gray);
|
||||
}
|
||||
|
||||
.avatar[data-domain="snort.social"] {
|
||||
background-image: var(--img-url), var(--snort-gradient);
|
||||
}
|
||||
|
||||
.avatar[data-domain="strike.army"] {
|
||||
background-image: var(--img-url), var(--strike-army-gradient);
|
||||
}
|
@ -6,18 +6,17 @@
|
||||
font-size: var(--font-size);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border: none !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.back-button svg {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
background: none;
|
||||
color: var(--font-color);
|
||||
.back-button:hover:hover,
|
||||
.light .back-button:hover {
|
||||
text-decoration: underline;
|
||||
box-shadow: none !important;
|
||||
background: none !important;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { useState, useMemo, ChangeEvent } from "react";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { HexKey, TaggedNostrEvent } from "@snort/system";
|
||||
|
||||
import Note from "Element/Note";
|
||||
import Note from "Element/Event/Note";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { UserCache } from "Cache";
|
||||
|
||||
@ -16,7 +16,7 @@ interface BookmarksProps {
|
||||
|
||||
const Bookmarks = ({ pubkey, bookmarks, related }: BookmarksProps) => {
|
||||
const [onlyPubkey, setOnlyPubkey] = useState<HexKey | "all">("all");
|
||||
const loginPubKey = useLogin().publicKey;
|
||||
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
|
||||
const ps = useMemo(() => {
|
||||
return [...new Set(bookmarks.map(ev => ev.pubkey))];
|
||||
}, [bookmarks]);
|
||||
@ -28,7 +28,7 @@ const Bookmarks = ({ pubkey, bookmarks, related }: BookmarksProps) => {
|
||||
|
||||
return (
|
||||
<div className="main-content">
|
||||
<div className="mb10 flex-end">
|
||||
<div className="flex-end p">
|
||||
<select
|
||||
disabled={ps.length <= 1}
|
||||
value={onlyPubkey}
|
||||
@ -47,7 +47,7 @@ const Bookmarks = ({ pubkey, bookmarks, related }: BookmarksProps) => {
|
||||
key={n.id}
|
||||
data={n}
|
||||
related={related}
|
||||
options={{ showTime: false, showBookmarked: true, canUnbookmark: loginPubKey === pubkey }}
|
||||
options={{ showTime: false, showBookmarked: true, canUnbookmark: publicKey === pubkey }}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
@ -1,81 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
|
||||
interface Token {
|
||||
token: Array<{
|
||||
mint: string;
|
||||
proofs: Array<{
|
||||
amount: number;
|
||||
}>;
|
||||
}>;
|
||||
memo?: string;
|
||||
}
|
||||
|
||||
export default function CashuNuts({ token }: { token: string }) {
|
||||
const login = useLogin();
|
||||
const profile = useUserProfile(login.publicKey);
|
||||
|
||||
async function copyToken(e: React.MouseEvent<HTMLButtonElement>, token: string) {
|
||||
e.stopPropagation();
|
||||
await navigator.clipboard.writeText(token);
|
||||
}
|
||||
async function redeemToken(e: React.MouseEvent<HTMLButtonElement>, token: string) {
|
||||
e.stopPropagation();
|
||||
const lnurl = profile?.lud16 ?? "";
|
||||
const url = `https://redeem.cashu.me?token=${encodeURIComponent(token)}&lightning=${encodeURIComponent(
|
||||
lnurl
|
||||
)}&autopay=yes`;
|
||||
window.open(url, "_blank");
|
||||
}
|
||||
|
||||
const [cashu, setCashu] = useState<Token>();
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (!token.startsWith("cashuA") || token.length < 10) {
|
||||
return;
|
||||
}
|
||||
import("@cashu/cashu-ts").then(({ getDecodedToken }) => {
|
||||
const tkn = getDecodedToken(token);
|
||||
setCashu(tkn);
|
||||
});
|
||||
} catch {
|
||||
// ignored
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
if (!cashu) return <>{token}</>;
|
||||
|
||||
return (
|
||||
<div className="note-invoice">
|
||||
<div className="flex f-between">
|
||||
<div>
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Cashu token" />
|
||||
</h4>
|
||||
<p>
|
||||
<FormattedMessage
|
||||
defaultMessage="Amount: {amount} sats"
|
||||
values={{
|
||||
amount: cashu.token[0].proofs.reduce((acc, v) => acc + v.amount, 0),
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
<small className="xs">
|
||||
<FormattedMessage defaultMessage="Mint: {url}" values={{ url: cashu.token[0].mint }} />
|
||||
</small>
|
||||
</div>
|
||||
<div>
|
||||
<button onClick={e => copyToken(e, token)} className="mr5">
|
||||
<FormattedMessage defaultMessage="Copy" description="Button: Copy Cashu token" />
|
||||
</button>
|
||||
<button onClick={e => redeemToken(e, token)}>
|
||||
<FormattedMessage defaultMessage="Redeem" description="Button: Redeem Cashu token" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
12
packages/app/src/Element/Chat/ChatParticipant.tsx
Normal file
12
packages/app/src/Element/Chat/ChatParticipant.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
import { ChatParticipant } from "chat";
|
||||
import NoteToSelf from "../User/NoteToSelf";
|
||||
import ProfileImage from "../User/ProfileImage";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
|
||||
export function ChatParticipantProfile({ participant }: { participant: ChatParticipant }) {
|
||||
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
|
||||
if (participant.id === publicKey) {
|
||||
return <NoteToSelf className="f-grow" pubkey={participant.id} />;
|
||||
}
|
||||
return <ProfileImage pubkey={participant.id} className="f-grow" profile={participant.profile} />;
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
import "./DM.css";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useIntl } from "react-intl";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import NoteTime from "Element/NoteTime";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import NoteTime from "Element/Event/NoteTime";
|
||||
import Text from "Element/Text";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { Chat, ChatMessage, ChatType, setLastReadIn } from "chat";
|
||||
import ProfileImage from "../User/ProfileImage";
|
||||
|
||||
import messages from "./messages";
|
||||
import ProfileImage from "./ProfileImage";
|
||||
import messages from "../messages";
|
||||
|
||||
export interface DMProps {
|
||||
chat: Chat;
|
||||
@ -18,15 +18,14 @@ export interface DMProps {
|
||||
}
|
||||
|
||||
export default function DM(props: DMProps) {
|
||||
const pubKey = useLogin().publicKey;
|
||||
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
|
||||
const publisher = useEventPublisher();
|
||||
const msg = props.data;
|
||||
const [content, setContent] = useState(msg.needsDecryption ? "Loading..." : msg.content);
|
||||
const [decrypted, setDecrypted] = useState(false);
|
||||
const { ref, inView } = useInView();
|
||||
const [content, setContent] = useState<string>();
|
||||
const { ref, inView } = useInView({ triggerOnce: true });
|
||||
const { formatMessage } = useIntl();
|
||||
const isMe = msg.from === pubKey;
|
||||
const otherPubkey = isMe ? pubKey : msg.from;
|
||||
const isMe = msg.from === publicKey;
|
||||
const otherPubkey = isMe ? publicKey : msg.from;
|
||||
|
||||
async function decrypt() {
|
||||
if (publisher) {
|
||||
@ -46,17 +45,24 @@ export default function DM(props: DMProps) {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!decrypted && inView && msg.needsDecryption) {
|
||||
setDecrypted(true);
|
||||
decrypt().catch(console.error);
|
||||
if (inView) {
|
||||
if (msg.needsDecryption) {
|
||||
decrypt().catch(console.error);
|
||||
} else {
|
||||
setContent(msg.content);
|
||||
}
|
||||
}
|
||||
}, [inView, msg]);
|
||||
}, [inView]);
|
||||
|
||||
return (
|
||||
<div className={isMe ? "dm me" : "dm other"} ref={ref}>
|
||||
<div>
|
||||
{sender()}
|
||||
<Text content={content} tags={[]} creator={otherPubkey} />
|
||||
{content ? (
|
||||
<Text id={msg.id} content={content} tags={[]} creator={otherPubkey} />
|
||||
) : (
|
||||
<FormattedMessage defaultMessage="Loading..." />
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<NoteTime from={msg.created_at * 1000} fallback={formatMessage(messages.JustNow)} />
|
@ -1,35 +1,21 @@
|
||||
import "./DmWindow.css";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import DM from "Element/DM";
|
||||
import NoteToSelf from "Element/NoteToSelf";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import DM from "Element/Chat/DM";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import WriteMessage from "Element/WriteMessage";
|
||||
import { Chat, ChatParticipant, createEmptyChatObject, useChatSystem } from "chat";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import WriteMessage from "Element/Chat/WriteMessage";
|
||||
import { Chat, createEmptyChatObject, useChatSystem } from "chat";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { ChatParticipantProfile } from "./ChatParticipant";
|
||||
|
||||
export default function DmWindow({ id }: { id: string }) {
|
||||
const pubKey = useLogin().publicKey;
|
||||
const dms = useChatSystem();
|
||||
const chat = dms.find(a => a.id === id) ?? createEmptyChatObject(id);
|
||||
|
||||
function participant(p: ChatParticipant) {
|
||||
if (p.id === pubKey) {
|
||||
return <NoteToSelf className="f-grow mb-10" pubkey={p.id} />;
|
||||
}
|
||||
if (p.type === "pubkey") {
|
||||
return <ProfileImage pubkey={p.id} className="f-grow mb10" />;
|
||||
}
|
||||
if (p?.profile) {
|
||||
return <ProfileImage pubkey={p.id} className="f-grow mb10" profile={p.profile} />;
|
||||
}
|
||||
return <ProfileImage pubkey={p.id} className="f-grow mb10" overrideUsername={p.id} />;
|
||||
}
|
||||
|
||||
function sender() {
|
||||
if (chat.participants.length === 1) {
|
||||
return participant(chat.participants[0]);
|
||||
return <ChatParticipantProfile participant={chat.participants[0]} />;
|
||||
} else {
|
||||
return (
|
||||
<div className="flex pfp-overlap mb10">
|
||||
@ -56,7 +42,7 @@ export default function DmWindow({ id }: { id: string }) {
|
||||
}
|
||||
|
||||
function DmChatSelected({ chat }: { chat: Chat }) {
|
||||
const { publicKey: myPubKey } = useLogin();
|
||||
const { publicKey: myPubKey } = useLogin(s => ({ publicKey: s.publicKey }));
|
||||
const sortedDms = useMemo(() => {
|
||||
const myDms = chat?.messages;
|
||||
if (myPubKey && myDms) {
|
@ -1,11 +1,11 @@
|
||||
import { encodeTLV, NostrPrefix, NostrEvent } from "@snort/system";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { NostrPrefix, NostrEvent, NostrLink } from "@snort/system";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import Icon from "Icons/Icon";
|
||||
import Spinner from "Icons/Spinner";
|
||||
import { useState } from "react";
|
||||
import useFileUpload from "Upload";
|
||||
import { openFile } from "SnortUtils";
|
||||
import Textarea from "./Textarea";
|
||||
import Textarea from "../Textarea";
|
||||
import { System } from "index";
|
||||
import { Chat } from "chat";
|
||||
|
||||
@ -37,7 +37,7 @@ export default function WriteMessage({ chat }: { chat: Chat }) {
|
||||
if (file) {
|
||||
const rx = await uploader.upload(file, file.name);
|
||||
if (rx.header) {
|
||||
const link = `nostr:${encodeTLV(NostrPrefix.Event, rx.header.id, undefined, rx.header.kind)}`;
|
||||
const link = `nostr:${new NostrLink(NostrPrefix.Event, rx.header.id, rx.header.kind).encode()}`;
|
||||
setMsg(`${msg ? `${msg}\n` : ""}${link}`);
|
||||
setOtherEvents([...otherEvents, rx.header]);
|
||||
} else if (rx.url) {
|
@ -1,7 +1,7 @@
|
||||
import { useState, ReactNode } from "react";
|
||||
|
||||
import Icon from "Icons/Icon";
|
||||
import ShowMore from "Element/ShowMore";
|
||||
import ShowMore from "Element/Event/ShowMore";
|
||||
|
||||
interface CollapsedProps {
|
||||
text?: string;
|
||||
|
@ -1,14 +1,5 @@
|
||||
.copy {
|
||||
cursor: pointer;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.copy .body {
|
||||
.copy .copy-body {
|
||||
font-size: var(--font-size-small);
|
||||
color: var(--font-color);
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.copy .icon {
|
||||
margin-bottom: -4px;
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ export default function Copy({ text, maxSize = 32, className }: CopyProps) {
|
||||
const trimmed = text.length > maxSize ? `${text.slice(0, sliceLength)}...${text.slice(-sliceLength)}` : text;
|
||||
|
||||
return (
|
||||
<div className={`flex flex-row copy ${className}`} onClick={() => copy(text)}>
|
||||
<span className="body">{trimmed}</span>
|
||||
<div className={`copy flex pointer g8${className ? ` ${className}` : ""}`} onClick={() => copy(text)}>
|
||||
<span className="copy-body">{trimmed}</span>
|
||||
<span className="icon" style={{ color: copied ? "var(--success)" : "var(--highlight)" }}>
|
||||
{copied ? <Icon name="check" size={14} /> : <Icon name="copy-solid" size={14} />}
|
||||
</span>
|
||||
|
18
packages/app/src/Element/Deck/Articles.tsx
Normal file
18
packages/app/src/Element/Deck/Articles.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import { NostrLink } from "@snort/system";
|
||||
import { useArticles } from "Feed/ArticlesFeed";
|
||||
import { orderDescending } from "SnortUtils";
|
||||
import Note from "../Event/Note";
|
||||
import { useReactions } from "Feed/Reactions";
|
||||
|
||||
export default function Articles() {
|
||||
const data = useArticles();
|
||||
const related = useReactions("articles:reactions", data.data?.map(v => NostrLink.fromEvent(v)) ?? []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{orderDescending(data.data ?? []).map(a => (
|
||||
<Note data={a} key={a.id} related={related.data ?? []} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
12
packages/app/src/Element/Deck/Nav.css
Normal file
12
packages/app/src/Element/Deck/Nav.css
Normal file
@ -0,0 +1,12 @@
|
||||
nav.deck {
|
||||
width: 48px;
|
||||
height: calc(100vh - 20px);
|
||||
padding: 10px 8px;
|
||||
border-right: 1px solid var(--border-color);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
nav.deck .avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
41
packages/app/src/Element/Deck/Nav.tsx
Normal file
41
packages/app/src/Element/Deck/Nav.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import Avatar from "Element/User/Avatar";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import "./Nav.css";
|
||||
import Icon from "Icons/Icon";
|
||||
import { Link } from "react-router-dom";
|
||||
import { profileLink } from "SnortUtils";
|
||||
|
||||
export function DeckNav() {
|
||||
const { publicKey } = useLogin();
|
||||
const profile = useUserProfile(publicKey);
|
||||
|
||||
const unreadDms = 0;
|
||||
const hasNotifications = false;
|
||||
|
||||
return (
|
||||
<nav className="deck flex-column f-space">
|
||||
<div className="flex-column f-center g24">
|
||||
<Link className="btn" to="/messages">
|
||||
<Icon name="mail" size={24} />
|
||||
{unreadDms > 0 && <span className="has-unread"></span>}
|
||||
</Link>
|
||||
<Link className="btn" to="/notifications">
|
||||
<Icon name="bell-02" size={24} />
|
||||
{hasNotifications && <span className="has-unread"></span>}
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex-column f-center g16">
|
||||
<Link className="btn" to="/">
|
||||
<Icon name="grid-01" size={24} />
|
||||
</Link>
|
||||
<Link className="btn" to="/settings">
|
||||
<Icon name="settings-02" size={24} />
|
||||
</Link>
|
||||
<Link to={profileLink(publicKey ?? "")}>
|
||||
<Avatar pubkey={publicKey ?? ""} user={profile} />
|
||||
</Link>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
@ -10,15 +10,15 @@
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.modal.spotlight img,
|
||||
.modal.spotlight video {
|
||||
.spotlight img,
|
||||
.spotlight video {
|
||||
max-width: 100vw;
|
||||
max-height: 100vh;
|
||||
max-height: 99vh;
|
||||
aspect-ratio: unset;
|
||||
width: unset;
|
||||
}
|
||||
|
||||
.modal.spotlight .details {
|
||||
.spotlight .details {
|
||||
text-align: right;
|
||||
position: absolute;
|
||||
top: 28px;
|
||||
@ -29,16 +29,17 @@
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
align-items: center;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.modal.spotlight .left {
|
||||
.spotlight .left {
|
||||
position: absolute;
|
||||
left: 24px;
|
||||
top: 50vh;
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.modal.spotlight .right {
|
||||
.spotlight .right {
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
top: 50vh;
|
@ -37,7 +37,7 @@ export function SpotlightMedia(props: SpotlightMediaProps) {
|
||||
});
|
||||
}
|
||||
return (
|
||||
<Modal onClose={props.onClose} className="spotlight">
|
||||
<div className="spotlight">
|
||||
<ProxyImg src={image} />
|
||||
<div className="details">
|
||||
{idx + 1}/{props.images.length}
|
||||
@ -49,6 +49,14 @@ export function SpotlightMedia(props: SpotlightMediaProps) {
|
||||
<Icon className="right" name="arrowFront" size={24} onClick={() => inc()} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SpotlightMediaModal(props: SpotlightMediaProps) {
|
||||
return (
|
||||
<Modal id="spotlight" onClose={props.onClose} className="spotlight">
|
||||
<SpotlightMedia {...props} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
8
packages/app/src/Element/Embed/CashuNuts.css
Normal file
8
packages/app/src/Element/Embed/CashuNuts.css
Normal file
@ -0,0 +1,8 @@
|
||||
.cashu {
|
||||
background: var(--cashu-gradient);
|
||||
}
|
||||
|
||||
.cashu h1 {
|
||||
font-size: 44px;
|
||||
line-height: 1em;
|
||||
}
|
137
packages/app/src/Element/Embed/CashuNuts.tsx
Normal file
137
packages/app/src/Element/Embed/CashuNuts.tsx
Normal file
@ -0,0 +1,137 @@
|
||||
import "./CashuNuts.css";
|
||||
import { useEffect, useState } from "react";
|
||||
import { FormattedMessage, FormattedNumber } from "react-intl";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import Icon from "Icons/Icon";
|
||||
|
||||
interface Token {
|
||||
token: Array<{
|
||||
mint: string;
|
||||
proofs: Array<{
|
||||
amount: number;
|
||||
}>;
|
||||
}>;
|
||||
memo?: string;
|
||||
}
|
||||
|
||||
export default function CashuNuts({ token }: { token: string }) {
|
||||
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
|
||||
const profile = useUserProfile(publicKey);
|
||||
|
||||
async function copyToken(e: React.MouseEvent<HTMLButtonElement>, token: string) {
|
||||
e.stopPropagation();
|
||||
await navigator.clipboard.writeText(token);
|
||||
}
|
||||
async function redeemToken(e: React.MouseEvent<HTMLButtonElement>, token: string) {
|
||||
e.stopPropagation();
|
||||
const lnurl = profile?.lud16 ?? "";
|
||||
const url = `https://redeem.cashu.me?token=${encodeURIComponent(token)}&lightning=${encodeURIComponent(
|
||||
lnurl,
|
||||
)}&autopay=yes`;
|
||||
window.open(url, "_blank");
|
||||
}
|
||||
|
||||
const [cashu, setCashu] = useState<Token>();
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (!token.startsWith("cashuA") || token.length < 10) {
|
||||
return;
|
||||
}
|
||||
import("@cashu/cashu-ts").then(({ getDecodedToken }) => {
|
||||
const tkn = getDecodedToken(token);
|
||||
setCashu(tkn);
|
||||
});
|
||||
} catch {
|
||||
// ignored
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
if (!cashu) return <>{token}</>;
|
||||
|
||||
const amount = cashu.token[0].proofs.reduce((acc, v) => acc + v.amount, 0);
|
||||
return (
|
||||
<div className="cashu flex f-space p24 br">
|
||||
<div className="flex-column g8 f-ellipsis">
|
||||
<div className="flex f-center g16">
|
||||
<svg width="30" height="39" viewBox="0 0 30 39" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="Group 47711">
|
||||
<path
|
||||
id="Rectangle 585"
|
||||
d="M29.3809 2.47055L29.3809 11.7277L26.7913 11.021C23.8493 10.2181 20.727 10.3835 17.8863 11.4929C15.5024 12.4238 12.9113 12.6933 10.3869 12.2728L7.11501 11.7277L7.11501 2.47054L10.3869 3.01557C12.9113 3.43607 15.5024 3.1666 17.8863 2.23566C20.727 1.12632 23.8493 0.960876 26.7913 1.7638L29.3809 2.47055Z"
|
||||
fill="url(#paint0_linear_1976_19241)"
|
||||
/>
|
||||
<path
|
||||
id="Rectangle 587"
|
||||
d="M29.3809 27.9803L29.3809 37.2375L26.7913 36.5308C23.8493 35.7278 20.727 35.8933 17.8863 37.0026C15.5024 37.9336 12.9113 38.203 10.3869 37.7825L7.11501 37.2375L7.11501 27.9803L10.3869 28.5253C12.9113 28.9458 15.5024 28.6764 17.8863 27.7454C20.727 26.6361 23.8493 26.4706 26.7913 27.2736L29.3809 27.9803Z"
|
||||
fill="url(#paint1_linear_1976_19241)"
|
||||
/>
|
||||
<path
|
||||
id="Rectangle 586"
|
||||
d="M8.494e-08 15.2069L4.89585e-07 24.4641L2.5896 23.7573C5.53159 22.9544 8.6539 23.1198 11.4946 24.2292C13.8784 25.1601 16.4695 25.4296 18.9939 25.0091L22.2658 24.4641L22.2658 15.2069L18.9939 15.7519C16.4695 16.1724 13.8784 15.9029 11.4946 14.972C8.6539 13.8627 5.53159 13.6972 2.5896 14.5001L8.494e-08 15.2069Z"
|
||||
fill="url(#paint2_linear_1976_19241)"
|
||||
/>
|
||||
</g>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="paint0_linear_1976_19241"
|
||||
x1="29.3809"
|
||||
y1="6.7213"
|
||||
x2="7.11501"
|
||||
y2="6.7213"
|
||||
gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="paint1_linear_1976_19241"
|
||||
x1="29.3809"
|
||||
y1="32.2311"
|
||||
x2="7.11501"
|
||||
y2="32.2311"
|
||||
gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id="paint2_linear_1976_19241"
|
||||
x1="2.70746e-07"
|
||||
y1="19.4576"
|
||||
x2="22.2658"
|
||||
y2="19.4576"
|
||||
gradientUnits="userSpaceOnUse">
|
||||
<stop stopColor="white" />
|
||||
<stop offset="1" stopColor="white" stopOpacity="0.5" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
<FormattedMessage
|
||||
defaultMessage="<h1>{n}</h1> Cashu sats"
|
||||
values={{
|
||||
h1: c => <h1>{c}</h1>,
|
||||
n: <FormattedNumber value={amount} />,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<small className="xs w-max">
|
||||
<FormattedMessage
|
||||
defaultMessage="<b>Mint:</b> {url}"
|
||||
values={{
|
||||
b: c => <b>{c}</b>,
|
||||
url: new URL(cashu.token[0].mint).hostname,
|
||||
}}
|
||||
/>
|
||||
</small>
|
||||
</div>
|
||||
<div className="flex g8">
|
||||
<button onClick={e => copyToken(e, token)}>
|
||||
<Icon name="copy" />
|
||||
</button>
|
||||
<button onClick={e => redeemToken(e, token)}>
|
||||
<FormattedMessage defaultMessage="Redeem" description="Button: Redeem Cashu token" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -8,6 +8,12 @@
|
||||
background: var(--invoice-gradient);
|
||||
}
|
||||
|
||||
.note-invoice.error {
|
||||
padding: 8px 12px !important;
|
||||
color: #aaa;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.note-invoice.expired {
|
||||
background: var(--expired-invoice-gradient);
|
||||
color: var(--font-secondary-color);
|
@ -8,7 +8,7 @@ import SendSats from "Element/SendSats";
|
||||
import Icon from "Icons/Icon";
|
||||
import { useWallet } from "Wallet";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
export interface InvoiceProps {
|
||||
invoice: string;
|
||||
@ -75,7 +75,7 @@ export default function Invoice(props: InvoiceProps) {
|
||||
{description && <p>{description}</p>}
|
||||
{isPaid ? (
|
||||
<div className="paid">
|
||||
<FormattedMessage {...messages.Paid} />
|
||||
<FormattedMessage defaultMessage="Paid" />
|
||||
</div>
|
||||
) : (
|
||||
<button disabled={isExpired} type="button" onClick={payInvoice}>
|
@ -40,12 +40,23 @@
|
||||
margin: 0 0 15px 0 !important;
|
||||
border-radius: 0 !important;
|
||||
background-image: var(--img-url);
|
||||
min-height: 250px;
|
||||
min-height: 220px;
|
||||
max-height: 500px;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
|
||||
.light .link-preview-container {
|
||||
background: #ddd;
|
||||
background: #fff;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.light .link-preview-container:hover {
|
||||
box-shadow: rgba(0, 0, 0, 0.08) 0 1px 3px;
|
||||
}
|
||||
|
||||
@media (min-width: 1025px) {
|
||||
.link-preview-image {
|
||||
min-height: 342px;
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import { CSSProperties, useEffect, useState } from "react";
|
||||
import Spinner from "Icons/Spinner";
|
||||
import SnortApi, { LinkPreviewData } from "SnortApi";
|
||||
import useImgProxy from "Hooks/useImgProxy";
|
||||
import { MediaElement } from "Element/MediaElement";
|
||||
import { MediaElement } from "Element/Embed/MediaElement";
|
||||
|
||||
async function fetchUrlPreviewInfo(url: string) {
|
||||
const api = new SnortApi();
|
@ -1,4 +1,4 @@
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
|
||||
import { Magnet } from "SnortUtils";
|
||||
|
@ -4,7 +4,7 @@ import { HexKey } from "@snort/system";
|
||||
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import { profileLink } from "SnortUtils";
|
||||
import { getDisplayName } from "Element/ProfileImage";
|
||||
import { getDisplayName } from "Element/User/ProfileImage";
|
||||
|
||||
export default function Mention({ pubkey, relays }: { pubkey: HexKey; relays?: Array<string> | string }) {
|
||||
const user = useUserProfile(pubkey);
|
@ -4,8 +4,8 @@ import useLogin from "Hooks/useLogin";
|
||||
const MixCloudEmbed = ({ link }: { link: string }) => {
|
||||
const feedPath = (MixCloudRegex.test(link) && RegExp.$1) + "%2F" + (MixCloudRegex.test(link) && RegExp.$2);
|
||||
|
||||
const lightTheme = useLogin().preferences.theme === "light";
|
||||
const lightParams = lightTheme ? "light=1" : "light=0";
|
||||
const { theme } = useLogin(s => ({ theme: s.preferences.theme }));
|
||||
const lightParams = theme === "light" ? "light=1" : "light=0";
|
||||
return (
|
||||
<>
|
||||
<br />
|
@ -1,8 +1,8 @@
|
||||
import { Link } from "react-router-dom";
|
||||
import { NostrPrefix, tryParseNostrLink } from "@snort/system";
|
||||
|
||||
import Mention from "Element/Mention";
|
||||
import NoteQuote from "Element/NoteQuote";
|
||||
import Mention from "Element/Embed/Mention";
|
||||
import NoteQuote from "Element/Event/NoteQuote";
|
||||
|
||||
export default function NostrLink({ link, depth }: { link: string; depth?: number }) {
|
||||
const nav = tryParseNostrLink(link);
|
@ -3,14 +3,14 @@ import { FormattedMessage, FormattedNumber } from "react-intl";
|
||||
import { LNURL } from "@snort/shared";
|
||||
|
||||
import { dedupe, hexToBech32 } from "SnortUtils";
|
||||
import FollowListBase from "Element/FollowListBase";
|
||||
import FollowListBase from "Element/User/FollowListBase";
|
||||
import AsyncButton from "Element/AsyncButton";
|
||||
import { useWallet } from "Wallet";
|
||||
import { Toastore } from "Toaster";
|
||||
import { getDisplayName } from "Element/ProfileImage";
|
||||
import { getDisplayName } from "Element/User/ProfileImage";
|
||||
import { UserCache } from "Cache";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { WalletInvoiceState } from "Wallet";
|
||||
|
||||
export default function PubkeyList({ ev, className }: { ev: NostrEvent; className?: string }) {
|
||||
@ -34,7 +34,7 @@ export default function PubkeyList({ ev, className }: { ev: NostrEvent; classNam
|
||||
pk,
|
||||
Object.keys(login.relays.item),
|
||||
undefined,
|
||||
`Zap from ${hexToBech32("note", ev.id)}`
|
||||
`Zap from ${hexToBech32("note", ev.id)}`,
|
||||
);
|
||||
const invoice = await svc.getInvoice(amtSend, undefined, zap);
|
||||
if (invoice.pr) {
|
@ -1,10 +1,10 @@
|
||||
import "./ZapstrEmbed.css";
|
||||
import { Link } from "react-router-dom";
|
||||
import { encodeTLV, NostrPrefix, NostrEvent } from "@snort/system";
|
||||
import { NostrEvent, NostrLink } from "@snort/system";
|
||||
|
||||
import { ProxyImg } from "Element/ProxyImg";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
|
||||
export default function ZapstrEmbed({ ev }: { ev: NostrEvent }) {
|
||||
const media = ev.tags.find(a => a[0] === "media");
|
||||
@ -12,13 +12,7 @@ export default function ZapstrEmbed({ ev }: { ev: NostrEvent }) {
|
||||
const subject = ev.tags.find(a => a[0] === "subject");
|
||||
const refPersons = ev.tags.filter(a => a[0] === "p");
|
||||
|
||||
const link = encodeTLV(
|
||||
NostrPrefix.Address,
|
||||
ev.tags.find(a => a[0] === "d")?.[1] ?? "",
|
||||
undefined,
|
||||
ev.kind,
|
||||
ev.pubkey
|
||||
);
|
||||
const link = NostrLink.fromEvent(ev).encode();
|
||||
return (
|
||||
<>
|
||||
<div className="flex zapstr mb10 card">
|
@ -1,11 +1,11 @@
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { NostrEvent, NostrLink } from "@snort/system";
|
||||
|
||||
import { findTag } from "SnortUtils";
|
||||
import useEventFeed from "Feed/EventFeed";
|
||||
import { useEventFeed } from "Feed/EventFeed";
|
||||
import PageSpinner from "Element/PageSpinner";
|
||||
import Reveal from "Element/Reveal";
|
||||
import { MediaElement } from "Element/MediaElement";
|
||||
import Reveal from "Element/Event/Reveal";
|
||||
import { MediaElement } from "Element/Embed/MediaElement";
|
||||
|
||||
export default function NostrFileHeader({ link }: { link: NostrLink }) {
|
||||
const ev = useEventFeed(link);
|
@ -2,7 +2,7 @@
|
||||
min-height: 110px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.note:hover {
|
||||
@ -65,6 +65,7 @@
|
||||
border: 1px solid var(--gray-superdark);
|
||||
border-radius: 12px;
|
||||
padding: 8px 16px 16px 16px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.note .footer .footer-reactions {
|
||||
@ -163,10 +164,6 @@
|
||||
min-height: unset;
|
||||
}
|
||||
|
||||
.hidden-note button {
|
||||
max-height: 30px;
|
||||
}
|
||||
|
||||
.expand-note {
|
||||
padding: 0 0 16px 0;
|
||||
font-weight: 400;
|
@ -3,15 +3,14 @@ import React, { useMemo, useState, ReactNode } from "react";
|
||||
import { useNavigate, Link } from "react-router-dom";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
import { useIntl, FormattedMessage } from "react-intl";
|
||||
import { TaggedNostrEvent, HexKey, EventKind, NostrPrefix, Lists, EventExt, parseZap } from "@snort/system";
|
||||
import { TaggedNostrEvent, HexKey, EventKind, NostrPrefix, Lists, EventExt, parseZap, NostrLink } from "@snort/system";
|
||||
|
||||
import { System } from "index";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import Icon from "Icons/Icon";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import Text from "Element/Text";
|
||||
import {
|
||||
eventLink,
|
||||
getReactions,
|
||||
dedupeByPubkey,
|
||||
tagFilterOfTextRepost,
|
||||
@ -21,23 +20,26 @@ import {
|
||||
profileLink,
|
||||
findTag,
|
||||
} from "SnortUtils";
|
||||
import NoteFooter from "Element/NoteFooter";
|
||||
import NoteTime from "Element/NoteTime";
|
||||
import Reveal from "Element/Reveal";
|
||||
import NoteFooter from "Element/Event/NoteFooter";
|
||||
import NoteTime from "Element/Event/NoteTime";
|
||||
import Reveal from "Element/Event/Reveal";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import { UserCache } from "Cache";
|
||||
import Poll from "Element/Poll";
|
||||
import Poll from "Element/Event/Poll";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { setBookmarked, setPinned } from "Login";
|
||||
import { NostrFileElement } from "Element/NostrFileHeader";
|
||||
import ZapstrEmbed from "Element/ZapstrEmbed";
|
||||
import PubkeyList from "Element/PubkeyList";
|
||||
import { NostrFileElement } from "Element/Event/NostrFileHeader";
|
||||
import ZapstrEmbed from "Element/Embed/ZapstrEmbed";
|
||||
import PubkeyList from "Element/Embed/PubkeyList";
|
||||
import { LiveEvent } from "Element/LiveEvent";
|
||||
import { NoteContextMenu, NoteTranslation } from "Element/NoteContextMenu";
|
||||
import Reactions from "Element/Reactions";
|
||||
import { ZapGoal } from "Element/ZapGoal";
|
||||
import { NoteContextMenu, NoteTranslation } from "Element/Event/NoteContextMenu";
|
||||
import Reactions from "Element/Event/Reactions";
|
||||
import { ZapGoal } from "Element/Event/ZapGoal";
|
||||
import NoteReaction from "Element/Event/NoteReaction";
|
||||
import ProfilePreview from "Element/User/ProfilePreview";
|
||||
import { ProxyImg } from "Element/ProxyImg";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
export interface NoteProps {
|
||||
data: TaggedNostrEvent;
|
||||
@ -60,20 +62,21 @@ export interface NoteProps {
|
||||
canUnpin?: boolean;
|
||||
canUnbookmark?: boolean;
|
||||
canClick?: boolean;
|
||||
showMediaSpotlight?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
const HiddenNote = ({ children }: { children: React.ReactNode }) => {
|
||||
const [show, setShow] = useState(false);
|
||||
return show ? (
|
||||
<>{children}</>
|
||||
children
|
||||
) : (
|
||||
<div className="card note hidden-note">
|
||||
<div className="header">
|
||||
<p>
|
||||
<FormattedMessage {...messages.MutedAuthor} />
|
||||
<FormattedMessage defaultMessage="This note has been muted" />
|
||||
</p>
|
||||
<button onClick={() => setShow(true)}>
|
||||
<button type="button" onClick={() => setShow(true)}>
|
||||
<FormattedMessage {...messages.Show} />
|
||||
</button>
|
||||
</div>
|
||||
@ -82,8 +85,10 @@ const HiddenNote = ({ children }: { children: React.ReactNode }) => {
|
||||
};
|
||||
|
||||
export default function Note(props: NoteProps) {
|
||||
const { data: ev, related, highlight, options: opt, ignoreModeration = false, className } = props;
|
||||
|
||||
const { data: ev, className } = props;
|
||||
if (ev.kind === EventKind.Repost) {
|
||||
return <NoteReaction data={ev} key={ev.id} root={undefined} depth={(props.depth ?? 0) + 1} />;
|
||||
}
|
||||
if (ev.kind === EventKind.FileHeader) {
|
||||
return <NostrFileElement ev={ev} />;
|
||||
}
|
||||
@ -96,16 +101,24 @@ export default function Note(props: NoteProps) {
|
||||
if (ev.kind === EventKind.LiveEvent) {
|
||||
return <LiveEvent ev={ev} />;
|
||||
}
|
||||
if (ev.kind === EventKind.SetMetadata) {
|
||||
return <ProfilePreview actions={<></>} pubkey={ev.pubkey} className="card" />;
|
||||
}
|
||||
if (ev.kind === (9041 as EventKind)) {
|
||||
return <ZapGoal ev={ev} />;
|
||||
}
|
||||
|
||||
return <NoteInner {...props} />;
|
||||
}
|
||||
|
||||
export function NoteInner(props: NoteProps) {
|
||||
const { data: ev, related, highlight, options: opt, ignoreModeration = false, className } = props;
|
||||
|
||||
const baseClassName = `note card${className ? ` ${className}` : ""}`;
|
||||
const navigate = useNavigate();
|
||||
const [showReactions, setShowReactions] = useState(false);
|
||||
const deletions = useMemo(() => getReactions(related, ev.id, EventKind.Deletion), [related]);
|
||||
const { isMuted } = useModeration();
|
||||
const isOpMuted = isMuted(ev?.pubkey);
|
||||
const { isEventMuted } = useModeration();
|
||||
const { ref, inView } = useInView({ triggerOnce: true });
|
||||
const login = useLogin();
|
||||
const { pinned, bookmarked } = login;
|
||||
@ -123,7 +136,7 @@ export default function Note(props: NoteProps) {
|
||||
{
|
||||
[Reaction.Positive]: [] as TaggedNostrEvent[],
|
||||
[Reaction.Negative]: [] as TaggedNostrEvent[],
|
||||
}
|
||||
},
|
||||
);
|
||||
return {
|
||||
[Reaction.Positive]: dedupeByPubkey(result[Reaction.Positive]),
|
||||
@ -138,7 +151,7 @@ export default function Note(props: NoteProps) {
|
||||
...getReactions(related, ev.id, EventKind.TextNote).filter(e => e.tags.some(tagFilterOfTextRepost(e, ev.id))),
|
||||
...getReactions(related, ev.id, EventKind.Repost),
|
||||
]),
|
||||
[related, ev]
|
||||
[related, ev],
|
||||
);
|
||||
const zaps = useMemo(() => {
|
||||
const sortedZaps = getReactions(related, ev.id, EventKind.ZapReceipt)
|
||||
@ -181,8 +194,49 @@ export default function Note(props: NoteProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const innerContent = () => {
|
||||
if (ev.kind === EventKind.LongFormTextNote) {
|
||||
const title = findTag(ev, "title");
|
||||
const summary = findTag(ev, "simmary");
|
||||
const image = findTag(ev, "image");
|
||||
return (
|
||||
<div className="long-form-note">
|
||||
<h3>{title}</h3>
|
||||
<div className="text">
|
||||
<p>{summary}</p>
|
||||
<Text
|
||||
id={ev.id}
|
||||
content={ev.content}
|
||||
highlighText={props.searchedValue}
|
||||
tags={ev.tags}
|
||||
creator={ev.pubkey}
|
||||
depth={props.depth}
|
||||
truncate={255}
|
||||
disableLinkPreview={true}
|
||||
disableMediaSpotlight={!(props.options?.showMediaSpotlight ?? true)}
|
||||
/>
|
||||
{image && <ProxyImg src={image} />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
const body = ev?.content ?? "";
|
||||
return (
|
||||
<Text
|
||||
id={ev.id}
|
||||
highlighText={props.searchedValue}
|
||||
content={body}
|
||||
tags={ev.tags}
|
||||
creator={ev.pubkey}
|
||||
depth={props.depth}
|
||||
disableMedia={!(options.showMedia ?? true)}
|
||||
disableMediaSpotlight={!(props.options?.showMediaSpotlight ?? true)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const transformBody = () => {
|
||||
const body = ev?.content ?? "";
|
||||
if (deletions?.length > 0) {
|
||||
return (
|
||||
<b className="error">
|
||||
@ -196,40 +250,39 @@ export default function Note(props: NoteProps) {
|
||||
<Reveal
|
||||
message={
|
||||
<>
|
||||
<FormattedMessage defaultMessage="This note has been marked as sensitive, click here to reveal" />
|
||||
<FormattedMessage
|
||||
defaultMessage="The author has marked this note as a <i>sensitive topic</i>"
|
||||
values={{
|
||||
i: c => <i>{c}</i>,
|
||||
}}
|
||||
/>
|
||||
{contentWarning[1] && (
|
||||
<>
|
||||
<br />
|
||||
|
||||
<FormattedMessage
|
||||
defaultMessage="Reason: {reason}"
|
||||
defaultMessage="Reason: <i>{reason}</i>"
|
||||
values={{
|
||||
i: c => <i>{c}</i>,
|
||||
reason: contentWarning[1],
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
<FormattedMessage defaultMessage="Click here to load anyway" />
|
||||
</>
|
||||
}>
|
||||
<Text highlighText={props.searchedValue} content={body} tags={ev.tags} creator={ev.pubkey} />
|
||||
{innerContent()}
|
||||
</Reveal>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Text
|
||||
highlighText={props.searchedValue}
|
||||
content={body}
|
||||
tags={ev.tags}
|
||||
creator={ev.pubkey}
|
||||
depth={props.depth}
|
||||
disableMedia={!(options.showMedia ?? true)}
|
||||
/>
|
||||
);
|
||||
return innerContent();
|
||||
};
|
||||
|
||||
function goToEvent(
|
||||
e: React.MouseEvent,
|
||||
eTarget: TaggedNostrEvent,
|
||||
isTargetAllowed: boolean = e.target === e.currentTarget
|
||||
isTargetAllowed: boolean = e.target === e.currentTarget,
|
||||
) {
|
||||
if (!isTargetAllowed || opt?.canClick === false) {
|
||||
return;
|
||||
@ -241,13 +294,13 @@ export default function Note(props: NoteProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
const link = eventLink(eTarget.id, eTarget.relays);
|
||||
const link = NostrLink.fromEvent(eTarget);
|
||||
// detect cmd key and open in new tab
|
||||
if (e.metaKey) {
|
||||
window.open(link, "_blank");
|
||||
window.open(`/e/${link.encode()}`, "_blank");
|
||||
} else {
|
||||
navigate(link, {
|
||||
state: ev,
|
||||
navigate(`/e/${link.encode()}`, {
|
||||
state: eTarget,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -259,8 +312,12 @@ export default function Note(props: NoteProps) {
|
||||
}
|
||||
|
||||
const maxMentions = 2;
|
||||
const replyId = thread?.replyTo?.value ?? thread?.root?.value;
|
||||
const replyRelayHints = thread?.replyTo?.relay ?? thread.root?.relay;
|
||||
const replyTo = thread?.replyTo ?? thread?.root;
|
||||
const replyLink = replyTo
|
||||
? NostrLink.fromTag(
|
||||
[replyTo.key, replyTo.value ?? "", replyTo.relay ?? "", replyTo.marker ?? ""].filter(a => a.length > 0),
|
||||
)
|
||||
: undefined;
|
||||
const mentions: { pk: string; name: string; link: ReactNode }[] = [];
|
||||
for (const pk of thread?.pubKeys ?? []) {
|
||||
const u = UserCache.getFromCache(pk);
|
||||
@ -293,23 +350,19 @@ export default function Note(props: NoteProps) {
|
||||
{pubMentions} {others}
|
||||
</>
|
||||
) : (
|
||||
replyId && (
|
||||
<Link to={eventLink(replyId, replyRelayHints)}>
|
||||
{hexToBech32(NostrPrefix.Event, replyId)?.substring(0, 12)}
|
||||
</Link>
|
||||
)
|
||||
replyLink && <Link to={`/e/${replyLink.encode()}`}>{replyLink.encode().substring(0, 12)}</Link>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const canRenderAsTextNote = [EventKind.TextNote, EventKind.Polls];
|
||||
const canRenderAsTextNote = [EventKind.TextNote, EventKind.Polls, EventKind.LongFormTextNote];
|
||||
if (!canRenderAsTextNote.includes(ev.kind)) {
|
||||
const alt = findTag(ev, "alt");
|
||||
if (alt) {
|
||||
return (
|
||||
<div className="note-quote">
|
||||
<Text content={alt} tags={[]} creator={ev.pubkey} />
|
||||
<Text id={ev.id} content={alt} tags={[]} creator={ev.pubkey} />
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
@ -418,5 +471,5 @@ export default function Note(props: NoteProps) {
|
||||
</div>
|
||||
);
|
||||
|
||||
return !ignoreModeration && isOpMuted ? <HiddenNote>{note}</HiddenNote> : note;
|
||||
return !ignoreModeration && isEventMuted(ev) ? <HiddenNote>{note}</HiddenNote> : note;
|
||||
}
|
@ -1,23 +1,17 @@
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { HexKey, Lists, NostrPrefix, TaggedNostrEvent, encodeTLV } from "@snort/system";
|
||||
import { HexKey, Lists, NostrLink, TaggedNostrEvent } from "@snort/system";
|
||||
import { Menu, MenuItem } from "@szhsin/react-menu";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import { TranslateHost } from "Const";
|
||||
import { System } from "index";
|
||||
import Icon from "Icons/Icon";
|
||||
import { setPinned, setBookmarked } from "Login";
|
||||
import {
|
||||
setNote as setReBroadcastNote,
|
||||
setShow as setReBroadcastShow,
|
||||
reset as resetReBroadcast,
|
||||
} from "State/ReBroadcast";
|
||||
import messages from "Element/messages";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { RootState } from "State/Store";
|
||||
import { ReBroadcaster } from "./ReBroadcaster";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { ReBroadcaster } from "../ReBroadcaster";
|
||||
import { useState } from "react";
|
||||
|
||||
export interface NoteTranslation {
|
||||
text: string;
|
||||
@ -33,20 +27,16 @@ interface NosteContextMenuProps {
|
||||
}
|
||||
|
||||
export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
const dispatch = useDispatch();
|
||||
const { formatMessage } = useIntl();
|
||||
const login = useLogin();
|
||||
const { pinned, bookmarked, publicKey, preferences: prefs } = login;
|
||||
const { mute, block } = useModeration();
|
||||
const publisher = useEventPublisher();
|
||||
const showReBroadcastModal = useSelector((s: RootState) => s.reBroadcast.show);
|
||||
const reBroadcastNote = useSelector((s: RootState) => s.reBroadcast.note);
|
||||
const willRenderReBroadcast = showReBroadcastModal && reBroadcastNote && reBroadcastNote?.id === ev.id;
|
||||
const [showBroadcast, setShowBroadcast] = useState(false);
|
||||
const lang = window.navigator.language;
|
||||
const langNames = new Intl.DisplayNames([...window.navigator.languages], {
|
||||
type: "language",
|
||||
});
|
||||
const isMine = ev.pubkey === publicKey;
|
||||
const isMine = ev.pubkey === login.publicKey;
|
||||
|
||||
async function deleteEvent() {
|
||||
if (window.confirm(formatMessage(messages.ConfirmDeletion, { id: ev.id.substring(0, 8) })) && publisher) {
|
||||
@ -56,7 +46,7 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
}
|
||||
|
||||
async function share() {
|
||||
const link = encodeTLV(NostrPrefix.Event, ev.id, ev.relays);
|
||||
const link = NostrLink.fromEvent(ev).encode();
|
||||
const url = `${window.location.protocol}//${window.location.host}/e/${link}`;
|
||||
if ("share" in window.navigator) {
|
||||
await window.navigator.share({
|
||||
@ -92,13 +82,13 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
}
|
||||
|
||||
async function copyId() {
|
||||
const link = encodeTLV(NostrPrefix.Event, ev.id, ev.relays);
|
||||
const link = NostrLink.fromEvent(ev).encode();
|
||||
await navigator.clipboard.writeText(link);
|
||||
}
|
||||
|
||||
async function pin(id: HexKey) {
|
||||
if (publisher) {
|
||||
const es = [...pinned.item, id];
|
||||
const es = [...login.pinned.item, id];
|
||||
const ev = await publisher.noteList(es, Lists.Pinned);
|
||||
System.BroadcastEvent(ev);
|
||||
setPinned(login, es, ev.created_at * 1000);
|
||||
@ -107,7 +97,7 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
|
||||
async function bookmark(id: HexKey) {
|
||||
if (publisher) {
|
||||
const es = [...bookmarked.item, id];
|
||||
const es = [...login.bookmarked.item, id];
|
||||
const ev = await publisher.noteList(es, Lists.Bookmarked);
|
||||
System.BroadcastEvent(ev);
|
||||
setBookmarked(login, es, ev.created_at * 1000);
|
||||
@ -119,12 +109,7 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
}
|
||||
|
||||
const handleReBroadcastButtonClick = () => {
|
||||
if (reBroadcastNote?.id !== ev.id) {
|
||||
dispatch(resetReBroadcast());
|
||||
}
|
||||
|
||||
dispatch(setReBroadcastNote(ev));
|
||||
dispatch(setReBroadcastShow(!showReBroadcastModal));
|
||||
setShowBroadcast(true);
|
||||
};
|
||||
|
||||
function menuItems() {
|
||||
@ -145,13 +130,13 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
<Icon name="share" />
|
||||
<FormattedMessage {...messages.Share} />
|
||||
</MenuItem>
|
||||
{!pinned.item.includes(ev.id) && (
|
||||
{!login.pinned.item.includes(ev.id) && !login.readonly && (
|
||||
<MenuItem onClick={() => pin(ev.id)}>
|
||||
<Icon name="pin" />
|
||||
<FormattedMessage {...messages.Pin} />
|
||||
</MenuItem>
|
||||
)}
|
||||
{!bookmarked.item.includes(ev.id) && (
|
||||
{!login.bookmarked.item.includes(ev.id) && !login.readonly && (
|
||||
<MenuItem onClick={() => bookmark(ev.id)}>
|
||||
<Icon name="bookmark" />
|
||||
<FormattedMessage {...messages.Bookmark} />
|
||||
@ -161,23 +146,23 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
<Icon name="copy" />
|
||||
<FormattedMessage {...messages.CopyID} />
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => mute(ev.pubkey)}>
|
||||
<Icon name="mute" />
|
||||
<FormattedMessage {...messages.Mute} />
|
||||
</MenuItem>
|
||||
{prefs.enableReactions && (
|
||||
{!login.readonly && (
|
||||
<MenuItem onClick={() => mute(ev.pubkey)}>
|
||||
<Icon name="mute" />
|
||||
<FormattedMessage {...messages.Mute} />
|
||||
</MenuItem>
|
||||
)}
|
||||
{login.preferences.enableReactions && !login.readonly && (
|
||||
<MenuItem onClick={() => props.react("-")}>
|
||||
<Icon name="dislike" />
|
||||
<FormattedMessage {...messages.DislikeAction} />
|
||||
</MenuItem>
|
||||
)}
|
||||
{ev.pubkey === publicKey && (
|
||||
<MenuItem onClick={handleReBroadcastButtonClick}>
|
||||
<Icon name="relay" />
|
||||
<FormattedMessage {...messages.ReBroadcast} />
|
||||
</MenuItem>
|
||||
)}
|
||||
{ev.pubkey !== publicKey && (
|
||||
<MenuItem onClick={handleReBroadcastButtonClick}>
|
||||
<Icon name="relay" />
|
||||
<FormattedMessage defaultMessage="Broadcast Event" />
|
||||
</MenuItem>
|
||||
{ev.pubkey !== login.publicKey && !login.readonly && (
|
||||
<MenuItem onClick={() => block(ev.pubkey)}>
|
||||
<Icon name="block" />
|
||||
<FormattedMessage {...messages.Block} />
|
||||
@ -187,13 +172,13 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
<Icon name="translate" />
|
||||
<FormattedMessage {...messages.TranslateTo} values={{ lang: langNames.of(lang.split("-")[0]) }} />
|
||||
</MenuItem>
|
||||
{prefs.showDebugMenus && (
|
||||
{login.preferences.showDebugMenus && (
|
||||
<MenuItem onClick={() => copyEvent()}>
|
||||
<Icon name="json" />
|
||||
<FormattedMessage {...messages.CopyJSON} />
|
||||
</MenuItem>
|
||||
)}
|
||||
{isMine && (
|
||||
{isMine && !login.readonly && (
|
||||
<MenuItem onClick={() => deleteEvent()}>
|
||||
<Icon name="trash" className="red" />
|
||||
<FormattedMessage {...messages.Delete} />
|
||||
@ -214,7 +199,7 @@ export function NoteContextMenu({ ev, ...props }: NosteContextMenuProps) {
|
||||
menuClassName="ctx-menu">
|
||||
{menuItems()}
|
||||
</Menu>
|
||||
{willRenderReBroadcast && <ReBroadcaster />}
|
||||
{showBroadcast && <ReBroadcaster ev={ev} onClose={() => setShowBroadcast(false)} />}
|
||||
</>
|
||||
);
|
||||
}
|
@ -2,18 +2,25 @@
|
||||
border: 1px solid transparent;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0px 0px 6px 1px rgba(182, 108, 156, 0.3);
|
||||
background: linear-gradient(var(--gray-superdark), var(--gray-superdark)) padding-box,
|
||||
background:
|
||||
linear-gradient(var(--gray-superdark), var(--gray-superdark)) padding-box,
|
||||
linear-gradient(90deg, #ef9644, #fd7c49, #ff5e58, #ff3b70, #ff088e, #eb00b1, #c31ed5, #7b41f6) border-box;
|
||||
}
|
||||
|
||||
.note-creator-modal .modal-body {
|
||||
.note-creator-modal .modal-body > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.note-creator-modal .note.card {
|
||||
padding: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.note-creator-modal .note.card.note-quote {
|
||||
border: 1px solid var(--gray);
|
||||
padding: 8px 12px;
|
||||
border-radius: 12px;
|
||||
background-color: var(--gray-dark);
|
||||
}
|
||||
|
||||
.note-creator-modal h4 {
|
||||
@ -80,13 +87,13 @@
|
||||
.note-create-button {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
background-color: var(--highlight);
|
||||
color: white;
|
||||
background: linear-gradient(90deg, rgba(239, 150, 68, 1) 0%, rgba(123, 65, 246, 1) 100%);
|
||||
border: none;
|
||||
border-radius: 100%;
|
||||
position: fixed;
|
||||
bottom: 50px;
|
||||
right: calc(((100vw - 640px) / 2) - 60px);
|
||||
bottom: 40px;
|
||||
right: calc(((100vw - 640px) / 2) - 75px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@ -97,3 +104,14 @@
|
||||
right: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.light .note-creator textarea {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.light .note-creator {
|
||||
box-shadow: 0px 0px 6px 1px rgba(182, 108, 156, 0.3);
|
||||
background:
|
||||
linear-gradient(var(--gray-superdark), var(--gray-superdark)) padding-box,
|
||||
linear-gradient(90deg, #ef9644, #fd7c49, #ff5e58, #ff3b70, #ff088e, #eb00b1, #c31ed5, #7b41f6) border-box;
|
||||
}
|
512
packages/app/src/Element/Event/NoteCreator.tsx
Normal file
512
packages/app/src/Element/Event/NoteCreator.tsx
Normal file
@ -0,0 +1,512 @@
|
||||
import "./NoteCreator.css";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import {
|
||||
EventKind,
|
||||
NostrPrefix,
|
||||
TaggedNostrEvent,
|
||||
EventBuilder,
|
||||
tryParseNostrLink,
|
||||
NostrLink,
|
||||
NostrEvent,
|
||||
} from "@snort/system";
|
||||
|
||||
import Icon from "Icons/Icon";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { openFile } from "SnortUtils";
|
||||
import Textarea from "Element/Textarea";
|
||||
import Modal from "Element/Modal";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import useFileUpload from "Upload";
|
||||
import Note from "Element/Event/Note";
|
||||
|
||||
import { ClipboardEventHandler } from "react";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { System, WasmPowWorker } from "index";
|
||||
import AsyncButton from "Element/AsyncButton";
|
||||
import { AsyncIcon } from "Element/AsyncIcon";
|
||||
import { fetchNip05Pubkey } from "@snort/shared";
|
||||
import { ZapTarget } from "Zapper";
|
||||
import { useNoteCreator } from "State/NoteCreator";
|
||||
|
||||
export function NoteCreator() {
|
||||
const { formatMessage } = useIntl();
|
||||
const uploader = useFileUpload();
|
||||
const login = useLogin(s => ({ relays: s.relays, publicKey: s.publicKey, pow: s.preferences.pow }));
|
||||
const publisher = login.pow ? useEventPublisher()?.pow(login.pow, new WasmPowWorker()) : useEventPublisher();
|
||||
const note = useNoteCreator();
|
||||
const relays = login.relays;
|
||||
|
||||
async function buildNote() {
|
||||
try {
|
||||
note.update(v => (v.error = ""));
|
||||
if (note && publisher) {
|
||||
let extraTags: Array<Array<string>> | undefined;
|
||||
if (note.zapSplits) {
|
||||
const parsedSplits = [] as Array<ZapTarget>;
|
||||
for (const s of note.zapSplits) {
|
||||
if (s.value.startsWith(NostrPrefix.PublicKey) || s.value.startsWith(NostrPrefix.Profile)) {
|
||||
const link = tryParseNostrLink(s.value);
|
||||
if (link) {
|
||||
parsedSplits.push({ ...s, value: link.id });
|
||||
} else {
|
||||
throw new Error(
|
||||
formatMessage(
|
||||
{
|
||||
defaultMessage: "Failed to parse zap split: {input}",
|
||||
},
|
||||
{
|
||||
input: s.value,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (s.value.includes("@")) {
|
||||
const [name, domain] = s.value.split("@");
|
||||
const pubkey = await fetchNip05Pubkey(name, domain);
|
||||
if (pubkey) {
|
||||
parsedSplits.push({ ...s, value: pubkey });
|
||||
} else {
|
||||
throw new Error(
|
||||
formatMessage(
|
||||
{
|
||||
defaultMessage: "Failed to parse zap split: {input}",
|
||||
},
|
||||
{
|
||||
input: s.value,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
formatMessage(
|
||||
{
|
||||
defaultMessage: "Invalid zap split: {input}",
|
||||
},
|
||||
{
|
||||
input: s.value,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
extraTags = parsedSplits.map(v => ["zap", v.value, "", String(v.weight)]);
|
||||
}
|
||||
|
||||
if (note.sensitive) {
|
||||
extraTags ??= [];
|
||||
extraTags.push(["content-warning", note.sensitive]);
|
||||
}
|
||||
const kind = note.pollOptions ? EventKind.Polls : EventKind.TextNote;
|
||||
if (note.pollOptions) {
|
||||
extraTags ??= [];
|
||||
extraTags.push(...note.pollOptions.map((a, i) => ["poll_option", i.toString(), a]));
|
||||
}
|
||||
const hk = (eb: EventBuilder) => {
|
||||
extraTags?.forEach(t => eb.tag(t));
|
||||
eb.kind(kind);
|
||||
return eb;
|
||||
};
|
||||
const ev = note.replyTo
|
||||
? await publisher.reply(note.replyTo, note.note, hk)
|
||||
: await publisher.note(note.note, hk);
|
||||
return ev;
|
||||
}
|
||||
} catch (e) {
|
||||
note.update(v => {
|
||||
if (e instanceof Error) {
|
||||
v.error = e.message;
|
||||
} else {
|
||||
v.error = e as string;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function sendEventToRelays(ev: NostrEvent) {
|
||||
if (note.selectedCustomRelays) {
|
||||
await Promise.all(note.selectedCustomRelays.map(r => System.WriteOnceToRelay(r, ev)));
|
||||
} else {
|
||||
System.BroadcastEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
async function sendNote() {
|
||||
const ev = await buildNote();
|
||||
if (ev) {
|
||||
await sendEventToRelays(ev);
|
||||
for (const oe of note.otherEvents ?? []) {
|
||||
await sendEventToRelays(oe);
|
||||
}
|
||||
note.update(v => {
|
||||
v.reset();
|
||||
v.show = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function attachFile() {
|
||||
try {
|
||||
const file = await openFile();
|
||||
if (file) {
|
||||
uploadFile(file);
|
||||
}
|
||||
} catch (e) {
|
||||
note.update(v => {
|
||||
if (e instanceof Error) {
|
||||
v.error = e.message;
|
||||
} else {
|
||||
v.error = e as string;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFile(file: File | Blob) {
|
||||
try {
|
||||
if (file) {
|
||||
const rx = await uploader.upload(file, file.name);
|
||||
note.update(v => {
|
||||
if (rx.header) {
|
||||
const link = `nostr:${new NostrLink(NostrPrefix.Event, rx.header.id, rx.header.kind).encode()}`;
|
||||
v.note = `${v.note ? `${v.note}\n` : ""}${link}`;
|
||||
v.otherEvents = [...(v.otherEvents ?? []), rx.header];
|
||||
} else if (rx.url) {
|
||||
v.note = `${v.note ? `${v.note}\n` : ""}${rx.url}`;
|
||||
} else if (rx?.error) {
|
||||
v.error = rx.error;
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
note.update(v => {
|
||||
if (e instanceof Error) {
|
||||
v.error = e.message;
|
||||
} else {
|
||||
v.error = e as string;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onChange(ev: React.ChangeEvent<HTMLTextAreaElement>) {
|
||||
const { value } = ev.target;
|
||||
note.update(n => (n.note = value));
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
note.update(v => {
|
||||
v.show = false;
|
||||
v.reset();
|
||||
});
|
||||
}
|
||||
|
||||
async function onSubmit(ev: React.MouseEvent<HTMLButtonElement>) {
|
||||
ev.stopPropagation();
|
||||
await sendNote();
|
||||
}
|
||||
|
||||
async function loadPreview() {
|
||||
if (note.preview) {
|
||||
note.update(v => (v.preview = undefined));
|
||||
} else if (publisher) {
|
||||
const tmpNote = await buildNote();
|
||||
note.update(v => (v.preview = tmpNote));
|
||||
}
|
||||
}
|
||||
|
||||
function getPreviewNote() {
|
||||
if (note.preview) {
|
||||
return (
|
||||
<Note
|
||||
data={note.preview as TaggedNostrEvent}
|
||||
related={[]}
|
||||
options={{
|
||||
showContextMenu: false,
|
||||
showFooter: false,
|
||||
canClick: false,
|
||||
showTime: false,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function renderPollOptions() {
|
||||
if (note.pollOptions) {
|
||||
return (
|
||||
<>
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Poll Options" />
|
||||
</h4>
|
||||
{note.pollOptions?.map((a, i) => (
|
||||
<div className="form-group w-max" key={`po-${i}`}>
|
||||
<div>
|
||||
<FormattedMessage defaultMessage="Option: {n}" values={{ n: i + 1 }} />
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" value={a} onChange={e => changePollOption(i, e.target.value)} />
|
||||
{i > 1 && (
|
||||
<button onClick={() => removePollOption(i)} className="ml5">
|
||||
<Icon name="close" size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<button onClick={() => note.update(v => (v.pollOptions = [...(note.pollOptions ?? []), ""]))}>
|
||||
<Icon name="plus" size={14} />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function changePollOption(i: number, v: string) {
|
||||
if (note.pollOptions) {
|
||||
const copy = [...note.pollOptions];
|
||||
copy[i] = v;
|
||||
note.update(v => (v.pollOptions = copy));
|
||||
}
|
||||
}
|
||||
|
||||
function removePollOption(i: number) {
|
||||
if (note.pollOptions) {
|
||||
const copy = [...note.pollOptions];
|
||||
copy.splice(i, 1);
|
||||
note.update(v => (v.pollOptions = copy));
|
||||
}
|
||||
}
|
||||
|
||||
function renderRelayCustomisation() {
|
||||
return (
|
||||
<div className="flex-column g8">
|
||||
{Object.keys(relays.item || {})
|
||||
.filter(el => relays.item[el].write)
|
||||
.map((r, i, a) => (
|
||||
<div className="p flex f-space note-creator-relay">
|
||||
<div>{r}</div>
|
||||
<div>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!note.selectedCustomRelays || note.selectedCustomRelays.includes(r)}
|
||||
onChange={e => {
|
||||
note.update(
|
||||
v =>
|
||||
(v.selectedCustomRelays =
|
||||
// set false if all relays selected
|
||||
e.target.checked &&
|
||||
note.selectedCustomRelays &&
|
||||
note.selectedCustomRelays.length == a.length - 1
|
||||
? undefined
|
||||
: // otherwise return selectedCustomRelays with target relay added / removed
|
||||
a.filter(el =>
|
||||
el === r
|
||||
? e.target.checked
|
||||
: !note.selectedCustomRelays || note.selectedCustomRelays.includes(el),
|
||||
)),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/*function listAccounts() {
|
||||
return LoginStore.getSessions().map(a => (
|
||||
<MenuItem
|
||||
onClick={ev => {
|
||||
ev.stopPropagation = true;
|
||||
LoginStore.switchAccount(a);
|
||||
}}>
|
||||
<ProfileImage pubkey={a} link={""} />
|
||||
</MenuItem>
|
||||
));
|
||||
}*/
|
||||
|
||||
const handlePaste: ClipboardEventHandler<HTMLDivElement> = evt => {
|
||||
if (evt.clipboardData) {
|
||||
const clipboardItems = evt.clipboardData.items;
|
||||
const items: DataTransferItem[] = Array.from(clipboardItems).filter(function (item: DataTransferItem) {
|
||||
// Filter the image items only
|
||||
return /^image\//.test(item.type);
|
||||
});
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const item = items[0];
|
||||
const blob = item.getAsFile();
|
||||
if (blob) {
|
||||
uploadFile(blob);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!note.show) return null;
|
||||
return (
|
||||
<Modal id="note-creator" className="note-creator-modal" onClose={() => note.update(v => (v.show = false))}>
|
||||
{note.replyTo && (
|
||||
<Note
|
||||
data={note.replyTo}
|
||||
related={[]}
|
||||
options={{
|
||||
showFooter: false,
|
||||
showContextMenu: false,
|
||||
showTime: false,
|
||||
canClick: false,
|
||||
showMedia: false,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{note.preview && getPreviewNote()}
|
||||
{!note.preview && (
|
||||
<div onPaste={handlePaste} className={`note-creator${note.pollOptions ? " poll" : ""}`}>
|
||||
<Textarea
|
||||
autoFocus
|
||||
className={`textarea ${note.active ? "textarea--focused" : ""}`}
|
||||
onChange={c => onChange(c)}
|
||||
value={note.note}
|
||||
onFocus={() => note.update(v => (v.active = true))}
|
||||
onKeyDown={e => {
|
||||
if (e.key === "Enter" && e.metaKey) {
|
||||
sendNote().catch(console.warn);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{renderPollOptions()}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex f-space">
|
||||
<div className="flex g8">
|
||||
<ProfileImage
|
||||
pubkey={login.publicKey ?? ""}
|
||||
className="note-creator-icon"
|
||||
link=""
|
||||
showUsername={false}
|
||||
showFollowingMark={false}
|
||||
/>
|
||||
{note.pollOptions === undefined && !note.replyTo && (
|
||||
<div className="note-creator-icon">
|
||||
<Icon name="pie-chart" onClick={() => note.update(v => (v.pollOptions = ["A", "B"]))} size={24} />
|
||||
</div>
|
||||
)}
|
||||
<AsyncIcon iconName="image-plus" iconSize={24} onClick={attachFile} className="note-creator-icon" />
|
||||
<button className="secondary" onClick={() => note.update(v => (v.advanced = !v.advanced))}>
|
||||
<FormattedMessage defaultMessage="Advanced" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex g8">
|
||||
<button className="secondary" onClick={cancel}>
|
||||
<FormattedMessage defaultMessage="Cancel" />
|
||||
</button>
|
||||
<AsyncButton onClick={onSubmit}>
|
||||
{note.replyTo ? <FormattedMessage defaultMessage="Reply" /> : <FormattedMessage defaultMessage="Send" />}
|
||||
</AsyncButton>
|
||||
</div>
|
||||
</div>
|
||||
{note.error && <span className="error">{note.error}</span>}
|
||||
{note.advanced && (
|
||||
<>
|
||||
<button className="secondary" onClick={loadPreview}>
|
||||
<FormattedMessage defaultMessage="Toggle Preview" />
|
||||
</button>
|
||||
<div>
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Custom Relays" />
|
||||
</h4>
|
||||
<p>
|
||||
<FormattedMessage defaultMessage="Send note to a subset of your write relays" />
|
||||
</p>
|
||||
{renderRelayCustomisation()}
|
||||
</div>
|
||||
<div className="flex-column g8">
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Zap Splits" />
|
||||
</h4>
|
||||
<FormattedMessage defaultMessage="Zaps on this note will be split to the following users." />
|
||||
<div className="flex-column g8">
|
||||
{[...(note.zapSplits ?? [])].map((v, i, arr) => (
|
||||
<div className="flex f-center g8">
|
||||
<div className="flex-column f-4 g4">
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Recipient" />
|
||||
</h4>
|
||||
<input
|
||||
type="text"
|
||||
value={v.value}
|
||||
onChange={e =>
|
||||
note.update(
|
||||
v => (v.zapSplits = arr.map((vv, ii) => (ii === i ? { ...vv, value: e.target.value } : vv))),
|
||||
)
|
||||
}
|
||||
placeholder={formatMessage({ defaultMessage: "npub / nprofile / nostr address" })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-column f-1 g4">
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Weight" />
|
||||
</h4>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
value={v.weight}
|
||||
onChange={e =>
|
||||
note.update(
|
||||
v =>
|
||||
(v.zapSplits = arr.map((vv, ii) =>
|
||||
ii === i ? { ...vv, weight: Number(e.target.value) } : vv,
|
||||
)),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-column f-shrink g4">
|
||||
<div> </div>
|
||||
<Icon
|
||||
name="close"
|
||||
onClick={() => note.update(v => (v.zapSplits = (v.zapSplits ?? []).filter((_v, ii) => ii !== i)))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
note.update(v => (v.zapSplits = [...(v.zapSplits ?? []), { type: "pubkey", value: "", weight: 1 }]))
|
||||
}>
|
||||
<FormattedMessage defaultMessage="Add" />
|
||||
</button>
|
||||
</div>
|
||||
<span className="warning">
|
||||
<FormattedMessage defaultMessage="Not all clients support this, you may still receive some zaps as if zap splits was not configured" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex-column g8">
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Sensitive Content" />
|
||||
</h4>
|
||||
<FormattedMessage defaultMessage="Users must accept the content warning to show the content of your note." />
|
||||
<input
|
||||
className="w-max"
|
||||
type="text"
|
||||
value={note.sensitive}
|
||||
onChange={e => note.update(v => (v.sensitive = e.target.value))}
|
||||
maxLength={50}
|
||||
minLength={1}
|
||||
placeholder={formatMessage({
|
||||
defaultMessage: "Reason",
|
||||
})}
|
||||
/>
|
||||
<span className="warning">
|
||||
<FormattedMessage defaultMessage="Not all clients support this yet" />
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
@ -1,19 +1,15 @@
|
||||
import React, { HTMLProps, useEffect, useState } from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import React, { HTMLProps, useContext, useEffect, useState } from "react";
|
||||
import { useIntl } from "react-intl";
|
||||
import { useLongPress } from "use-long-press";
|
||||
import { TaggedNostrEvent, HexKey, u256, ParsedZap, countLeadingZeros } from "@snort/system";
|
||||
import { LNURL } from "@snort/shared";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import { TaggedNostrEvent, ParsedZap, countLeadingZeros, NostrLink } from "@snort/system";
|
||||
import { SnortContext, useUserProfile } from "@snort/system-react";
|
||||
|
||||
import { formatShort } from "Number";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { delay, findTag, normalizeReaction, unwrap } from "SnortUtils";
|
||||
import { NoteCreator } from "Element/NoteCreator";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { delay, findTag, normalizeReaction } from "SnortUtils";
|
||||
import { NoteCreator } from "Element/Event/NoteCreator";
|
||||
import SendSats from "Element/SendSats";
|
||||
import { ZapsSummary } from "Element/Zap";
|
||||
import { RootState } from "State/Store";
|
||||
import { setReplyTo, setShow, reset } from "State/NoteCreator";
|
||||
import { ZapsSummary } from "Element/Event/Zap";
|
||||
import { AsyncIcon } from "Element/AsyncIcon";
|
||||
|
||||
import { useWallet } from "Wallet";
|
||||
@ -21,8 +17,11 @@ import useLogin from "Hooks/useLogin";
|
||||
import { useInteractionCache } from "Hooks/useInteractionCache";
|
||||
import { ZapPoolController } from "ZapPoolController";
|
||||
import { System } from "index";
|
||||
import { Zapper, ZapTarget } from "Zapper";
|
||||
import { getDisplayName } from "../User/ProfileImage";
|
||||
import { useNoteCreator } from "State/NoteCreator";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
let isZapperBusy = false;
|
||||
const barrierZapper = async <T,>(then: () => Promise<T>): Promise<T> => {
|
||||
@ -46,21 +45,24 @@ export interface NoteFooterProps {
|
||||
|
||||
export default function NoteFooter(props: NoteFooterProps) {
|
||||
const { ev, positive, reposts, zaps } = props;
|
||||
const dispatch = useDispatch();
|
||||
const system = useContext(SnortContext);
|
||||
const { formatMessage } = useIntl();
|
||||
const login = useLogin();
|
||||
const { publicKey, preferences: prefs, relays } = login;
|
||||
const {
|
||||
publicKey,
|
||||
preferences: prefs,
|
||||
readonly,
|
||||
} = useLogin(s => ({ preferences: s.preferences, publicKey: s.publicKey, readonly: s.readonly }));
|
||||
const author = useUserProfile(ev.pubkey);
|
||||
const interactionCache = useInteractionCache(publicKey, ev.id);
|
||||
const publisher = useEventPublisher();
|
||||
const showNoteCreatorModal = useSelector((s: RootState) => s.noteCreator.show);
|
||||
const replyTo = useSelector((s: RootState) => s.noteCreator.replyTo);
|
||||
const willRenderNoteCreator = showNoteCreatorModal && replyTo?.id === ev.id;
|
||||
const note = useNoteCreator(n => ({ show: n.show, replyTo: n.replyTo, update: n.update }));
|
||||
const willRenderNoteCreator = note.show && note.replyTo?.id === ev.id;
|
||||
const [tip, setTip] = useState(false);
|
||||
const [zapping, setZapping] = useState(false);
|
||||
const walletState = useWallet();
|
||||
const wallet = walletState.wallet;
|
||||
|
||||
const canFastZap = wallet?.isReady() && !readonly;
|
||||
const isMine = ev.pubkey === publicKey;
|
||||
const zapTotal = zaps.reduce((acc, z) => acc + z.amount, 0);
|
||||
const didZap = interactionCache.data.zapped || zaps.some(a => a.sender === publicKey);
|
||||
@ -71,7 +73,7 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
},
|
||||
{
|
||||
captureEvent: true,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function hasReacted(emoji: string) {
|
||||
@ -103,27 +105,36 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}
|
||||
}
|
||||
|
||||
function getLNURL() {
|
||||
return ev.tags.find(a => a[0] === "zap")?.[1] || author?.lud16 || author?.lud06;
|
||||
}
|
||||
function getZapTarget(): Array<ZapTarget> | undefined {
|
||||
if (ev.tags.some(v => v[0] === "zap")) {
|
||||
return Zapper.fromEvent(ev);
|
||||
}
|
||||
|
||||
function getTargetName() {
|
||||
const zapTarget = ev.tags.find(a => a[0] === "zap")?.[1];
|
||||
if (zapTarget) {
|
||||
return new LNURL(zapTarget).name;
|
||||
} else {
|
||||
return author?.display_name || author?.name;
|
||||
const authorTarget = author?.lud16 || author?.lud06;
|
||||
if (authorTarget) {
|
||||
return [
|
||||
{
|
||||
type: "lnurl",
|
||||
value: authorTarget,
|
||||
weight: 1,
|
||||
name: getDisplayName(author, ev.pubkey),
|
||||
zap: {
|
||||
pubkey: ev.pubkey,
|
||||
event: NostrLink.fromEvent(ev),
|
||||
},
|
||||
} as ZapTarget,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
async function fastZap(e?: React.MouseEvent) {
|
||||
if (zapping || e?.isPropagationStopped()) return;
|
||||
|
||||
const lnurl = getLNURL();
|
||||
if (wallet?.isReady() && lnurl) {
|
||||
const lnurl = getZapTarget();
|
||||
if (canFastZap && lnurl) {
|
||||
setZapping(true);
|
||||
try {
|
||||
await fastZapInner(lnurl, prefs.defaultZapAmount, ev.pubkey, ev.id);
|
||||
await fastZapInner(lnurl, prefs.defaultZapAmount);
|
||||
} catch (e) {
|
||||
console.warn("Fast zap failed", e);
|
||||
if (!(e instanceof Error) || e.message !== "User rejected") {
|
||||
@ -137,30 +148,29 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}
|
||||
}
|
||||
|
||||
async function fastZapInner(lnurl: string, amount: number, key: HexKey, id?: u256) {
|
||||
// only allow 1 invoice req/payment at a time to avoid hitting rate limits
|
||||
await barrierZapper(async () => {
|
||||
const handler = new LNURL(lnurl);
|
||||
await handler.load();
|
||||
|
||||
const zr = Object.keys(relays.item);
|
||||
const zap = handler.canZap && publisher ? await publisher.zap(amount * 1000, key, zr, id) : undefined;
|
||||
const invoice = await handler.getInvoice(amount, undefined, zap);
|
||||
await wallet?.payInvoice(unwrap(invoice.pr));
|
||||
ZapPoolController.allocate(amount);
|
||||
|
||||
await interactionCache.zap();
|
||||
});
|
||||
async function fastZapInner(targets: Array<ZapTarget>, amount: number) {
|
||||
if (wallet) {
|
||||
// only allow 1 invoice req/payment at a time to avoid hitting rate limits
|
||||
await barrierZapper(async () => {
|
||||
const zapper = new Zapper(system, publisher);
|
||||
const result = await zapper.send(wallet, targets, amount);
|
||||
const totalSent = result.reduce((acc, v) => (acc += v.sent), 0);
|
||||
if (totalSent > 0) {
|
||||
ZapPoolController.allocate(totalSent);
|
||||
await interactionCache.zap();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (prefs.autoZap && !didZap && !isMine && !zapping) {
|
||||
const lnurl = getLNURL();
|
||||
const lnurl = getZapTarget();
|
||||
if (wallet?.isReady() && lnurl) {
|
||||
setZapping(true);
|
||||
queueMicrotask(async () => {
|
||||
try {
|
||||
await fastZapInner(lnurl, prefs.defaultZapAmount, ev.pubkey, ev.id);
|
||||
await fastZapInner(lnurl, prefs.defaultZapAmount);
|
||||
} catch {
|
||||
// ignored
|
||||
} finally {
|
||||
@ -181,14 +191,14 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}
|
||||
|
||||
function tipButton() {
|
||||
const service = getLNURL();
|
||||
if (service) {
|
||||
const targets = getZapTarget();
|
||||
if (targets) {
|
||||
return (
|
||||
<AsyncFooterIcon
|
||||
className={didZap ? "reacted" : ""}
|
||||
{...longPress()}
|
||||
title={formatMessage({ defaultMessage: "Zap" })}
|
||||
iconName={wallet?.isReady() ? "zapFast" : "zap"}
|
||||
iconName={canFastZap ? "zapFast" : "zap"}
|
||||
value={zapTotal}
|
||||
onClick={e => fastZap(e)}
|
||||
/>
|
||||
@ -198,13 +208,17 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}
|
||||
|
||||
function repostIcon() {
|
||||
if (readonly) return;
|
||||
return (
|
||||
<AsyncFooterIcon
|
||||
className={hasReposted() ? "reacted" : ""}
|
||||
iconName="repeat"
|
||||
title={formatMessage({ defaultMessage: "Repost" })}
|
||||
value={reposts.length}
|
||||
onClick={() => repost()}
|
||||
onClick={async () => {
|
||||
if (readonly) return;
|
||||
await repost();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -220,15 +234,19 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
iconName={reacted ? "heart-solid" : "heart"}
|
||||
title={formatMessage({ defaultMessage: "Like" })}
|
||||
value={positive.length}
|
||||
onClick={() => react(prefs.reactionEmoji)}
|
||||
onClick={async () => {
|
||||
if (readonly) return;
|
||||
await react(prefs.reactionEmoji);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function replyIcon() {
|
||||
if (readonly) return;
|
||||
return (
|
||||
<AsyncFooterIcon
|
||||
className={showNoteCreatorModal ? "reacted" : ""}
|
||||
className={note.show ? "reacted" : ""}
|
||||
iconName="reply"
|
||||
title={formatMessage({ defaultMessage: "Reply" })}
|
||||
value={0}
|
||||
@ -238,34 +256,27 @@ export default function NoteFooter(props: NoteFooterProps) {
|
||||
}
|
||||
|
||||
const handleReplyButtonClick = () => {
|
||||
if (replyTo?.id !== ev.id) {
|
||||
dispatch(reset());
|
||||
}
|
||||
|
||||
dispatch(setReplyTo(ev));
|
||||
dispatch(setShow(!showNoteCreatorModal));
|
||||
note.update(v => {
|
||||
if (v.replyTo?.id !== ev.id) {
|
||||
v.reset();
|
||||
}
|
||||
v.show = true;
|
||||
v.replyTo = ev;
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="footer">
|
||||
<div className="footer-reactions">
|
||||
{tipButton()}
|
||||
{reactionIcon()}
|
||||
{repostIcon()}
|
||||
{replyIcon()}
|
||||
{repostIcon()}
|
||||
{reactionIcon()}
|
||||
{tipButton()}
|
||||
{powIcon()}
|
||||
</div>
|
||||
{willRenderNoteCreator && <NoteCreator />}
|
||||
<SendSats
|
||||
lnurl={getLNURL()}
|
||||
onClose={() => setTip(false)}
|
||||
show={tip}
|
||||
author={author?.pubkey}
|
||||
target={getTargetName()}
|
||||
note={ev.id}
|
||||
allocatePool={true}
|
||||
/>
|
||||
{willRenderNoteCreator && <NoteCreator key={`note-creator-${ev.id}`} />}
|
||||
<SendSats targets={getZapTarget()} onClose={() => setTip(false)} show={tip} note={ev.id} allocatePool={true} />
|
||||
</div>
|
||||
<ZapsSummary zaps={zaps} />
|
||||
</>
|
@ -1,5 +1,5 @@
|
||||
import "./Note.css";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
|
||||
interface NoteGhostProps {
|
||||
className?: string;
|
@ -1,6 +1,6 @@
|
||||
import useEventFeed from "Feed/EventFeed";
|
||||
import { useEventFeed } from "Feed/EventFeed";
|
||||
import { NostrLink } from "@snort/system";
|
||||
import Note from "Element/Note";
|
||||
import Note from "Element/Event/Note";
|
||||
import PageSpinner from "Element/PageSpinner";
|
||||
|
||||
export default function NoteQuote({ link, depth }: { link: NostrLink; depth?: number }) {
|
@ -1,24 +1,27 @@
|
||||
import "./NoteReaction.css";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useMemo } from "react";
|
||||
import { EventKind, NostrEvent, TaggedNostrEvent, NostrPrefix } from "@snort/system";
|
||||
import { EventKind, NostrEvent, TaggedNostrEvent, NostrPrefix, EventExt } from "@snort/system";
|
||||
|
||||
import Note from "Element/Note";
|
||||
import { getDisplayName } from "Element/ProfileImage";
|
||||
import Note from "Element/Event/Note";
|
||||
import { getDisplayName } from "Element/User/ProfileImage";
|
||||
import { eventLink, hexToBech32 } from "SnortUtils";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import Icon from "Icons/Icon";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
|
||||
export interface NoteReactionProps {
|
||||
data: TaggedNostrEvent;
|
||||
root?: TaggedNostrEvent;
|
||||
depth?: number;
|
||||
}
|
||||
export default function NoteReaction(props: NoteReactionProps) {
|
||||
const { data: ev } = props;
|
||||
const { isMuted } = useModeration();
|
||||
const profile = useUserProfile(ev.pubkey);
|
||||
const { inView, ref } = useInView({ triggerOnce: true });
|
||||
const profile = useUserProfile(inView ? ev.pubkey : "");
|
||||
|
||||
const refEvent = useMemo(() => {
|
||||
if (ev) {
|
||||
@ -43,9 +46,15 @@ export default function NoteReaction(props: NoteReactionProps) {
|
||||
* Some clients embed the reposted note in the content
|
||||
*/
|
||||
function extractRoot() {
|
||||
if (!inView) return null;
|
||||
if (ev?.kind === EventKind.Repost && ev.content.length > 0 && ev.content !== "#[0]") {
|
||||
try {
|
||||
const r: NostrEvent = JSON.parse(ev.content);
|
||||
EventExt.fixupEvent(r);
|
||||
if (!EventExt.verify(r)) {
|
||||
console.debug("Event in repost is invalid");
|
||||
return undefined;
|
||||
}
|
||||
return r as TaggedNostrEvent;
|
||||
} catch (e) {
|
||||
console.error("Could not load reposted content", e);
|
||||
@ -54,7 +63,11 @@ export default function NoteReaction(props: NoteReactionProps) {
|
||||
return props.root;
|
||||
}
|
||||
|
||||
const root = extractRoot();
|
||||
const root = useMemo(() => extractRoot(), [ev, props.root, inView]);
|
||||
|
||||
if (!inView) {
|
||||
return <div className="card reaction" ref={ref}></div>;
|
||||
}
|
||||
const isOpMuted = root && isMuted(root.pubkey);
|
||||
const shouldNotBeRendered = isOpMuted || root?.kind !== EventKind.TextNote;
|
||||
const opt = {
|
||||
@ -73,7 +86,7 @@ export default function NoteReaction(props: NoteReactionProps) {
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{root ? <Note data={root} options={opt} related={[]} /> : null}
|
||||
{root ? <Note data={root} options={opt} related={[]} depth={props.depth} /> : null}
|
||||
{!root && refEvent ? (
|
||||
<p>
|
||||
<Link to={eventLink(refEvent[1] ?? "", refEvent[2])}>
|
@ -4,8 +4,7 @@ import { useState } from "react";
|
||||
import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
|
||||
import Text from "Element/Text";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { useWallet } from "Wallet";
|
||||
import { unwrap } from "SnortUtils";
|
||||
import { formatShort } from "Number";
|
||||
@ -18,12 +17,15 @@ interface PollProps {
|
||||
zaps: Array<ParsedZap>;
|
||||
}
|
||||
|
||||
type PollTally = "zaps" | "pubkeys";
|
||||
|
||||
export default function Poll(props: PollProps) {
|
||||
const { formatMessage } = useIntl();
|
||||
const publisher = useEventPublisher();
|
||||
const { wallet } = useWallet();
|
||||
const { preferences: prefs, publicKey: myPubKey, relays } = useLogin();
|
||||
const pollerProfile = useUserProfile(props.ev.pubkey);
|
||||
const [tallyBy, setTallyBy] = useState<PollTally>("pubkeys");
|
||||
const [error, setError] = useState("");
|
||||
const [invoice, setInvoice] = useState("");
|
||||
const [voting, setVoting] = useState<number>();
|
||||
@ -31,7 +33,10 @@ export default function Poll(props: PollProps) {
|
||||
const isMyPoll = props.ev.pubkey === myPubKey;
|
||||
const showResults = didVote || isMyPoll;
|
||||
|
||||
const options = props.ev.tags.filter(a => a[0] === "poll_option").sort((a, b) => Number(a[1]) - Number(b[1]));
|
||||
const options = props.ev.tags
|
||||
.filter(a => a[0] === "poll_option")
|
||||
.sort((a, b) => (Number(a[1]) > Number(b[1]) ? 1 : -1));
|
||||
|
||||
async function zapVote(ev: React.MouseEvent, opt: number) {
|
||||
ev.stopPropagation();
|
||||
if (voting || !publisher) return;
|
||||
@ -46,15 +51,15 @@ export default function Poll(props: PollProps) {
|
||||
},
|
||||
{
|
||||
amount,
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
setVoting(opt);
|
||||
const r = Object.keys(relays.item);
|
||||
const zap = await publisher.zap(amount * 1000, props.ev.pubkey, r, props.ev.id, undefined, eb =>
|
||||
eb.tag(["poll_option", opt.toString()])
|
||||
eb.tag(["poll_option", opt.toString()]),
|
||||
);
|
||||
|
||||
const lnurl = props.ev.tags.find(a => a[0] === "zap")?.[1] || pollerProfile?.lud16 || pollerProfile?.lud06;
|
||||
@ -67,7 +72,7 @@ export default function Poll(props: PollProps) {
|
||||
throw new Error(
|
||||
formatMessage({
|
||||
defaultMessage: "Can't vote because LNURL service does not support zaps",
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@ -84,7 +89,7 @@ export default function Poll(props: PollProps) {
|
||||
setError(
|
||||
formatMessage({
|
||||
defaultMessage: "Failed to send vote",
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
@ -92,33 +97,57 @@ export default function Poll(props: PollProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const allTotal = props.zaps.filter(a => a.pollOption !== undefined).reduce((acc, v) => (acc += v.amount), 0);
|
||||
const totalVotes = (() => {
|
||||
switch (tallyBy) {
|
||||
case "zaps":
|
||||
return props.zaps.filter(a => a.pollOption !== undefined).reduce((acc, v) => (acc += v.amount), 0);
|
||||
case "pubkeys":
|
||||
return new Set(props.zaps.filter(a => a.pollOption !== undefined).map(a => unwrap(a.sender))).size;
|
||||
}
|
||||
})();
|
||||
|
||||
return (
|
||||
<>
|
||||
<small>
|
||||
<FormattedMessage
|
||||
defaultMessage="You are voting with {amount} sats"
|
||||
values={{
|
||||
amount: formatShort(prefs.defaultZapAmount),
|
||||
}}
|
||||
/>
|
||||
</small>
|
||||
<div className="flex f-space p">
|
||||
<small>
|
||||
<FormattedMessage
|
||||
defaultMessage="You are voting with {amount} sats"
|
||||
values={{
|
||||
amount: formatShort(prefs.defaultZapAmount),
|
||||
}}
|
||||
/>
|
||||
</small>
|
||||
<button type="button" onClick={() => setTallyBy(s => (s !== "zaps" ? "zaps" : "pubkeys"))}>
|
||||
<FormattedMessage
|
||||
defaultMessage="Votes by {type}"
|
||||
values={{
|
||||
type:
|
||||
tallyBy === "zaps" ? (
|
||||
<FormattedMessage defaultMessage="zap" />
|
||||
) : (
|
||||
<FormattedMessage defaultMessage="user" />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<div className="poll-body">
|
||||
{options.map(a => {
|
||||
const opt = Number(a[1]);
|
||||
const desc = a[2];
|
||||
const zapsOnOption = props.zaps.filter(b => b.pollOption === opt);
|
||||
const total = zapsOnOption.reduce((acc, v) => (acc += v.amount), 0);
|
||||
const weight = allTotal === 0 ? 0 : total / allTotal;
|
||||
const total = (() => {
|
||||
switch (tallyBy) {
|
||||
case "zaps":
|
||||
return zapsOnOption.reduce((acc, v) => (acc += v.amount), 0);
|
||||
case "pubkeys":
|
||||
return new Set(zapsOnOption.map(a => unwrap(a.sender))).size;
|
||||
}
|
||||
})();
|
||||
const weight = totalVotes === 0 ? 0 : total / totalVotes;
|
||||
return (
|
||||
<div key={a[1]} className="flex" onClick={e => zapVote(e, opt)}>
|
||||
<div className="f-grow">
|
||||
{opt === voting ? (
|
||||
<Spinner />
|
||||
) : (
|
||||
<Text content={desc} tags={props.ev.tags} creator={props.ev.pubkey} disableMediaSpotlight={true} />
|
||||
)}
|
||||
</div>
|
||||
<div className="f-grow">{opt === voting ? <Spinner /> : <>{desc}</>}</div>
|
||||
{showResults && (
|
||||
<>
|
||||
<div className="flex">
|
@ -29,11 +29,31 @@
|
||||
color: var(--font-tertiary-color);
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .tabs.p {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .reactions-header {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin-bottom: 32px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .tab {
|
||||
background: none;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .tab.active {
|
||||
background: #fff;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .tab:hover {
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
color: #000;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .reactions-header h2 {
|
||||
@ -47,8 +67,11 @@
|
||||
.reactions-modal .modal-body .reactions-body {
|
||||
overflow: scroll;
|
||||
height: 40vh;
|
||||
-ms-overflow-style: none; /* for Internet Explorer, Edge */
|
||||
scrollbar-width: none; /* Firefox */
|
||||
-ms-overflow-style: none;
|
||||
/* for Internet Explorer, Edge */
|
||||
scrollbar-width: none;
|
||||
/* Firefox */
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.reactions-modal .modal-body .reactions-body::-webkit-scrollbar {
|
@ -7,11 +7,11 @@ import { TaggedNostrEvent, ParsedZap } from "@snort/system";
|
||||
import { formatShort } from "Number";
|
||||
import Icon from "Icons/Icon";
|
||||
import { Tab } from "Element/Tabs";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import Tabs from "Element/Tabs";
|
||||
import Modal from "Element/Modal";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
interface ReactionsProps {
|
||||
show: boolean;
|
||||
@ -60,7 +60,7 @@ const Reactions = ({ show, setShow, positive, negative, reposts, zaps }: Reactio
|
||||
value: 3,
|
||||
},
|
||||
]
|
||||
: []
|
||||
: [],
|
||||
);
|
||||
|
||||
const [tab, setTab] = useState(tabs[0]);
|
||||
@ -72,7 +72,7 @@ const Reactions = ({ show, setShow, positive, negative, reposts, zaps }: Reactio
|
||||
}, [show]);
|
||||
|
||||
return show ? (
|
||||
<Modal className="reactions-modal" onClose={onClose}>
|
||||
<Modal id="reactions" className="reactions-modal" onClose={onClose}>
|
||||
<div className="close" onClick={onClose}>
|
||||
<Icon name="close" />
|
||||
</div>
|
@ -1,3 +1,5 @@
|
||||
import "../Reveal.css";
|
||||
import Icon from "Icons/Icon";
|
||||
import { useState } from "react";
|
||||
|
||||
interface RevealProps {
|
||||
@ -15,8 +17,9 @@ export default function Reveal(props: RevealProps): JSX.Element {
|
||||
e.stopPropagation();
|
||||
setReveal(true);
|
||||
}}
|
||||
className="note-invoice">
|
||||
{props.message}
|
||||
className="note-notice flex g8">
|
||||
<Icon name="alert-circle" size={24} />
|
||||
<div>{props.message}</div>
|
||||
</div>
|
||||
);
|
||||
} else {
|
@ -1,9 +1,10 @@
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
|
||||
import { FileExtensionRegex } from "Const";
|
||||
import Reveal from "Element/Reveal";
|
||||
import Reveal from "Element/Event/Reveal";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { MediaElement } from "Element/MediaElement";
|
||||
import { MediaElement } from "Element/Embed/MediaElement";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
interface RevealMediaProps {
|
||||
creator: string;
|
||||
@ -51,7 +52,16 @@ export default function RevealMedia(props: RevealMediaProps) {
|
||||
if (hideMedia) {
|
||||
return (
|
||||
<Reveal
|
||||
message={<FormattedMessage defaultMessage="Click to load content from {link}" values={{ link: hostname }} />}>
|
||||
message={
|
||||
<FormattedMessage
|
||||
defaultMessage="You don't follow this person, click here to load media from <i>{link}</i>, or update <a><i>your preferences</i></a> to always load media from everybody."
|
||||
values={{
|
||||
i: i => <i>{i}</i>,
|
||||
a: a => <Link to="/settings/preferences">{a}</Link>,
|
||||
link: hostname,
|
||||
}}
|
||||
/>
|
||||
}>
|
||||
<MediaElement mime={`${type}/${extension}`} url={url.toString()} onMediaClick={props.onMediaClick} />
|
||||
</Reveal>
|
||||
);
|
@ -1,7 +1,7 @@
|
||||
import "./ShowMore.css";
|
||||
import { useIntl } from "react-intl";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
interface ShowMoreProps {
|
||||
text?: string;
|
@ -8,7 +8,8 @@
|
||||
}
|
||||
|
||||
.thread-root.note > .body .text {
|
||||
font-size: 19px;
|
||||
font-size: 18px;
|
||||
line-height: 27px;
|
||||
}
|
||||
|
||||
.thread-root.note > .footer {
|
||||
@ -55,54 +56,46 @@
|
||||
position: absolute;
|
||||
left: calc(48px / 2 + 16px);
|
||||
top: 48px;
|
||||
border-left: 1px solid var(--gray-superdark);
|
||||
border-left: 1px solid var(--border-color);
|
||||
height: 100%;
|
||||
z-index: -1;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.subthread-container.subthread-mid:not(.subthread-last) .line-container:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
border-left: 1px solid var(--gray-superdark);
|
||||
border-left: 1px solid var(--border-color);
|
||||
left: calc(48px / 2 + 16px);
|
||||
top: 0;
|
||||
height: 48px;
|
||||
z-index: -1;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.subthread-container.subthread-last .line-container:before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
border-left: 1px solid var(--gray-superdark);
|
||||
border-left: 1px solid var(--border-color);
|
||||
left: calc(48px / 2 + 16px);
|
||||
top: 0;
|
||||
height: 48px;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.divider-container {
|
||||
margin-right: 16px;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: 1px;
|
||||
background: var(--gray-superdark);
|
||||
background: var(--border-color);
|
||||
}
|
||||
|
||||
.divider.divider-small {
|
||||
margin-left: calc(16px + 61px);
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.thread-container .collapsed,
|
||||
.thread-container .show-more-container {
|
||||
background: var(--gray-superdark);
|
||||
min-height: 48px;
|
||||
}
|
||||
|
||||
.thread-container .collapsed {
|
||||
background-color: var(--gray-superdark);
|
||||
}
|
||||
|
||||
.thread-container .hidden-note {
|
||||
padding-left: 48px;
|
||||
}
|
@ -1,25 +1,17 @@
|
||||
import "./Thread.css";
|
||||
import { useMemo, useState, ReactNode } from "react";
|
||||
import { useMemo, useState, ReactNode, useContext } from "react";
|
||||
import { useIntl } from "react-intl";
|
||||
import { useNavigate, useLocation, Link, useParams } from "react-router-dom";
|
||||
import {
|
||||
TaggedNostrEvent,
|
||||
u256,
|
||||
EventKind,
|
||||
NostrPrefix,
|
||||
EventExt,
|
||||
Thread as ThreadInfo,
|
||||
parseNostrLink,
|
||||
} from "@snort/system";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { TaggedNostrEvent, u256, NostrPrefix, EventExt, parseNostrLink } from "@snort/system";
|
||||
|
||||
import { eventLink, unwrap, getReactions, getAllReactions, findTag } from "SnortUtils";
|
||||
import { getReactions, getAllReactions } from "SnortUtils";
|
||||
import BackButton from "Element/BackButton";
|
||||
import Note from "Element/Note";
|
||||
import NoteGhost from "Element/NoteGhost";
|
||||
import Note from "Element/Event/Note";
|
||||
import NoteGhost from "Element/Event/NoteGhost";
|
||||
import Collapsed from "Element/Collapsed";
|
||||
import useThreadFeed from "Feed/ThreadFeed";
|
||||
import { ThreadContext, ThreadContextWrapper, chainKey } from "Hooks/useThreadContext";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
interface DividerProps {
|
||||
variant?: "regular" | "small";
|
||||
@ -213,110 +205,39 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
|
||||
);
|
||||
};
|
||||
|
||||
export default function Thread() {
|
||||
export function ThreadRoute() {
|
||||
const params = useParams();
|
||||
const location = useLocation();
|
||||
|
||||
const link = parseNostrLink(params.id ?? "", NostrPrefix.Note);
|
||||
const thread = useThreadFeed(link);
|
||||
|
||||
const [currentId, setCurrentId] = useState(link.id);
|
||||
return (
|
||||
<ThreadContextWrapper link={link}>
|
||||
<Thread />
|
||||
</ThreadContextWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export function Thread(props: { onBack?: () => void; disableSpotlight?: boolean }) {
|
||||
const thread = useContext(ThreadContext);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const isSingleNote = thread.data?.filter(a => a.kind === EventKind.TextNote).length === 1;
|
||||
const isSingleNote = thread.chains?.size === 1 && [thread.chains.values].every(v => v.length === 0);
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
function navigateThread(e: TaggedNostrEvent) {
|
||||
setCurrentId(e.id);
|
||||
//const link = encodeTLV(e.id, NostrPrefix.Event, e.relays);
|
||||
thread.setCurrent(e.id);
|
||||
//router.navigate(`/e/${NostrLink.fromEvent(e).encode()}`, { replace: true })
|
||||
}
|
||||
|
||||
const chains = useMemo(() => {
|
||||
const chains = new Map<u256, Array<TaggedNostrEvent>>();
|
||||
if (thread.data) {
|
||||
thread.data
|
||||
?.filter(a => a.kind === EventKind.TextNote)
|
||||
.sort((a, b) => b.created_at - a.created_at)
|
||||
.forEach(v => {
|
||||
const t = EventExt.extractThread(v);
|
||||
let replyTo = t?.replyTo?.value ?? t?.root?.value;
|
||||
if (t?.root?.key === "a" && t?.root?.value) {
|
||||
const parsed = t.root.value.split(":");
|
||||
replyTo = thread.data?.find(
|
||||
a => a.kind === Number(parsed[0]) && a.pubkey === parsed[1] && findTag(a, "d") === parsed[2]
|
||||
)?.id;
|
||||
}
|
||||
if (replyTo) {
|
||||
if (!chains.has(replyTo)) {
|
||||
chains.set(replyTo, [v]);
|
||||
} else {
|
||||
unwrap(chains.get(replyTo)).push(v);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return chains;
|
||||
}, [thread.data]);
|
||||
|
||||
// Root is the parent of the current note or the current note if its a root note or the root of the thread
|
||||
const root = useMemo(() => {
|
||||
const currentNote =
|
||||
thread.data?.find(
|
||||
ne =>
|
||||
ne.id === currentId ||
|
||||
(link.type === NostrPrefix.Address && findTag(ne, "d") === currentId && ne.pubkey === link.author)
|
||||
) ?? (location.state && "sig" in location.state ? (location.state as TaggedNostrEvent) : undefined);
|
||||
if (currentNote) {
|
||||
const currentThread = EventExt.extractThread(currentNote);
|
||||
const isRoot = (ne?: ThreadInfo) => ne === undefined;
|
||||
|
||||
if (isRoot(currentThread)) {
|
||||
return currentNote;
|
||||
}
|
||||
const replyTo = currentThread?.replyTo ?? currentThread?.root;
|
||||
|
||||
// sometimes the root event ID is missing, and we can only take the happy path if the root event ID exists
|
||||
if (replyTo) {
|
||||
if (replyTo.key === "a" && replyTo.value) {
|
||||
const parsed = replyTo.value.split(":");
|
||||
return thread.data?.find(
|
||||
a => a.kind === Number(parsed[0]) && a.pubkey === parsed[1] && findTag(a, "d") === parsed[2]
|
||||
);
|
||||
}
|
||||
if (replyTo.value) {
|
||||
return thread.data?.find(a => a.id === replyTo.value);
|
||||
}
|
||||
}
|
||||
|
||||
const possibleRoots = thread.data?.filter(a => {
|
||||
const thread = EventExt.extractThread(a);
|
||||
return isRoot(thread);
|
||||
});
|
||||
if (possibleRoots) {
|
||||
// worst case we need to check every possible root to see which one contains the current note as a child
|
||||
for (const ne of possibleRoots) {
|
||||
const children = chains.get(ne.id) ?? [];
|
||||
|
||||
if (children.find(ne => ne.id === currentId)) {
|
||||
return ne;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [thread.data, currentId, location]);
|
||||
|
||||
const parent = useMemo(() => {
|
||||
if (root) {
|
||||
const currentThread = EventExt.extractThread(root);
|
||||
if (thread.root) {
|
||||
const currentThread = EventExt.extractThread(thread.root);
|
||||
return (
|
||||
currentThread?.replyTo?.value ??
|
||||
currentThread?.root?.value ??
|
||||
(currentThread?.root?.key === "a" && currentThread.root?.value)
|
||||
);
|
||||
}
|
||||
}, [root]);
|
||||
|
||||
const brokenChains = Array.from(chains?.keys()).filter(a => !thread.data?.some(b => b.id === a));
|
||||
}, [thread.root]);
|
||||
|
||||
function renderRoot(note: TaggedNostrEvent) {
|
||||
const className = `thread-root${isSingleNote ? " thread-root-single" : ""}`;
|
||||
@ -326,8 +247,8 @@ export default function Thread() {
|
||||
className={className}
|
||||
key={note.id}
|
||||
data={note}
|
||||
related={getReactions(thread.data, note.id)}
|
||||
options={{ showReactionsLink: true }}
|
||||
related={getReactions(thread.reactions, note.id)}
|
||||
options={{ showReactionsLink: true, showMediaSpotlight: !props.disableSpotlight }}
|
||||
onClick={navigateThread}
|
||||
/>
|
||||
);
|
||||
@ -337,20 +258,20 @@ export default function Thread() {
|
||||
}
|
||||
|
||||
function renderChain(from: u256): ReactNode {
|
||||
if (!from || !chains) {
|
||||
if (!from || thread.chains.size === 0) {
|
||||
return;
|
||||
}
|
||||
const replies = chains.get(from);
|
||||
if (replies && currentId) {
|
||||
const replies = thread.chains.get(from);
|
||||
if (replies && thread.current) {
|
||||
return (
|
||||
<Subthread
|
||||
active={currentId}
|
||||
active={thread.current}
|
||||
notes={replies}
|
||||
related={getAllReactions(
|
||||
thread.data,
|
||||
replies.map(a => a.id)
|
||||
thread.reactions,
|
||||
replies.map(a => a.id),
|
||||
)}
|
||||
chains={chains}
|
||||
chains={thread.chains}
|
||||
onNavigate={navigateThread}
|
||||
/>
|
||||
);
|
||||
@ -359,7 +280,9 @@ export default function Thread() {
|
||||
|
||||
function goBack() {
|
||||
if (parent) {
|
||||
setCurrentId(parent);
|
||||
thread.setCurrent(parent);
|
||||
} else if (props.onBack) {
|
||||
props.onBack();
|
||||
} else {
|
||||
navigate(-1);
|
||||
}
|
||||
@ -373,26 +296,36 @@ export default function Thread() {
|
||||
defaultMessage: "Back",
|
||||
description: "Navigate back button on threads view",
|
||||
});
|
||||
|
||||
const debug = window.location.search.includes("debug=true");
|
||||
return (
|
||||
<>
|
||||
{debug && (
|
||||
<div className="main-content p xs">
|
||||
<h1>Chains</h1>
|
||||
<pre>
|
||||
{JSON.stringify(
|
||||
Object.fromEntries([...thread.chains.entries()].map(([k, v]) => [k, v.map(c => c.id)])),
|
||||
undefined,
|
||||
" ",
|
||||
)}
|
||||
</pre>
|
||||
<h1>Current</h1>
|
||||
<pre>{JSON.stringify(thread.current)}</pre>
|
||||
<h1>Root</h1>
|
||||
<pre>{JSON.stringify(thread.root, undefined, " ")}</pre>
|
||||
<h1>Data</h1>
|
||||
<pre>{JSON.stringify(thread.data, undefined, " ")}</pre>
|
||||
<h1>Reactions</h1>
|
||||
<pre>{JSON.stringify(thread.reactions, undefined, " ")}</pre>
|
||||
</div>
|
||||
)}
|
||||
<div className="main-content p">
|
||||
<BackButton onClick={goBack} text={parent ? parentText : backText} />
|
||||
</div>
|
||||
<div className="main-content">
|
||||
{root && renderRoot(root)}
|
||||
{root && renderChain(root.id)}
|
||||
|
||||
{brokenChains.length > 0 && <h3>Other replies</h3>}
|
||||
{brokenChains.map(a => {
|
||||
return (
|
||||
<div className="mb10">
|
||||
<NoteGhost className={`thread-note thread-root ghost-root`} key={a}>
|
||||
Missing event <Link to={eventLink(a)}>{a.substring(0, 8)}</Link>
|
||||
</NoteGhost>
|
||||
{renderChain(a)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{thread.root && renderRoot(thread.root)}
|
||||
{thread.root && renderChain(chainKey(thread.root))}
|
||||
</div>
|
||||
</>
|
||||
);
|
@ -6,30 +6,26 @@ import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { unwrap } from "SnortUtils";
|
||||
import { formatShort } from "Number";
|
||||
import Text from "Element/Text";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
const Zap = ({ zap, showZapped = true }: { zap: ParsedZap; showZapped?: boolean }) => {
|
||||
const { amount, content, sender, valid, receiver } = zap;
|
||||
const pubKey = useLogin().publicKey;
|
||||
|
||||
return valid && sender ? (
|
||||
<div className="zap note card">
|
||||
<div className="header">
|
||||
<div className="card">
|
||||
<div className="flex f-space">
|
||||
<ProfileImage pubkey={sender} />
|
||||
{receiver !== pubKey && showZapped && <ProfileImage pubkey={unwrap(receiver)} />}
|
||||
<div className="amount">
|
||||
<span className="amount-number">
|
||||
<FormattedMessage {...messages.Sats} values={{ n: formatShort(amount ?? 0) }} />
|
||||
</span>
|
||||
</div>
|
||||
<h3>
|
||||
<FormattedMessage {...messages.Sats} values={{ n: formatShort(amount ?? 0) }} />
|
||||
</h3>
|
||||
</div>
|
||||
{(content?.length ?? 0) > 0 && sender && (
|
||||
<div className="body">
|
||||
<Text creator={sender} content={unwrap(content)} tags={[]} />
|
||||
</div>
|
||||
<Text id={zap.id} creator={sender} content={unwrap(content)} tags={[]} />
|
||||
)}
|
||||
</div>
|
||||
) : null;
|
||||
@ -63,6 +59,7 @@ export const ZapsSummary = ({ zaps }: ZapsSummaryProps) => {
|
||||
{sender && (
|
||||
<ProfileImage
|
||||
pubkey={anonZap ? "" : sender}
|
||||
showFollowingMark={false}
|
||||
overrideUsername={anonZap ? formatMessage({ defaultMessage: "Anonymous" }) : undefined}
|
||||
/>
|
||||
)}
|
@ -5,6 +5,7 @@ import { useUserProfile } from "@snort/system-react";
|
||||
|
||||
import SendSats from "Element/SendSats";
|
||||
import Icon from "Icons/Icon";
|
||||
import { ZapTarget } from "Zapper";
|
||||
|
||||
const ZapButton = ({
|
||||
pubkey,
|
||||
@ -24,16 +25,22 @@ const ZapButton = ({
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="zap-button flex" onClick={() => setZap(true)}>
|
||||
<Icon name="zap" className={children ? "mr5" : ""} size={15} />
|
||||
<button type="button" className="flex g8" onClick={() => setZap(true)}>
|
||||
<Icon name="zap-solid" />
|
||||
{children}
|
||||
</div>
|
||||
</button>
|
||||
<SendSats
|
||||
target={profile?.display_name || profile?.name}
|
||||
lnurl={service}
|
||||
targets={[
|
||||
{
|
||||
type: "lnurl",
|
||||
value: service,
|
||||
weight: 1,
|
||||
name: profile?.display_name || profile?.name,
|
||||
zap: { pubkey: pubkey },
|
||||
} as ZapTarget,
|
||||
]}
|
||||
show={zap}
|
||||
onClose={() => setZap(false)}
|
||||
author={pubkey}
|
||||
note={event}
|
||||
/>
|
||||
</>
|
@ -1,13 +1,16 @@
|
||||
import "./ZapGoal.css";
|
||||
import { NostrEvent, NostrPrefix, createNostrLink } from "@snort/system";
|
||||
import { CSSProperties, useState } from "react";
|
||||
import { NostrEvent, NostrLink } from "@snort/system";
|
||||
import useZapsFeed from "Feed/ZapsFeed";
|
||||
import { formatShort } from "Number";
|
||||
import { findTag } from "SnortUtils";
|
||||
import { CSSProperties } from "react";
|
||||
import ZapButton from "./ZapButton";
|
||||
import Icon from "Icons/Icon";
|
||||
import SendSats from "../SendSats";
|
||||
import { Zapper } from "Zapper";
|
||||
|
||||
export function ZapGoal({ ev }: { ev: NostrEvent }) {
|
||||
const zaps = useZapsFeed(createNostrLink(NostrPrefix.Note, ev.id));
|
||||
const [zap, setZap] = useState(false);
|
||||
const zaps = useZapsFeed(NostrLink.fromEvent(ev));
|
||||
const target = Number(findTag(ev, "amount"));
|
||||
const amount = zaps.reduce((acc, v) => (acc += v.amount * 1000), 0);
|
||||
const progress = 100 * (amount / target);
|
||||
@ -16,7 +19,10 @@ export function ZapGoal({ ev }: { ev: NostrEvent }) {
|
||||
<div className="zap-goal card">
|
||||
<div className="flex f-space">
|
||||
<h2>{ev.content}</h2>
|
||||
<ZapButton pubkey={ev.pubkey} event={ev.id} />
|
||||
<div className="zap-button flex" onClick={() => setZap(true)}>
|
||||
<Icon name="zap" size={15} />
|
||||
</div>
|
||||
<SendSats targets={Zapper.fromEvent(ev)} show={zap} onClose={() => setZap(false)} />
|
||||
</div>
|
||||
|
||||
<div className="flex f-space">
|
@ -1,8 +1,8 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
|
||||
import messages from "./messages";
|
||||
import messages from "../messages";
|
||||
|
||||
export default function LoadMore({
|
||||
onLoadMore,
|
@ -10,16 +10,16 @@
|
||||
|
||||
.latest-notes-fixed {
|
||||
position: fixed;
|
||||
left: calc(50% - 261px / 2 + 0.5px);
|
||||
left: 45%;
|
||||
top: 12px;
|
||||
width: 261px;
|
||||
left: calc(50% - 261px / 2 + 0.5px);
|
||||
width: auto;
|
||||
z-index: 42;
|
||||
opacity: 0.9;
|
||||
box-shadow: 0px 0px 15px rgba(78, 0, 255, 0.6);
|
||||
color: white;
|
||||
background: var(--highlight);
|
||||
border-radius: 100px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
@ -36,6 +36,7 @@
|
||||
margin: 0;
|
||||
margin-right: -26px;
|
||||
}
|
||||
|
||||
.latest-notes .pfp:last-of-type {
|
||||
margin-right: -8px;
|
||||
}
|
@ -1,19 +1,15 @@
|
||||
import "./Timeline.css";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
import { TaggedNostrEvent, EventKind, u256, parseZap } from "@snort/system";
|
||||
import { TaggedNostrEvent, EventKind, u256 } from "@snort/system";
|
||||
|
||||
import Icon from "Icons/Icon";
|
||||
import { dedupeByPubkey, findTag, tagFilterOfTextRepost } from "SnortUtils";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import { dedupeByPubkey, findTag } from "SnortUtils";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import useTimelineFeed, { TimelineFeed, TimelineSubject } from "Feed/TimelineFeed";
|
||||
import Zap from "Element/Zap";
|
||||
import Note from "Element/Note";
|
||||
import NoteReaction from "Element/NoteReaction";
|
||||
import Note from "Element/Event/Note";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import ProfilePreview from "Element/ProfilePreview";
|
||||
import { UserCache } from "Cache";
|
||||
import { LiveStreams } from "Element/LiveStreams";
|
||||
|
||||
export interface TimelineProps {
|
||||
@ -28,7 +24,7 @@ export interface TimelineProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of notes by pubkeys
|
||||
* A list of notes by "subject"
|
||||
*/
|
||||
const Timeline = (props: TimelineProps) => {
|
||||
const feedOptions = useMemo(() => {
|
||||
@ -51,7 +47,7 @@ const Timeline = (props: TimelineProps) => {
|
||||
?.filter(a => (props.postsOnly ? !a.tags.some(b => b[0] === "e") : true))
|
||||
.filter(a => props.ignoreModeration || !isMuted(a.pubkey));
|
||||
},
|
||||
[props.postsOnly, muted, props.ignoreModeration]
|
||||
[props.postsOnly, muted, props.ignoreModeration],
|
||||
);
|
||||
|
||||
const mainFeed = useMemo(() => {
|
||||
@ -64,50 +60,16 @@ const Timeline = (props: TimelineProps) => {
|
||||
(id: u256) => {
|
||||
return (feed.related ?? []).filter(a => findTag(a, "e") === id);
|
||||
},
|
||||
[feed.related]
|
||||
[feed.related],
|
||||
);
|
||||
const liveStreams = useMemo(() => {
|
||||
return (feed.main ?? []).filter(a => a.kind === EventKind.LiveEvent && findTag(a, "status") === "live");
|
||||
}, [feed]);
|
||||
|
||||
const findRelated = useCallback(
|
||||
(id?: u256) => {
|
||||
if (!id) return undefined;
|
||||
return (feed.related ?? []).find(a => a.id === id);
|
||||
},
|
||||
[feed.related]
|
||||
);
|
||||
const latestAuthors = useMemo(() => {
|
||||
return dedupeByPubkey(latestFeed).map(e => e.pubkey);
|
||||
}, [latestFeed]);
|
||||
|
||||
function eventElement(e: TaggedNostrEvent) {
|
||||
switch (e.kind) {
|
||||
case EventKind.SetMetadata: {
|
||||
return <ProfilePreview actions={<></>} pubkey={e.pubkey} className="card" />;
|
||||
}
|
||||
case EventKind.Polls:
|
||||
case EventKind.TextNote: {
|
||||
const eRef = e.tags.find(tagFilterOfTextRepost(e))?.at(1);
|
||||
if (eRef) {
|
||||
return <NoteReaction data={e} key={e.id} root={findRelated(eRef)} />;
|
||||
}
|
||||
return (
|
||||
<Note key={e.id} searchedValue={props.subject.discriminator} data={e} related={relatedFeed(e.id)} ignoreModeration={props.ignoreModeration} depth={0} />
|
||||
);
|
||||
}
|
||||
case EventKind.ZapReceipt: {
|
||||
const zap = parseZap(e, UserCache);
|
||||
return zap.event ? null : <Zap zap={zap} key={e.id} />;
|
||||
}
|
||||
case EventKind.Reaction:
|
||||
case EventKind.Repost: {
|
||||
const eRef = findTag(e, "e");
|
||||
return <NoteReaction data={e} key={e.id} root={findRelated(eRef)} />;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onShowLatest(scrollToTop = false) {
|
||||
feed.showLatest();
|
||||
if (scrollToTop) {
|
||||
@ -144,7 +106,9 @@ const Timeline = (props: TimelineProps) => {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{mainFeed.map(eventElement)}
|
||||
{mainFeed.map(e => (
|
||||
<Note key={e.id} searchedValue={props.subject.discriminator} data={e} related={relatedFeed(e.id)} ignoreModeration={props.ignoreModeration} depth={0} />
|
||||
))}
|
||||
{(props.loadMore === undefined || props.loadMore === true) && (
|
||||
<div className="flex f-center">
|
||||
<button type="button" onClick={() => feed.loadMore()}>
|
140
packages/app/src/Element/Feed/TimelineFollows.tsx
Normal file
140
packages/app/src/Element/Feed/TimelineFollows.tsx
Normal file
@ -0,0 +1,140 @@
|
||||
import "./Timeline.css";
|
||||
import { ReactNode, useCallback, useContext, useMemo, useState, useSyncExternalStore } from "react";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { TaggedNostrEvent, EventKind, u256, NostrEvent, NostrLink } from "@snort/system";
|
||||
import { unixNow } from "@snort/shared";
|
||||
import { SnortContext } from "@snort/system-react";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
|
||||
import { dedupeByPubkey, findTag, orderDescending } from "SnortUtils";
|
||||
import Note from "Element/Event/Note";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
import { FollowsFeed } from "Cache";
|
||||
import { LiveStreams } from "Element/LiveStreams";
|
||||
import { useReactions } from "Feed/Reactions";
|
||||
import AsyncButton from "../AsyncButton";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import ProfileImage from "Element/User/ProfileImage";
|
||||
import Icon from "Icons/Icon";
|
||||
|
||||
export interface TimelineFollowsProps {
|
||||
postsOnly: boolean;
|
||||
liveStreams?: boolean;
|
||||
noteFilter?: (ev: NostrEvent) => boolean;
|
||||
noteRenderer?: (ev: NostrEvent) => ReactNode;
|
||||
noteOnClick?: (ev: NostrEvent) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of notes by "subject"
|
||||
*/
|
||||
const TimelineFollows = (props: TimelineFollowsProps) => {
|
||||
const [latest, setLatest] = useState(unixNow());
|
||||
const feed = useSyncExternalStore(
|
||||
cb => FollowsFeed.hook(cb, "*"),
|
||||
() => FollowsFeed.snapshot(),
|
||||
);
|
||||
const reactions = useReactions(
|
||||
"follows-feed-reactions",
|
||||
feed.map(a => NostrLink.fromEvent(a)),
|
||||
);
|
||||
const system = useContext(SnortContext);
|
||||
const login = useLogin();
|
||||
const { muted, isMuted } = useModeration();
|
||||
const { ref, inView } = useInView();
|
||||
|
||||
const sortedFeed = useMemo(() => orderDescending(feed), [feed]);
|
||||
|
||||
const filterPosts = useCallback(
|
||||
function <T extends NostrEvent>(nts: Array<T>) {
|
||||
const a = nts.filter(a => a.kind !== EventKind.LiveEvent);
|
||||
return a
|
||||
?.filter(a => (props.postsOnly ? !a.tags.some(b => b[0] === "e") : true))
|
||||
.filter(a => !isMuted(a.pubkey) && login.follows.item.includes(a.pubkey) && (props.noteFilter?.(a) ?? true));
|
||||
},
|
||||
[props.postsOnly, muted, login.follows.timestamp],
|
||||
);
|
||||
|
||||
const mainFeed = useMemo(() => {
|
||||
return filterPosts((sortedFeed ?? []).filter(a => a.created_at <= latest));
|
||||
}, [sortedFeed, filterPosts, latest, login.follows.timestamp]);
|
||||
|
||||
const latestFeed = useMemo(() => {
|
||||
return filterPosts((sortedFeed ?? []).filter(a => a.created_at > latest));
|
||||
}, [sortedFeed, latest]);
|
||||
|
||||
const relatedFeed = useCallback(
|
||||
(id: u256) => {
|
||||
return (reactions?.data ?? []).filter(a => findTag(a, "e") === id);
|
||||
},
|
||||
[reactions],
|
||||
);
|
||||
|
||||
const liveStreams = useMemo(() => {
|
||||
return (sortedFeed ?? []).filter(a => a.kind === EventKind.LiveEvent && findTag(a, "status") === "live");
|
||||
}, [sortedFeed]);
|
||||
|
||||
const latestAuthors = useMemo(() => {
|
||||
return dedupeByPubkey(latestFeed).map(e => e.pubkey);
|
||||
}, [latestFeed]);
|
||||
|
||||
function onShowLatest(scrollToTop = false) {
|
||||
setLatest(unixNow());
|
||||
if (scrollToTop) {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{(props.liveStreams ?? true) && <LiveStreams evs={liveStreams} />}
|
||||
{latestFeed.length > 0 && (
|
||||
<>
|
||||
<div className="card latest-notes" onClick={() => onShowLatest()} ref={ref}>
|
||||
{latestAuthors.slice(0, 3).map(p => {
|
||||
return <ProfileImage pubkey={p} showUsername={false} link={""} showFollowingMark={false} />;
|
||||
})}
|
||||
<FormattedMessage
|
||||
defaultMessage="{n} new {n, plural, =1 {note} other {notes}}"
|
||||
values={{ n: latestFeed.length }}
|
||||
/>
|
||||
<Icon name="arrowUp" />
|
||||
</div>
|
||||
{!inView && (
|
||||
<div className="card latest-notes latest-notes-fixed pointer fade-in" onClick={() => onShowLatest(true)}>
|
||||
{latestAuthors.slice(0, 3).map(p => {
|
||||
return <ProfileImage pubkey={p} showUsername={false} link={""} showFollowingMark={false} />;
|
||||
})}
|
||||
<FormattedMessage
|
||||
defaultMessage="{n} new {n, plural, =1 {note} other {notes}}"
|
||||
values={{ n: latestFeed.length }}
|
||||
/>
|
||||
<Icon name="arrowUp" />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{mainFeed.map(
|
||||
a =>
|
||||
props.noteRenderer?.(a) ?? (
|
||||
<Note
|
||||
data={a as TaggedNostrEvent}
|
||||
related={relatedFeed(a.id)}
|
||||
key={a.id}
|
||||
depth={0}
|
||||
onClick={props.noteOnClick}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
<div className="flex f-center p">
|
||||
<AsyncButton
|
||||
onClick={async () => {
|
||||
await FollowsFeed.loadMore(system, login, sortedFeed[sortedFeed.length - 1].created_at);
|
||||
}}>
|
||||
<FormattedMessage defaultMessage="Load more" />
|
||||
</AsyncButton>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
export default TimelineFollows;
|
@ -1,14 +1,14 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { NostrEvent, TaggedNostrEvent } from "@snort/system";
|
||||
import { NostrEvent, NostrLink, TaggedNostrEvent } from "@snort/system";
|
||||
|
||||
import PageSpinner from "Element/PageSpinner";
|
||||
import Note from "Element/Note";
|
||||
import Note from "Element/Event/Note";
|
||||
import NostrBandApi from "External/NostrBand";
|
||||
import { useReactions } from "Feed/FeedReactions";
|
||||
import { useReactions } from "Feed/Reactions";
|
||||
|
||||
export default function TrendingNotes() {
|
||||
const [posts, setPosts] = useState<Array<NostrEvent>>();
|
||||
const related = useReactions("trending", posts?.map(a => a.id) ?? []);
|
||||
const related = useReactions("trending", posts?.map(a => NostrLink.fromEvent(a)) ?? []);
|
||||
|
||||
async function loadTrendingNotes() {
|
||||
const api = new NostrBandApi();
|
22
packages/app/src/Element/FormattedMessage.tsx
Normal file
22
packages/app/src/Element/FormattedMessage.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import { useState, useEffect, FC, ComponentProps } from "react";
|
||||
import { useIntl, FormattedMessage } from "react-intl";
|
||||
|
||||
type ExtendedProps = ComponentProps<typeof FormattedMessage>;
|
||||
|
||||
const ExtendedFormattedMessage: FC<ExtendedProps> = props => {
|
||||
const { id, defaultMessage, values } = props;
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const [processedMessage, setProcessedMessage] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const translatedMessage = formatMessage({ id, defaultMessage }, values);
|
||||
if (typeof translatedMessage === "string") {
|
||||
setProcessedMessage(translatedMessage.replace("Snort", process.env.APP_NAME_CAPITALIZED || "Snort"));
|
||||
}
|
||||
}, [id, defaultMessage, values, formatMessage]);
|
||||
|
||||
return <>{processedMessage}</>;
|
||||
};
|
||||
|
||||
export default ExtendedFormattedMessage;
|
@ -13,23 +13,24 @@ import {
|
||||
WavlakeRegex,
|
||||
} from "Const";
|
||||
import { magnetURIDecode } from "SnortUtils";
|
||||
import SoundCloudEmbed from "Element/SoundCloudEmded";
|
||||
import MixCloudEmbed from "Element/MixCloudEmbed";
|
||||
import SpotifyEmbed from "Element/SpotifyEmbed";
|
||||
import TidalEmbed from "Element/TidalEmbed";
|
||||
import TwitchEmbed from "Element/TwitchEmbed";
|
||||
import AppleMusicEmbed from "Element/AppleMusicEmbed";
|
||||
import WavlakeEmbed from "Element/WavlakeEmbed";
|
||||
import LinkPreview from "Element/LinkPreview";
|
||||
import NostrLink from "Element/NostrLink";
|
||||
import MagnetLink from "Element/MagnetLink";
|
||||
import SoundCloudEmbed from "Element/Embed/SoundCloudEmded";
|
||||
import MixCloudEmbed from "Element/Embed/MixCloudEmbed";
|
||||
import SpotifyEmbed from "Element/Embed/SpotifyEmbed";
|
||||
import TidalEmbed from "Element/Embed/TidalEmbed";
|
||||
import TwitchEmbed from "Element/Embed/TwitchEmbed";
|
||||
import AppleMusicEmbed from "Element/Embed/AppleMusicEmbed";
|
||||
import WavlakeEmbed from "Element/Embed/WavlakeEmbed";
|
||||
import LinkPreview from "Element/Embed/LinkPreview";
|
||||
import NostrLink from "Element/Embed/NostrLink";
|
||||
import MagnetLink from "Element/Embed/MagnetLink";
|
||||
|
||||
interface HypeTextProps {
|
||||
link: string;
|
||||
depth?: number;
|
||||
showLinkPreview?: boolean;
|
||||
}
|
||||
|
||||
export default function HyperText({ link, depth }: HypeTextProps) {
|
||||
export default function HyperText({ link, depth, showLinkPreview }: HypeTextProps) {
|
||||
const a = link;
|
||||
try {
|
||||
const url = new URL(a);
|
||||
@ -91,7 +92,7 @@ export default function HyperText({ link, depth }: HypeTextProps) {
|
||||
if (parsed) {
|
||||
return <MagnetLink magnet={parsed} />;
|
||||
}
|
||||
} else {
|
||||
} else if (showLinkPreview ?? true) {
|
||||
return <LinkPreview url={a} />;
|
||||
}
|
||||
} catch {
|
||||
|
@ -1,25 +1,84 @@
|
||||
import { NostrEvent, NostrPrefix, encodeTLV } from "@snort/system";
|
||||
import { findTag, unwrap } from "SnortUtils";
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import { NostrEvent, NostrLink } from "@snort/system";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { findTag } from "SnortUtils";
|
||||
import ProfileImage from "./User/ProfileImage";
|
||||
import Icon from "Icons/Icon";
|
||||
|
||||
export function LiveEvent({ ev }: { ev: NostrEvent }) {
|
||||
const title = findTag(ev, "title");
|
||||
const d = unwrap(findTag(ev, "d"));
|
||||
return (
|
||||
<div className="text">
|
||||
<div className="flex card">
|
||||
<div className="f-grow">
|
||||
<h3>{title}</h3>
|
||||
</div>
|
||||
<div>
|
||||
<Link to={`https://zap.stream/${encodeTLV(NostrPrefix.Address, d, undefined, ev.kind, ev.pubkey)}`}>
|
||||
<button className="primary" type="button">
|
||||
<FormattedMessage defaultMessage="Watch Live!" />
|
||||
const status = findTag(ev, "status");
|
||||
const starts = Number(findTag(ev, "starts"));
|
||||
const host = ev.tags.find(a => a[0] === "p" && a[3] === "host")?.[1] ?? ev.pubkey;
|
||||
|
||||
function statusLine() {
|
||||
switch (status) {
|
||||
case "live": {
|
||||
return (
|
||||
<div className="flex g4">
|
||||
<Icon name="signal-01" />
|
||||
<b className="uppercase">
|
||||
<FormattedMessage defaultMessage="Live" />
|
||||
</b>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
case "ended": {
|
||||
return (
|
||||
<b className="uppercase">
|
||||
<FormattedMessage defaultMessage="Ended" />
|
||||
</b>
|
||||
);
|
||||
}
|
||||
case "planned": {
|
||||
return (
|
||||
<b className="uppercase">
|
||||
{new Intl.DateTimeFormat(undefined, { dateStyle: "full", timeStyle: "short" }).format(
|
||||
new Date(starts * 1000),
|
||||
)}
|
||||
</b>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cta() {
|
||||
const link = `https://zap.stream/${NostrLink.fromEvent(ev).encode()}`;
|
||||
switch (status) {
|
||||
case "live": {
|
||||
return (
|
||||
<Link to={link} target="_blank">
|
||||
<button type="button">
|
||||
<FormattedMessage defaultMessage="Join Stream" />
|
||||
</button>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
case "ended": {
|
||||
if (findTag(ev, "recording")) {
|
||||
return (
|
||||
<Link to={link} target="_blank">
|
||||
<button type="button">
|
||||
<FormattedMessage defaultMessage="Watch Replay" />
|
||||
</button>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex f-space br p24 bg-primary">
|
||||
<div className="flex g12">
|
||||
<ProfileImage pubkey={host} showUsername={false} size={56} />
|
||||
<div>
|
||||
<h2>{title}</h2>
|
||||
{statusLine()}
|
||||
</div>
|
||||
</div>
|
||||
<div>{cta()}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import "./LiveStreams.css";
|
||||
import { NostrEvent, NostrPrefix, encodeTLV } from "@snort/system";
|
||||
import { NostrEvent, NostrLink } from "@snort/system";
|
||||
import { findTag } from "SnortUtils";
|
||||
import { CSSProperties, useMemo } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
@ -32,7 +32,7 @@ function LiveStreamEvent({ ev }: { ev: NostrEvent }) {
|
||||
const image = findTag(ev, "image");
|
||||
const status = findTag(ev, "status");
|
||||
|
||||
const link = encodeTLV(NostrPrefix.Address, findTag(ev, "d") ?? "", undefined, ev.kind, ev.pubkey);
|
||||
const link = NostrLink.fromEvent(ev).encode();
|
||||
const imageProxy = proxy(image ?? "");
|
||||
|
||||
return (
|
||||
|
@ -4,7 +4,7 @@ const Logo = () => {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<h1 className="logo" onClick={() => navigate("/")}>
|
||||
Snort
|
||||
{process.env.APP_NAME}
|
||||
</h1>
|
||||
);
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FormattedMessage } from "react-intl";
|
||||
import FormattedMessage from "Element/FormattedMessage";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { logout } from "Login";
|
||||
@ -7,15 +7,15 @@ import messages from "./messages";
|
||||
|
||||
export default function LogoutButton() {
|
||||
const navigate = useNavigate();
|
||||
const publicKey = useLogin().publicKey;
|
||||
const login = useLogin(s => ({ publicKey: s.publicKey, id: s.id }));
|
||||
|
||||
if (!publicKey) return;
|
||||
if (!login.publicKey) return;
|
||||
return (
|
||||
<button
|
||||
className="secondary"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
logout(publicKey);
|
||||
logout(login.id);
|
||||
navigate("/");
|
||||
}}>
|
||||
<FormattedMessage {...messages.Logout} />
|
||||
|
@ -13,15 +13,24 @@
|
||||
|
||||
.modal-body {
|
||||
background-color: var(--gray-superdark);
|
||||
padding: 16px 24px;
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 500px;
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
--border-color: var(--gray);
|
||||
}
|
||||
|
||||
.modal-body button.secondary:hover {
|
||||
background-color: var(--gray);
|
||||
}
|
||||
|
||||
.light .modal-body {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.modal.spotlight {
|
||||
color: #fff;
|
||||
}
|
||||
|
@ -1,25 +1,23 @@
|
||||
import "./Modal.css";
|
||||
import { useEffect, MouseEventHandler, ReactNode } from "react";
|
||||
import { ReactNode, useEffect } from "react";
|
||||
|
||||
export interface ModalProps {
|
||||
id: string;
|
||||
className?: string;
|
||||
onClose?: MouseEventHandler;
|
||||
onClose?: (e: React.MouseEvent) => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export default function Modal(props: ModalProps) {
|
||||
const onClose = props.onClose || (() => undefined);
|
||||
const className = props.className || "";
|
||||
|
||||
useEffect(() => {
|
||||
document.body.classList.add("scroll-lock");
|
||||
return () => document.body.classList.remove("scroll-lock");
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={`modal ${className}`} onClick={onClose}>
|
||||
<div className="modal-body" onClick={e => e.stopPropagation()}>
|
||||
{props.children}
|
||||
<div className={`modal${props.className ? ` ${props.className}` : ""}`} onClick={props.onClose}>
|
||||
<div className="modal-body" onClick={props.onClose}>
|
||||
<div onClick={e => e.stopPropagation()}>{props.children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -18,7 +18,7 @@ import AsyncButton from "Element/AsyncButton";
|
||||
import SendSats from "Element/SendSats";
|
||||
import Copy from "Element/Copy";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { debounce } from "SnortUtils";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import SnortServiceProvider from "Nip05/SnortServiceProvider";
|
||||
@ -43,8 +43,8 @@ export default function Nip5Service(props: Nip05ServiceProps) {
|
||||
const navigate = useNavigate();
|
||||
const { helpText = true } = props;
|
||||
const { formatMessage } = useIntl();
|
||||
const pubkey = useLogin().publicKey;
|
||||
const user = useUserProfile(pubkey);
|
||||
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
|
||||
const user = useUserProfile(publicKey);
|
||||
const publisher = useEventPublisher();
|
||||
const svc = useMemo(() => new ServiceProvider(props.service), [props.service]);
|
||||
const [serviceConfig, setServiceConfig] = useState<ServiceConfig>();
|
||||
@ -179,11 +179,11 @@ export default function Nip5Service(props: Nip05ServiceProps) {
|
||||
}
|
||||
|
||||
async function startBuy(handle: string, domain: string) {
|
||||
if (!pubkey) {
|
||||
if (!publicKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rsp = await svc.RegisterHandle(handle, domain, pubkey);
|
||||
const rsp = await svc.RegisterHandle(handle, domain, publicKey);
|
||||
if ("error" in rsp) {
|
||||
setError(rsp);
|
||||
} else {
|
||||
@ -193,7 +193,7 @@ export default function Nip5Service(props: Nip05ServiceProps) {
|
||||
}
|
||||
|
||||
async function claimForSubscription(handle: string, domain: string, sub: string) {
|
||||
if (!pubkey || !publisher) {
|
||||
if (!publicKey || !publisher) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -261,9 +261,7 @@ export default function Nip5Service(props: Nip05ServiceProps) {
|
||||
/>
|
||||
@
|
||||
<select value={domain} onChange={onDomainChange}>
|
||||
{serviceConfig?.domains.map(a => (
|
||||
<option key={a.name}>{a.name}</option>
|
||||
))}
|
||||
{serviceConfig?.domains.map(a => <option key={a.name}>{a.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
|
@ -1,419 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import "./NoteCreator.css";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { encodeTLV, EventKind, NostrPrefix, TaggedNostrEvent, EventBuilder } from "@snort/system";
|
||||
import { LNURL } from "@snort/shared";
|
||||
|
||||
import Icon from "Icons/Icon";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { openFile } from "SnortUtils";
|
||||
import Textarea from "Element/Textarea";
|
||||
import Modal from "Element/Modal";
|
||||
import ProfileImage from "Element/ProfileImage";
|
||||
import useFileUpload from "Upload";
|
||||
import Note from "Element/Note";
|
||||
import {
|
||||
setShow,
|
||||
setNote,
|
||||
setError,
|
||||
setActive,
|
||||
setPreview,
|
||||
setShowAdvanced,
|
||||
setSelectedCustomRelays,
|
||||
setZapForward,
|
||||
setSensitive,
|
||||
reset,
|
||||
setPollOptions,
|
||||
setOtherEvents,
|
||||
} from "State/NoteCreator";
|
||||
import type { RootState } from "State/Store";
|
||||
|
||||
import messages from "./messages";
|
||||
import { ClipboardEventHandler, useState } from "react";
|
||||
import Spinner from "Icons/Spinner";
|
||||
import { Menu, MenuItem } from "@szhsin/react-menu";
|
||||
import { LoginStore } from "Login";
|
||||
import { getCurrentSubscription } from "Subscription";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { System } from "index";
|
||||
import AsyncButton from "Element/AsyncButton";
|
||||
import { AsyncIcon } from "Element/AsyncIcon";
|
||||
|
||||
export function NoteCreator() {
|
||||
const { formatMessage } = useIntl();
|
||||
const publisher = useEventPublisher();
|
||||
const uploader = useFileUpload();
|
||||
const {
|
||||
note,
|
||||
zapForward,
|
||||
sensitive,
|
||||
pollOptions,
|
||||
replyTo,
|
||||
otherEvents,
|
||||
preview,
|
||||
active,
|
||||
show,
|
||||
showAdvanced,
|
||||
selectedCustomRelays,
|
||||
error,
|
||||
} = useSelector((s: RootState) => s.noteCreator);
|
||||
const dispatch = useDispatch();
|
||||
const sub = getCurrentSubscription(LoginStore.allSubscriptions());
|
||||
const login = useLogin();
|
||||
const relays = login.relays;
|
||||
|
||||
async function sendNote() {
|
||||
if (note && publisher) {
|
||||
let extraTags: Array<Array<string>> | undefined;
|
||||
if (zapForward) {
|
||||
try {
|
||||
const svc = new LNURL(zapForward);
|
||||
await svc.load();
|
||||
extraTags = [svc.getZapTag()];
|
||||
} catch {
|
||||
dispatch(
|
||||
setError(
|
||||
formatMessage({
|
||||
defaultMessage: "Invalid LNURL",
|
||||
})
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (sensitive) {
|
||||
extraTags ??= [];
|
||||
extraTags.push(["content-warning", sensitive]);
|
||||
}
|
||||
const kind = pollOptions ? EventKind.Polls : EventKind.TextNote;
|
||||
if (pollOptions) {
|
||||
extraTags ??= [];
|
||||
extraTags.push(...pollOptions.map((a, i) => ["poll_option", i.toString(), a]));
|
||||
}
|
||||
const hk = (eb: EventBuilder) => {
|
||||
extraTags?.forEach(t => eb.tag(t));
|
||||
eb.kind(kind);
|
||||
return eb;
|
||||
};
|
||||
const ev = replyTo ? await publisher.reply(replyTo, note, hk) : await publisher.note(note, hk);
|
||||
if (selectedCustomRelays) selectedCustomRelays.forEach(r => System.WriteOnceToRelay(r, ev));
|
||||
else System.BroadcastEvent(ev);
|
||||
dispatch(reset());
|
||||
for (const oe of otherEvents) {
|
||||
if (selectedCustomRelays) selectedCustomRelays.forEach(r => System.WriteOnceToRelay(r, oe));
|
||||
else System.BroadcastEvent(oe);
|
||||
}
|
||||
dispatch(reset());
|
||||
}
|
||||
}
|
||||
|
||||
async function attachFile() {
|
||||
try {
|
||||
const file = await openFile();
|
||||
if (file) {
|
||||
uploadFile(file);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
dispatch(setError(error?.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFile(file: File | Blob) {
|
||||
try {
|
||||
if (file) {
|
||||
const rx = await uploader.upload(file, file.name);
|
||||
if (rx.header) {
|
||||
const link = `nostr:${encodeTLV(NostrPrefix.Event, rx.header.id, undefined, rx.header.kind)}`;
|
||||
dispatch(setNote(`${note ? `${note}\n` : ""}${link}`));
|
||||
dispatch(setOtherEvents([...otherEvents, rx.header]));
|
||||
} else if (rx.url) {
|
||||
dispatch(setNote(`${note ? `${note}\n` : ""}${rx.url}`));
|
||||
} else if (rx?.error) {
|
||||
dispatch(setError(rx.error));
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
dispatch(setError(error?.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onChange(ev: React.ChangeEvent<HTMLTextAreaElement>) {
|
||||
const { value } = ev.target;
|
||||
dispatch(setNote(value));
|
||||
if (value) {
|
||||
dispatch(setActive(true));
|
||||
} else {
|
||||
dispatch(setActive(false));
|
||||
}
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
dispatch(reset());
|
||||
}
|
||||
|
||||
async function onSubmit(ev: React.MouseEvent<HTMLButtonElement>) {
|
||||
ev.stopPropagation();
|
||||
await sendNote();
|
||||
}
|
||||
|
||||
async function loadPreview() {
|
||||
if (preview) {
|
||||
dispatch(setPreview(undefined));
|
||||
} else if (publisher) {
|
||||
const tmpNote = await publisher.note(note);
|
||||
if (tmpNote) {
|
||||
dispatch(setPreview(tmpNote));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPreviewNote() {
|
||||
if (preview) {
|
||||
return (
|
||||
<Note
|
||||
data={preview as TaggedNostrEvent}
|
||||
related={[]}
|
||||
options={{
|
||||
showContextMenu: false,
|
||||
showFooter: false,
|
||||
canClick: false,
|
||||
showTime: false,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function renderPollOptions() {
|
||||
if (pollOptions) {
|
||||
return (
|
||||
<>
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Poll Options" />
|
||||
</h4>
|
||||
{pollOptions?.map((a, i) => (
|
||||
<div className="form-group w-max" key={`po-${i}`}>
|
||||
<div>
|
||||
<FormattedMessage defaultMessage="Option: {n}" values={{ n: i + 1 }} />
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" value={a} onChange={e => changePollOption(i, e.target.value)} />
|
||||
{i > 1 && (
|
||||
<button onClick={() => removePollOption(i)} className="ml5">
|
||||
<Icon name="close" size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<button onClick={() => dispatch(setPollOptions([...pollOptions, ""]))}>
|
||||
<Icon name="plus" size={14} />
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function changePollOption(i: number, v: string) {
|
||||
if (pollOptions) {
|
||||
const copy = [...pollOptions];
|
||||
copy[i] = v;
|
||||
dispatch(setPollOptions(copy));
|
||||
}
|
||||
}
|
||||
|
||||
function removePollOption(i: number) {
|
||||
if (pollOptions) {
|
||||
const copy = [...pollOptions];
|
||||
copy.splice(i, 1);
|
||||
dispatch(setPollOptions(copy));
|
||||
}
|
||||
}
|
||||
|
||||
function renderRelayCustomisation() {
|
||||
return (
|
||||
<div className="flex-column g8">
|
||||
{Object.keys(relays.item || {})
|
||||
.filter(el => relays.item[el].write)
|
||||
.map((r, i, a) => (
|
||||
<div className="p flex f-space note-creator-relay">
|
||||
<div>{r}</div>
|
||||
<div>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!selectedCustomRelays || selectedCustomRelays.includes(r)}
|
||||
onChange={e =>
|
||||
dispatch(
|
||||
setSelectedCustomRelays(
|
||||
// set false if all relays selected
|
||||
e.target.checked && selectedCustomRelays && selectedCustomRelays.length == a.length - 1
|
||||
? false
|
||||
: // otherwise return selectedCustomRelays with target relay added / removed
|
||||
a.filter(el =>
|
||||
el === r ? e.target.checked : !selectedCustomRelays || selectedCustomRelays.includes(el)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function listAccounts() {
|
||||
return LoginStore.getSessions().map(a => (
|
||||
<MenuItem
|
||||
onClick={ev => {
|
||||
ev.stopPropagation = true;
|
||||
LoginStore.switchAccount(a);
|
||||
}}>
|
||||
<ProfileImage pubkey={a} link={""} />
|
||||
</MenuItem>
|
||||
));
|
||||
}
|
||||
|
||||
const handlePaste: ClipboardEventHandler<HTMLDivElement> = evt => {
|
||||
if (evt.clipboardData) {
|
||||
const clipboardItems = evt.clipboardData.items;
|
||||
const items: DataTransferItem[] = Array.from(clipboardItems).filter(function (item: DataTransferItem) {
|
||||
// Filter the image items only
|
||||
return /^image\//.test(item.type);
|
||||
});
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const item = items[0];
|
||||
const blob = item.getAsFile();
|
||||
if (blob) {
|
||||
uploadFile(blob);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{show && (
|
||||
<Modal className="note-creator-modal" onClose={() => dispatch(setShow(false))}>
|
||||
{replyTo && (
|
||||
<Note
|
||||
data={replyTo}
|
||||
related={[]}
|
||||
options={{
|
||||
showFooter: false,
|
||||
showContextMenu: false,
|
||||
showTime: false,
|
||||
canClick: false,
|
||||
showMedia: false,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{preview && getPreviewNote()}
|
||||
{!preview && (
|
||||
<div onPaste={handlePaste} className={`note-creator${pollOptions ? " poll" : ""}`}>
|
||||
<Textarea
|
||||
autoFocus
|
||||
className={`textarea ${active ? "textarea--focused" : ""}`}
|
||||
onChange={onChange}
|
||||
value={note}
|
||||
onFocus={() => dispatch(setActive(true))}
|
||||
onKeyDown={e => {
|
||||
if (e.key === "Enter" && e.metaKey) {
|
||||
sendNote().catch(console.warn);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{renderPollOptions()}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex f-space">
|
||||
<div className="flex g8">
|
||||
<ProfileImage pubkey={login.publicKey ?? ""} className="note-creator-icon" link="" showUsername={false} />
|
||||
{pollOptions === undefined && !replyTo && (
|
||||
<div className="note-creator-icon">
|
||||
<Icon name="pie-chart" onClick={() => dispatch(setPollOptions(["A", "B"]))} size={24} />
|
||||
</div>
|
||||
)}
|
||||
<AsyncIcon iconName="image-plus" iconSize={24} onClick={attachFile} className="note-creator-icon" />
|
||||
<button className="secondary" onClick={() => dispatch(setShowAdvanced(!showAdvanced))}>
|
||||
<FormattedMessage defaultMessage="Advanced" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex g8">
|
||||
<button className="secondary" onClick={cancel}>
|
||||
<FormattedMessage defaultMessage="Cancel" />
|
||||
</button>
|
||||
<AsyncButton onClick={onSubmit}>
|
||||
{replyTo ? <FormattedMessage defaultMessage="Reply" /> : <FormattedMessage defaultMessage="Send" />}
|
||||
</AsyncButton>
|
||||
</div>
|
||||
</div>
|
||||
{error && <span className="error">{error}</span>}
|
||||
{showAdvanced && (
|
||||
<>
|
||||
<button className="secondary" onClick={loadPreview}>
|
||||
<FormattedMessage defaultMessage="Toggle Preview" />
|
||||
</button>
|
||||
<div>
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Custom Relays" />
|
||||
</h4>
|
||||
<p>
|
||||
<FormattedMessage defaultMessage="Send note to a subset of your write relays" />
|
||||
</p>
|
||||
{renderRelayCustomisation()}
|
||||
</div>
|
||||
<div className="flex-column g8">
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Forward Zaps" />
|
||||
</h4>
|
||||
<FormattedMessage defaultMessage="All zaps sent to this note will be received by the following LNURL" />
|
||||
<input
|
||||
type="text"
|
||||
className="w-max"
|
||||
placeholder={formatMessage({
|
||||
defaultMessage: "LNURL to forward zaps to",
|
||||
})}
|
||||
value={zapForward}
|
||||
onChange={e => dispatch(setZapForward(e.target.value))}
|
||||
/>
|
||||
<span className="warning">
|
||||
<FormattedMessage defaultMessage="Not all clients support this yet" />
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex-column g8">
|
||||
<h4>
|
||||
<FormattedMessage defaultMessage="Sensitive Content" />
|
||||
</h4>
|
||||
<FormattedMessage defaultMessage="Users must accept the content warning to show the content of your note." />
|
||||
<input
|
||||
className="w-max"
|
||||
type="text"
|
||||
value={sensitive}
|
||||
onChange={e => dispatch(setSensitive(e.target.value))}
|
||||
maxLength={50}
|
||||
minLength={1}
|
||||
placeholder={formatMessage({
|
||||
defaultMessage: "Reason",
|
||||
})}
|
||||
/>
|
||||
<span className="warning">
|
||||
<FormattedMessage defaultMessage="Not all clients support this yet" />
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user