-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement pop window and responsive design (#452)
- Loading branch information
Showing
39 changed files
with
323 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/adena-extension/src/common/constants/storage.constant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const WALLET_EXPORT_TYPE_STORAGE_KEY = 'WALLET_EXPORT_TYPE' as const; | ||
export const WALLET_EXPORT_ACCOUNT_ID = 'WALLET_EXPORT_ACCOUNT_ID' as const; | ||
export const QUESTIONNAIRE_EXPIRATION_MIN = 30 * 24 * 60; | ||
export const POPUP_SESSION_DATA_KEY = 'POPUP_SESSION_DATA' as const; |
10 changes: 10 additions & 0 deletions
10
packages/adena-extension/src/common/constants/ui.constant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
// Web Constants | ||
export const WEB_CONTENT_WIDTH = 552 as const; | ||
export const WEB_TOP_SPACING = 272 as const; | ||
export const WEB_TOP_SPACING_RESPONSIVE = 150 as const; | ||
|
||
// Responsive Sizes | ||
export const RESPONSIVE_EXTENSION_WIDTH = 650 as const; | ||
|
||
// Popup Constants | ||
export const POPUP_WIDTH = 380 as const; | ||
export const POPUP_HEIGHT = 590 as const; | ||
|
||
export const WINDOW_EXPAND_SIZE = 650 as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/adena-extension/src/common/utils/browser-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { POPUP_SESSION_DATA_KEY } from '@common/constants/storage.constant'; | ||
import { POPUP_HEIGHT, POPUP_WIDTH } from '@common/constants/ui.constant'; | ||
import { ChromeSessionStorage } from '@common/storage/chrome-session-storage'; | ||
|
||
export const createPopupWindow = async (popupPath: string, state: object = {}): Promise<void> => { | ||
const popupOption: chrome.windows.CreateData = { | ||
url: chrome.runtime.getURL(`popup.html#${popupPath}`), | ||
type: 'popup', | ||
width: POPUP_WIDTH, | ||
height: POPUP_HEIGHT, | ||
}; | ||
new ChromeSessionStorage().set(POPUP_SESSION_DATA_KEY, JSON.stringify(state)).then(() => { | ||
chrome.windows.create(popupOption, async (windowResponse) => { | ||
window?.close(); | ||
chrome.tabs.onUpdated.addListener(() => { | ||
if (!windowResponse) { | ||
return; | ||
} | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { ChromeSessionStorage } from '@common/storage/chrome-session-storage'; | ||
import { POPUP_SESSION_DATA_KEY } from '@common/constants/storage.constant'; | ||
import { RouteParams } from '@types'; | ||
import useAppNavigate from './use-app-navigate'; | ||
|
||
const useSessionParams = <RouteName extends keyof RouteParams>(): { | ||
isPopup: boolean | null; | ||
params: RouteParams[RouteName] | null; | ||
isLoading: boolean; | ||
} => { | ||
const { params } = useAppNavigate<RouteName>(); | ||
const { data: isPopup = null } = useQuery( | ||
['popup/isPopup', chrome.windows], | ||
async () => { | ||
try { | ||
const isPopup = (await chrome.windows.getCurrent()).type === 'popup'; | ||
return isPopup; | ||
} catch { | ||
return null; | ||
} | ||
}, | ||
{}, | ||
); | ||
|
||
const { data = null, isLoading } = useQuery( | ||
['popup/popupState', params, isPopup], | ||
async () => { | ||
if (params) { | ||
return params; | ||
} | ||
if (!isPopup) { | ||
return null; | ||
} | ||
try { | ||
const sessionState = await new ChromeSessionStorage().get(POPUP_SESSION_DATA_KEY); | ||
return JSON.parse(sessionState) as RouteParams[RouteName]; | ||
} catch { | ||
return null; | ||
} | ||
}, | ||
{}, | ||
); | ||
|
||
return { | ||
isPopup, | ||
params: data, | ||
isLoading, | ||
}; | ||
}; | ||
|
||
export default useSessionParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { WINDOW_EXPAND_SIZE } from '@common/constants/ui.constant'; | ||
import { CommonState } from '@states'; | ||
import { WindowSizeType } from '@types'; | ||
import { useEffect } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
export type UseWindowSizeReturn = { | ||
windowSizeType: WindowSizeType; | ||
}; | ||
|
||
export const useWindowSize = (init = false): UseWindowSizeReturn => { | ||
const [windowSizeType, setWindowSizeType] = useRecoilState(CommonState.windowSizeType); | ||
|
||
useEffect(() => { | ||
if (!init) { | ||
return; | ||
} | ||
if (typeof window !== 'undefined') { | ||
const handleResize = (): void => { | ||
const windowSizeType = window.innerWidth > WINDOW_EXPAND_SIZE ? 'EXPAND' : 'DEFAULT'; | ||
setWindowSizeType(windowSizeType); | ||
}; | ||
window.addEventListener('resize', handleResize); | ||
handleResize(); | ||
return () => window.removeEventListener('resize', handleResize); | ||
} else { | ||
return () => | ||
window.removeEventListener('resize', () => { | ||
return null; | ||
}); | ||
} | ||
}, []); | ||
|
||
return { windowSizeType }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,6 @@ export const Login = (): JSX.Element => { | |
</Button> | ||
</Wrapper> | ||
) : ( | ||
<div></div> | ||
<React.Fragment /> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.