Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
feat: add windowless frame
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Sep 25, 2020
1 parent 344afbb commit 26a99ad
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</script>
</head>
<body>
<div class="draggable-bar"></div>
<div id="root"></div>
<script>
if (typeof process === 'object') {
Expand Down
2 changes: 1 addition & 1 deletion app/components/onboarding/onboarding-back-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const OnboardingBackButton: React.FC<OnboardingBackButton> = props => (
width="32px"
height="32px"
type="button"
top="20px"
top="60px"
left="20px"
style={{
position: 'absolute',
Expand Down
12 changes: 12 additions & 0 deletions app/hooks/use-back-url.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect, useContext } from 'react';
import { BackContext } from '../pages/root';

export function useBackButton(urlToGoBackTo?: string | null) {
const { backUrl, setBackUrl } = useContext(BackContext);
useEffect(() => {
if (!urlToGoBackTo) return;
setBackUrl(urlToGoBackTo);
return () => setBackUrl(null);
}, [setBackUrl, urlToGoBackTo]);
return backUrl;
}
1 change: 1 addition & 0 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const createWindow = async () => {
show: false,
width: 1024,
height: 728,
titleBarStyle: 'hiddenInset',
webPreferences:
// SECURITY: Remove node env
process.env.NODE_ENV === 'development' || process.env.E2E_BUILD === 'true'
Expand Down
2 changes: 2 additions & 0 deletions app/pages/onboarding/01-welcome/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
OnboardingButton,
OnboardingText,
} from '../../../components/onboarding';
import { useBackButton } from '../../../hooks/use-back-url.hook';

export const Welcome: React.FC = () => {
const history = useHistory();
useBackButton(null);
return (
<Onboarding>
<OnboardingTitle>Stacks Wallet</OnboardingTitle>
Expand Down
2 changes: 2 additions & 0 deletions app/pages/onboarding/02-create-wallet/create-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import {
OnboardingFooterLink,
OnboardingBackButton,
} from '../../../components/onboarding';
import { useBackButton } from '../../../hooks/use-back-url.hook';

export const CreateWallet: React.FC = () => {
const dispatch = useDispatch();
const history = useHistory();
useBackButton(routes.WELCOME);

const createSoftwareWallet = () => {
dispatch(onboardingMnemonicGenerationStep({ stepDelayMs: 1_500 }));
Expand Down
2 changes: 2 additions & 0 deletions app/pages/onboarding/03-restore-wallet/restore-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ErrorLabel } from '../../../components/error-label';
import { ErrorText } from '../../../components/error-text';
import { persistMnemonic } from '../../../store/keys/keys.actions';
import { safeAwait } from '../../../utils/safe-await';
import { useBackButton } from '../../../hooks/use-back-url.hook';
import {
Onboarding,
OnboardingTitle,
Expand All @@ -24,6 +25,7 @@ export const RestoreWallet: React.FC = () => {
const [mnemonic, setMnemonic] = useState('');
const [error, setError] = useState<string | null>(null);
const history = useHistory();
useBackButton(routes.WELCOME);
const dispatch = useDispatch();

const handleMnemonicInput = (e: React.FormEvent<HTMLInputElement>) => {
Expand Down
2 changes: 2 additions & 0 deletions app/pages/onboarding/05-secret-key/secret-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import {
OnboardingBackButton,
} from '../../../components/onboarding';
import { selectMnemonic } from '../../../store/keys/keys.reducer';
import { useBackButton } from '../../../hooks/use-back-url.hook';

const COPY_TOAST_TIMEOUT = 2_500;

export const SecretKey: React.FC = () => {
const history = useHistory();
useBackButton(routes.CREATE);
const [copied, setCopiedState] = useState(false);
const mnemonic = useSelector(selectMnemonic);

Expand Down
2 changes: 2 additions & 0 deletions app/pages/onboarding/06-save-key/save-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
OnboardingBackButton,
} from '../../../components/onboarding';
import { Collapse, onboardingFaq } from '../../../components/secret-key-faq';
import { useBackButton } from '../../../hooks/use-back-url.hook';

export const SaveKey: React.FC = () => {
const history = useHistory();
useBackButton(routes.SECRET_KEY);
return (
<Onboarding>
<OnboardingTitle>Save your Secret Key</OnboardingTitle>
Expand Down
2 changes: 2 additions & 0 deletions app/pages/onboarding/07-verify-key/verify-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import routes from '../../../constants/routes.json';
import { selectMnemonic } from '../../../store/keys';
import { ErrorLabel } from '../../../components/error-label';
import { ErrorText } from '../../../components/error-text';
import { useBackButton } from '../../../hooks/use-back-url.hook';
import {
Onboarding,
OnboardingTitle,
Expand All @@ -20,6 +21,7 @@ import {

export const VerifyKey: React.FC = () => {
const history = useHistory();
useBackButton(routes.SECRET_KEY);
const mnemonic = useSelector(selectMnemonic);
const [inputMnemonic, setInputMnemonic] = useState('');
const [hasSubmitted, setHasSubmitted] = useState(false);
Expand Down
39 changes: 32 additions & 7 deletions app/pages/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState, createContext } from 'react';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'connected-react-router';
import { createGlobalStyle } from 'styled-components';
Expand All @@ -16,24 +16,49 @@ const GlobalStyle = createGlobalStyle`
min-height: 100vh;
max-height: 100vh;
}
.draggable-bar {
position: absolute;
height: 44px;
width: 100%;
z-index: 9;
padding-left: 90px;
box-shadow: 0px 1px 2px rgba(15, 17, 23, 0.08);
-webkit-user-select: none;
-webkit-app-region: drag;
}
`;

interface RootProps {
store: Store;
history: History;
}

interface BackContext {
backUrl: null | string;
setBackUrl(url: null | string): void;
}

export const BackContext = createContext<BackContext>({
backUrl: null,
// eslint-disable-next-line @typescript-eslint/no-empty-function
setBackUrl: (_url: string) => {},
});

function Root({ store, history }: RootProps) {
const [backUrl, setBackUrl] = useState<string | null>(null);

useEffect(() => void loadFonts(), []);

return (
<Provider store={store}>
<CSSReset />
<GlobalStyle />
<NetworkMessage />
<ConnectedRouter history={history}>
<Routes />
</ConnectedRouter>
<BackContext.Provider value={{ backUrl, setBackUrl }}>
<CSSReset />
<GlobalStyle />
<NetworkMessage />
<ConnectedRouter history={history}>
<Routes />
</ConnectedRouter>
</BackContext.Provider>
</Provider>
);
}
Expand Down
7 changes: 5 additions & 2 deletions app/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { useStore } from 'react-redux';
import React, { useContext } from 'react';
import ReactDOM from 'react-dom';
import { Switch, Route, Redirect } from 'react-router-dom';
import { useHistory } from 'react-router';
import { useStore } from 'react-redux';
import { Button, ArrowIcon } from '@blockstack/ui';

import routes from './constants/routes.json';
import { Home } from './pages/home/home';
Expand Down

0 comments on commit 26a99ad

Please sign in to comment.