polish splash screen
This commit is contained in:
46
src/app.tsx
46
src/app.tsx
@@ -15,29 +15,33 @@ import { SettingsLayout } from '@shared/settingsLayout';
|
|||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
const appLoader = async () => {
|
const appLoader = async () => {
|
||||||
const account = await getActiveAccount();
|
try {
|
||||||
const stronghold = sessionStorage.getItem('stronghold');
|
const account = await getActiveAccount();
|
||||||
const privkey = JSON.parse(stronghold).state.privkey || null;
|
const stronghold = sessionStorage.getItem('stronghold');
|
||||||
const onboarding = localStorage.getItem('onboarding');
|
const privkey = JSON.parse(stronghold).state.privkey || null;
|
||||||
const step = JSON.parse(onboarding).state.step || null;
|
const onboarding = localStorage.getItem('onboarding');
|
||||||
|
const step = JSON.parse(onboarding).state.step || null;
|
||||||
|
|
||||||
if (step) {
|
if (step) {
|
||||||
return redirect(step);
|
return redirect(step);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!account) {
|
||||||
|
return redirect('/auth/welcome');
|
||||||
|
} else {
|
||||||
|
if (account.privkey.length > 35) {
|
||||||
|
return redirect('/auth/migrate');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!privkey) {
|
||||||
|
return redirect('/auth/unlock');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error('App failed to load');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!account) {
|
|
||||||
return redirect('/auth/welcome');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (account && account.privkey.length > 35) {
|
|
||||||
return redirect('/auth/migrate');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (account && !privkey) {
|
|
||||||
return redirect('/auth/unlock');
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
|
|||||||
@@ -31,21 +31,12 @@ export function UnlockScreen() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setPrivkey = useStronghold((state) => state.setPrivkey);
|
const setPrivkey = useStronghold((state) => state.setPrivkey);
|
||||||
|
|
||||||
const [passwordInput, setPasswordInput] = useState('password');
|
const [showPassword, setShowPassword] = useState<boolean>(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
const { account } = useAccount();
|
const { account } = useAccount();
|
||||||
const { load } = useSecureStorage();
|
const { load } = useSecureStorage();
|
||||||
|
|
||||||
// toggle private key
|
|
||||||
const showPassword = () => {
|
|
||||||
if (passwordInput === 'password') {
|
|
||||||
setPasswordInput('text');
|
|
||||||
} else {
|
|
||||||
setPasswordInput('password');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
setError,
|
setError,
|
||||||
@@ -62,20 +53,19 @@ export function UnlockScreen() {
|
|||||||
setPrivkey(privkey);
|
setPrivkey(privkey);
|
||||||
// redirect to home
|
// redirect to home
|
||||||
navigate('/', { replace: true });
|
navigate('/', { replace: true });
|
||||||
} catch {
|
} catch (e) {
|
||||||
setLoading(false);
|
|
||||||
setError('password', {
|
setError('password', {
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
message: 'Wrong password',
|
message: e,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
|
||||||
setError('password', {
|
setError('password', {
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
message: 'Password is required and must be greater than 3',
|
message: 'Password is required and must be greater than 3',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -89,15 +79,15 @@ export function UnlockScreen() {
|
|||||||
<div className="relative">
|
<div className="relative">
|
||||||
<input
|
<input
|
||||||
{...register('password', { required: true })}
|
{...register('password', { required: true })}
|
||||||
type={passwordInput}
|
type={showPassword ? 'text' : 'password'}
|
||||||
className="relative h-12 w-full rounded-lg bg-white/10 py-1 text-center text-white !outline-none placeholder:text-white/10"
|
className="relative h-12 w-full rounded-lg bg-white/10 py-1 text-center text-white !outline-none placeholder:text-white/10"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => showPassword()}
|
onClick={() => setShowPassword((prev) => !prev)}
|
||||||
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 hover:bg-white/10"
|
className="group absolute right-2 top-1/2 -translate-y-1/2 transform rounded p-1 hover:bg-white/10"
|
||||||
>
|
>
|
||||||
{passwordInput === 'password' ? (
|
{showPassword ? (
|
||||||
<EyeOffIcon className="h-5 w-5 text-white/50 group-hover:text-white" />
|
<EyeOffIcon className="h-5 w-5 text-white/50 group-hover:text-white" />
|
||||||
) : (
|
) : (
|
||||||
<EyeOnIcon className="h-5 w-5 text-white/50 group-hover:text-white" />
|
<EyeOnIcon className="h-5 w-5 text-white/50 group-hover:text-white" />
|
||||||
|
|||||||
@@ -5,27 +5,30 @@ import { Link } from 'react-router-dom';
|
|||||||
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
import { ArrowRightCircleIcon } from '@shared/icons/arrowRightCircle';
|
||||||
|
|
||||||
export function WelcomeScreen() {
|
export function WelcomeScreen() {
|
||||||
useEffect(() => {
|
async function setWindow() {
|
||||||
async function setWindow() {
|
await appWindow.setSize(new LogicalSize(400, 500));
|
||||||
await appWindow.setSize(new LogicalSize(400, 500));
|
await appWindow.setResizable(false);
|
||||||
await appWindow.setResizable(false);
|
await appWindow.center();
|
||||||
await appWindow.center();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
async function resetWindow() {
|
||||||
|
await appWindow.setSize(new LogicalSize(1080, 800));
|
||||||
|
await appWindow.setResizable(false);
|
||||||
|
await appWindow.center();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
setWindow();
|
setWindow();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
appWindow.setSize(new LogicalSize(1080, 800)).then(() => {
|
resetWindow();
|
||||||
appWindow.setResizable(false);
|
|
||||||
appWindow.center();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-full flex-col justify-between bg-white/10">
|
<div className="flex h-screen w-full flex-col justify-between bg-white/10">
|
||||||
<div className="flex flex-col gap-10 pt-16">
|
<div className="flex flex-col gap-10 pt-16">
|
||||||
<div className="flex flex-col gap-2 text-center">
|
<div className="sflex flex-col gap-2 text-center">
|
||||||
<h1 className="text-3xl font-medium text-white">Welcome to Lume</h1>
|
<h1 className="text-3xl font-medium text-white">Welcome to Lume</h1>
|
||||||
<h3 className="mx-auto w-2/3 text-white/50">
|
<h3 className="mx-auto w-2/3 text-white/50">
|
||||||
Let's get you up and connecting with all peoples around the world on
|
Let's get you up and connecting with all peoples around the world on
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
|
|
||||||
import { FeedBlock } from '@app/space/components/blocks/feed';
|
|
||||||
import { HashtagBlock } from '@app/space/components/blocks/hashtag';
|
|
||||||
import { ImageBlock } from '@app/space/components/blocks/image';
|
|
||||||
import { NetworkBlock } from '@app/space/components/blocks/network';
|
|
||||||
import { ThreadBlock } from '@app/space/components/blocks/thread';
|
|
||||||
import { UserBlock } from '@app/space/components/blocks/user';
|
|
||||||
import { FeedModal } from '@app/space/components/modals/feed';
|
import { FeedModal } from '@app/space/components/modals/feed';
|
||||||
import { HashtagModal } from '@app/space/components/modals/hashtag';
|
import { HashtagModal } from '@app/space/components/modals/hashtag';
|
||||||
import { ImageModal } from '@app/space/components/modals/image';
|
import { ImageModal } from '@app/space/components/modals/image';
|
||||||
|
import { FeedBlock } from '@app/space/components/widgets/feed';
|
||||||
|
import { HashtagBlock } from '@app/space/components/widgets/hashtag';
|
||||||
|
import { ImageBlock } from '@app/space/components/widgets/image';
|
||||||
|
import { NetworkBlock } from '@app/space/components/widgets/network';
|
||||||
|
import { ThreadBlock } from '@app/space/components/widgets/thread';
|
||||||
|
import { UserBlock } from '@app/space/components/widgets/user';
|
||||||
|
|
||||||
import { LoaderIcon } from '@shared/icons';
|
import { LoaderIcon } from '@shared/icons';
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ export function SplashScreen() {
|
|||||||
const { status, account } = useAccount();
|
const { status, account } = useAccount();
|
||||||
const { fetchChats, fetchNotes } = useNostr();
|
const { fetchChats, fetchNotes } = useNostr();
|
||||||
|
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||||
const [error, setError] = useState<null | string>(null);
|
const [errorMessage, setErrorMessage] = useState<null | string>(null);
|
||||||
|
|
||||||
const skip = async () => {
|
const skip = async () => {
|
||||||
await invoke('close_splashscreen');
|
await invoke('close_splashscreen');
|
||||||
@@ -26,18 +26,24 @@ export function SplashScreen() {
|
|||||||
const step = JSON.parse(onboarding).state.step || null;
|
const step = JSON.parse(onboarding).state.step || null;
|
||||||
if (step) await invoke('close_splashscreen');
|
if (step) await invoke('close_splashscreen');
|
||||||
|
|
||||||
const notes = await fetchNotes();
|
try {
|
||||||
const chats = await fetchChats();
|
const notes = await fetchNotes();
|
||||||
|
const chats = await fetchChats();
|
||||||
|
|
||||||
if (notes.status === 'ok' && chats.status === 'ok') {
|
if (notes.status === 'ok' && chats.status === 'ok') {
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
await updateLastLogin(now);
|
await updateLastLogin(now);
|
||||||
invoke('close_splashscreen');
|
invoke('close_splashscreen');
|
||||||
} else {
|
} else {
|
||||||
setLoading(false);
|
setIsLoading(false);
|
||||||
setError(notes.message || chats.message);
|
setErrorMessage(notes.message || chats.message);
|
||||||
console.log('fetch notes failed, error: ', notes.message);
|
console.log('fetch notes failed, error: ', notes.message);
|
||||||
console.log('fetch chats failed, error: ', chats.message);
|
console.log('fetch chats failed, error: ', chats.message);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setIsLoading(false);
|
||||||
|
setErrorMessage(e);
|
||||||
|
console.log('prefetch failed, error: ', e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,7 +64,7 @@ export function SplashScreen() {
|
|||||||
<div className="flex min-h-0 w-full flex-1 items-center justify-center">
|
<div className="flex min-h-0 w-full flex-1 items-center justify-center">
|
||||||
<div className="flex flex-col items-center justify-center gap-4">
|
<div className="flex flex-col items-center justify-center gap-4">
|
||||||
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
<LoaderIcon className="h-6 w-6 animate-spin text-white" />
|
||||||
{loading ? (
|
{isLoading ? (
|
||||||
<div className="mt-2 flex flex-col gap-1 text-center">
|
<div className="mt-2 flex flex-col gap-1 text-center">
|
||||||
<h3 className="text-lg font-semibold leading-none text-white">
|
<h3 className="text-lg font-semibold leading-none text-white">
|
||||||
{!ndk
|
{!ndk
|
||||||
@@ -74,7 +80,7 @@ export function SplashScreen() {
|
|||||||
<h3 className="text-lg font-semibold leading-none text-white">
|
<h3 className="text-lg font-semibold leading-none text-white">
|
||||||
Something wrong!
|
Something wrong!
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-sm text-white/50">{error}</p>
|
<p className="text-sm text-white/50">{errorMessage}</p>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={skip}
|
onClick={skip}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export function useAccount() {
|
|||||||
['currentAccount'],
|
['currentAccount'],
|
||||||
async () => {
|
async () => {
|
||||||
const account = await getActiveAccount();
|
const account = await getActiveAccount();
|
||||||
console.log('active account: ', account);
|
console.log('account: ', account);
|
||||||
if (account?.pubkey) {
|
if (account?.pubkey) {
|
||||||
const user = ndk.getUser({ hexpubkey: account?.pubkey });
|
const user = ndk.getUser({ hexpubkey: account?.pubkey });
|
||||||
await user.fetchProfile();
|
await user.fetchProfile();
|
||||||
|
|||||||
Reference in New Issue
Block a user