diff --git a/src/components/GridView/DetailsView.tsx b/src/components/GridView/DetailsView.tsx index a586490..5293991 100644 --- a/src/components/GridView/DetailsView.tsx +++ b/src/components/GridView/DetailsView.tsx @@ -1,4 +1,4 @@ -import { NostrImage, createImgProxyUrl } from '../nostrImageDownload'; +import { NostrImage } from '../nostrImageDownload'; import './DetailsView.css'; import { useNDK } from '@nostr-dev-kit/ndk-react'; import DetailsAuthor from './DetailsAuthor'; diff --git a/src/components/SlideShow.tsx b/src/components/SlideShow.tsx index 2df266c..a71eca4 100644 --- a/src/components/SlideShow.tsx +++ b/src/components/SlideShow.tsx @@ -26,6 +26,9 @@ import IconGrid from './Icons/IconGrid'; import useNav from '../utils/useNav'; import { NDKEvent } from '@nostr-dev-kit/ndk'; import { useGlobalState } from '../utils/globalState'; +import useAutoLogin from '../utils/useAutoLogin'; + +type AlbyNostr = typeof window.nostr & { enabled: boolean }; /* FEATURES: @@ -69,6 +72,7 @@ const SlideShow = () => { const [showSettings, setShowSettings] = useState(false); const { currentSettings: settings } = useNav(); const [state, setState] = useGlobalState(); + const { autoLogin, setAutoLogin } = useAutoLogin(); const fetch = () => { if (!ndk) { @@ -127,6 +131,7 @@ const SlideShow = () => { // reset all setPosts([]); images.current = []; + clearTimeout(fetchTimeoutHandle.current); fetch(); } @@ -173,6 +178,13 @@ const SlideShow = () => { }; useEffect(() => { + setTimeout(() => { + if (autoLogin && window.nostr) { + // auto login when alby is available + onLogin(); + } + }, 500); + document.body.addEventListener('keydown', onKeyDown); return () => { document.body.removeEventListener('keydown', onKeyDown); @@ -190,6 +202,7 @@ const SlideShow = () => { } const onLogin = async () => { + setAutoLogin(true); const result = await loginWithNip07(); if (!result) { console.error('Login failed.'); @@ -201,6 +214,7 @@ const SlideShow = () => { }; const onLogout = () => { + setAutoLogin(false); setState({ userNPub: undefined, profile: undefined }); }; diff --git a/src/components/env.ts b/src/components/env.ts index 8f5c91f..3a32c23 100644 --- a/src/components/env.ts +++ b/src/components/env.ts @@ -148,6 +148,7 @@ export const adultNPubs = [ 'npub1tsrs6ptjnq5hluxawfme5sfxalfscapequm3ej0yfw65scwu8lys8q7y7l', // 💜 🔞EUPHORIA 🔞💜 'npub1fh8e9pnm8rfln0k7c6uh8wrvmva8enkdzsgzsc7v9jk97up23ewqs6kuue', // nostrporn 'npub1apr6dy5z4f0qs4cnswxj0gf37g46jxvh7xgwgs4wvzm6stu8f0asd4996r', // Anime Girl + 'npub1acwrv7aqgu949mw0zxmw2akgsjqp574nnq4vcl9wln5355q79w5ssv9qxg', // Arianna ]; export const adultPublicKeys = adultNPubs.map(npub => (nip19.decode(npub).data as string).toLowerCase()); @@ -168,7 +169,7 @@ export const defaultRelays = [ 'wss://relay.damus.io', 'wss://relay.nostr.band', 'wss://nos.lol', - 'wss://eden.nostr.land', + //'wss://eden.nostr.land', 'wss://relay.shitforce.one/', 'wss://nostr.wine', // "wss://nostr1.current.fyi/", diff --git a/src/main.tsx b/src/main.tsx index 101dfea..1e12496 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,43 +1,10 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; -import { NDKProvider } from '@nostr-dev-kit/ndk-react'; -import App from './App'; -import './index.css'; -import { defaultRelays } from './components/env'; -import { createBrowserRouter, RouterProvider } from 'react-router-dom'; import GlobalState from './utils/globalState'; - -const router = createBrowserRouter([ - { - path: '/', - element: , - }, - { - path: 'global', - element: , - }, - { - path: 'tags/:tags', - element: , - }, - { - path: 'profile/:npub', - element: , - }, - { - path: 'p/:npub', - element: , - }, - { - path: '/:npub', - element: , - }, -]); +import MainInner from './mainInner'; ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( - - - - - + + + ); diff --git a/src/mainInner.tsx b/src/mainInner.tsx new file mode 100644 index 0000000..7118773 --- /dev/null +++ b/src/mainInner.tsx @@ -0,0 +1,44 @@ +import App from './App'; +import './index.css'; +import { createBrowserRouter, RouterProvider } from 'react-router-dom'; +import { NDKProvider } from '@nostr-dev-kit/ndk-react'; +import { defaultRelays } from './components/env'; + +const MainInner = () => { + //const [state] = useGlobalState(); + + const router = createBrowserRouter([ + { + path: '/', + element: , + }, + { + path: 'global', + element: , + }, + { + path: 'tags/:tags', + element: , + }, + { + path: 'profile/:npub', + element: , + }, + { + path: 'p/:npub', + element: , + }, + { + path: '/:npub', + element: , + }, + ]); + + return ( + + + + ); +}; + +export default MainInner; diff --git a/src/utils/useAutoLogin.ts b/src/utils/useAutoLogin.ts new file mode 100644 index 0000000..5d79d33 --- /dev/null +++ b/src/utils/useAutoLogin.ts @@ -0,0 +1,28 @@ +import { useEffect, useState } from 'react'; + +declare global { + interface Window { + localStorage: any; + } +} + +const useAutoLogin = () => { + const [autoLogin, setAutoLogin] = useState(false); + + useEffect(() => { + const disclaimerAcceptedPreviously = JSON.parse(localStorage.getItem('autoLogin') as string); + if (disclaimerAcceptedPreviously === true) { + setAutoLogin(true); + } + }, []); + + return { + autoLogin, + setAutoLogin: (login: boolean) => { + setAutoLogin(login); + localStorage.setItem('autoLogin', JSON.stringify(login)); + }, + }; +}; + +export default useAutoLogin;