Skip to content

Commit

Permalink
fix: show download banner only on android
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Aug 18, 2023
1 parent 9576b51 commit d3e231f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 32 deletions.
7 changes: 7 additions & 0 deletions src/client/view/components/banner/useShowAppDownloadBanner.ts
@@ -0,0 +1,7 @@
import { useContext } from 'react';
import { EnvContext } from '../context/EnvContext';

export const useShowAppDownloadBanner = () => {
const { platform } = useContext(EnvContext);
return platform === 'android';
};
3 changes: 3 additions & 0 deletions src/client/view/components/context/EnvContext.tsx
@@ -1,15 +1,18 @@
import React, { createContext, PropsWithChildren } from 'react';
import { Platform } from '../../../../server/types/platform';

type EnvContextState = {
assetPath: string;
isMobile: boolean;
appDownloadUrl: string;
platform: Platform;
};

const initialState: EnvContextState = {
assetPath: '',
isMobile: false,
appDownloadUrl: '',
platform: 'desktop',
};

export const EnvContext = createContext(initialState);
Expand Down
28 changes: 16 additions & 12 deletions src/client/view/pages/404/index.tsx
Expand Up @@ -4,19 +4,23 @@ import { DefaultContainer } from '../../components/_common/DefaultContainer';
import { css } from '@linaria/core';
import { AppProps } from '../../types/app';
import { AppDownload } from '../../components/banner/AppDownload';
import { useShowAppDownloadBanner } from '../../components/banner/useShowAppDownloadBanner';

export const NotFoundPage = (props: AppProps) => (
<DefaultContainer {...props}>
<div className={container}>
{props.isMobile && <AppDownload />}
<WarningTemplate
iconName={'warning'}
title={'존재하지 않는 페이지에요'}
iconSize={53}
/>
</div>
</DefaultContainer>
);
export const NotFoundPage = (props: AppProps) => {
const showDownloadBanner = useShowAppDownloadBanner();
return (
<DefaultContainer {...props}>
<div className={container}>
{showDownloadBanner && <AppDownload />}
<WarningTemplate
iconName={'warning'}
title={'존재하지 않는 페이지에요'}
iconSize={53}
/>
</div>
</DefaultContainer>
);
};

const container = css`
height: 100dvh;
Expand Down
30 changes: 17 additions & 13 deletions src/client/view/pages/expired/index.tsx
Expand Up @@ -4,20 +4,24 @@ import { DefaultContainer } from '../../components/_common/DefaultContainer';
import { css } from '@linaria/core';
import { AppProps } from '../../types/app';
import { AppDownload } from '../../components/banner/AppDownload';
import { useShowAppDownloadBanner } from '../../components/banner/useShowAppDownloadBanner';

export const ExpiredPage = (props: AppProps) => (
<DefaultContainer {...props}>
<div className={container}>
{props.isMobile && <AppDownload />}
<WarningTemplate
iconName={'hourglass'}
title={'유효기간이 만료된 페이지에요'}
description={'링크는 생성된 이후 7일 동안 볼 수 있어요'}
iconSize={46}
/>
</div>
</DefaultContainer>
);
export const ExpiredPage = (props: AppProps) => {
const showDownloadBanner = useShowAppDownloadBanner();
return (
<DefaultContainer {...props}>
<div className={container}>
{showDownloadBanner && <AppDownload />}
<WarningTemplate
iconName={'hourglass'}
title={'유효기간이 만료된 페이지에요'}
description={'링크는 생성된 이후 7일 동안 볼 수 있어요'}
iconSize={46}
/>
</div>
</DefaultContainer>
);
};

const container = css`
height: 100dvh;
Expand Down
8 changes: 4 additions & 4 deletions src/client/view/pages/share/index.tsx
@@ -1,20 +1,20 @@
import React, { CSSProperties, useContext } from 'react';
import React, { CSSProperties } from 'react';
import { css } from '@linaria/core';
import { useSelector } from 'react-redux';
import { RootState } from '../../../stores/createStore';
import { HeaderSection } from '../../components/HeaderSection';
import { Table } from '../../components/table/Table';
import { TABLE_SIZE } from '../../constants/table';
import { AppDownload } from '../../components/banner/AppDownload';
import { EnvContext } from '../../components/context/EnvContext';
import { useShowAppDownloadBanner } from '../../components/banner/useShowAppDownloadBanner';

export const BandalartSharePage = () => {
const detail = useSelector((state: RootState) => state.bandalartDetail);
const treeRoot = useSelector((state: RootState) => state.bandalartTree)!;

const completionRatio = treeRoot.completionRatio;

const { isMobile } = useContext(EnvContext);
const showDownloadBanner = useShowAppDownloadBanner();

return (
<div
Expand All @@ -26,7 +26,7 @@ export const BandalartSharePage = () => {
} as CSSProperties
}
>
{isMobile && <AppDownload />}
{showDownloadBanner && <AppDownload />}
<HeaderSection detail={detail} completionRatio={completionRatio} />
<main className={mainStyle}>
<Table root={treeRoot} />
Expand Down
3 changes: 3 additions & 0 deletions src/client/view/types/app.ts
@@ -1,5 +1,8 @@
import { Platform } from '../../../server/types/platform';

export type AppProps = {
assetPath: string;
isMobile: boolean;
appDownloadUrl: string;
platform: Platform;
};
32 changes: 29 additions & 3 deletions src/server/route/viewRoute.ts
Expand Up @@ -6,17 +6,41 @@ import { createStore } from '../../client/stores/createStore';
import { initApiClient } from '../../agent/ApiClient';
import { Context } from 'koa';
import { isAxiosError } from 'axios';
import { AppProps } from '../../client/view/types/app';
import { Platform } from '../types/platform';

const viewRouter = new Router();

const createAppProps = ({ isMobile }: { isMobile: boolean }) => ({
const createAppProps = ({
isMobile,
platform,
}: {
isMobile: boolean;
platform: Platform;
}): AppProps => ({
assetPath: process.env.ASSET_PATH ?? '',
appDownloadUrl: process.env.APP_DOWNLOAD_URL || '',
platform,
isMobile,
});

const getPlatform = (ctx: Context): Platform => {
const ua = ctx.userAgent;
if (ua.isMobile) {
if (ua.isAndroid) {
return 'android';
} else if (ua.iPhone) {
return 'ios';
}
}
return 'desktop';
};

viewRouter.get('/share/:key', async (ctx) => {
const appProps = createAppProps({ isMobile: ctx.userAgent.isMobile });
const appProps = createAppProps({
isMobile: ctx.userAgent.isMobile,
platform: getPlatform(ctx),
});
try {
initApiClient();
const key = ctx.params.key;
Expand Down Expand Up @@ -51,5 +75,7 @@ viewRouter.get('/health', (ctx) => {
export default viewRouter;
export const fallback = (ctx: Context) => {
const isMobile = ctx.userAgent.isMobile;
ctx.response.body = renderNotFound(createAppProps({ isMobile }));
ctx.response.body = renderNotFound(
createAppProps({ isMobile, platform: getPlatform(ctx) }),
);
};
2 changes: 2 additions & 0 deletions src/server/types/platform.ts
@@ -0,0 +1,2 @@
const PLATFORM_LIST = ['ios', 'android', 'desktop'];
export type Platform = (typeof PLATFORM_LIST)[number];

0 comments on commit d3e231f

Please sign in to comment.