Skip to content

Commit 30c9e5e

Browse files
authored
Merge pull request #40 from line/appearances-for-mini
Appearances for MINI
2 parents 41d8f2c + 12f3c52 commit 30c9e5e

11 files changed

+67
-24
lines changed
File renamed without changes.

public/assets/qr_mini.png

16.8 KB
Loading

public/assets/qr_mini_preview.png

17.1 KB
Loading

src/App.module.css

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ body {
2121
height: auto;
2222
}
2323

24+
.applicationNotice {
25+
color: #777777;
26+
font-size: 15px;
27+
}
28+
2429
@media only screen and (max-width: 375px) {
2530
.container {
2631
width: auto;

src/App.tsx

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
import React from 'react'
1+
import React, { useContext } from 'react'
22
import liff from '@line/liff'
33
import styles from './App.module.css'
44
import Header from './components/Header'
55
import Snippet from './components/Snippet'
66
import Input from './components/Input'
7-
import { FilterContext, FilterType } from './Context'
8-
import qrCode from './qr-code.png'
9-
import { SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST } from './constants'
7+
import { SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST, QR_IMG_MAP } from './constants'
108
import { FilterTypes } from './FilterTypes'
9+
import { AppContext } from './Context'
1110

12-
type Props = {
13-
appUrl: string
14-
filter: FilterType
15-
}
11+
function App() {
12+
const { appUrl, filter } = useContext(AppContext)
1613

17-
function App({ appUrl, filter }: Props) {
1814
let isLoggedIn = false
1915
try {
2016
isLoggedIn = liff.isLoggedIn()
2117
} catch (e) {
2218
console.log(e)
2319
}
20+
2421
return (
25-
<FilterContext.Provider value={filter}>
22+
<>
2623
<Header />
2724
<div className={styles.container}>
25+
{filter === FilterTypes.MINI || filter === FilterTypes.MINI_PREVIEW ? (
26+
<div className={styles.applicationNotice}>
27+
本「LINEミニアプリプレイグラウンド」は日本限定のサービスです。
28+
<br />
29+
This “LINE MINI App Playground” is available only in Japan.
30+
</div>
31+
) : null}
2832
<div className={styles.liffIdBox}>
2933
<Input readonly value={`URL: ${appUrl}`} />
30-
<img src={qrCode} className={styles.qrCode} />
34+
<img src={QR_IMG_MAP[filter]} className={styles.qrCode} />
3135
</div>
3236
<h1>Client APIs</h1>
3337
{!isLoggedIn ? (
@@ -226,7 +230,9 @@ function App({ appUrl, filter }: Props) {
226230
docUrl="https://developers.line.biz/en/reference/liff/#share-target-picker"
227231
needRequestPayload={true}
228232
hideResponse={true}
229-
defaultRequestPayload={SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST[0].value}
233+
defaultRequestPayload={
234+
SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST[0].value
235+
}
230236
pulldownOptions={SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST}
231237
skipAutoRun={true}
232238
runner={async (options) => {
@@ -308,7 +314,7 @@ function App({ appUrl, filter }: Props) {
308314
)}
309315
runner={async (payload) => {
310316
const parsed = JSON.parse(payload)
311-
await liff.createShortcutOnHomeScreen(parsed);
317+
await liff.createShortcutOnHomeScreen(parsed)
312318
}}
313319
skipAutoRun={true}
314320
isInLIFF={false}
@@ -353,7 +359,7 @@ function App({ appUrl, filter }: Props) {
353359
</>
354360
)}
355361
</div>
356-
</FilterContext.Provider>
362+
</>
357363
)
358364
}
359365

src/Context.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ import { FilterTypes } from './FilterTypes'
33

44
export type FilterType = keyof typeof FilterTypes
55

6-
export const FilterContext = React.createContext<FilterType>(FilterTypes.LIFF)
6+
export const AppContext = React.createContext<{
7+
filter: FilterType,
8+
appId: string,
9+
appUrl: string
10+
}>({
11+
filter: FilterTypes.LIFF,
12+
appId: import.meta.env.VITE_LIFF_ID,
13+
appUrl: `https://liff.line.me/${import.meta.env.VITE_LIFF_ID}`
14+
})

src/components/Header.module.css

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
align-items: center;
1818
}
1919

20+
.left {
21+
flex: 1;
22+
}
23+
2024
.left a {
2125
text-decoration: none;
2226
color: #000;
@@ -41,4 +45,7 @@
4145
.gitHubButton {
4246
display: none;
4347
}
48+
.right {
49+
flex-basis: 100px;
50+
}
4451
}

src/components/Header.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import liff from '@line/liff'
2-
import React from 'react'
2+
import React, { useContext, useMemo } from 'react'
33
import styles from './Header.module.css'
44
import Button from './Button'
5+
import { AppContext } from '../Context'
56

67
export default function Header() {
8+
const {filter, appId} = useContext(AppContext);
9+
const appName = useMemo(() => {
10+
return filter === 'LIFF' ? 'LIFF Playground' : 'LINE MINI App Playground'
11+
}, [filter])
12+
713
const openGitHub = () => {
814
window.open(`https://github.com/line/liff-playground`, '_blank')
915
}
1016

1117
const openInApp = () => {
1218
window.open(
13-
`https://line.me/R/app/${import.meta.env.VITE_LIFF_ID}`,
19+
`https://line.me/R/app/${appId}`,
1420
'_blank'
1521
)
1622
}
@@ -20,7 +26,7 @@ export default function Header() {
2026
<div className={styles.header}>
2127
<div className={styles.left}>
2228
<a href='/'>
23-
<h1>LIFF Playground</h1>
29+
<h1>{appName}</h1>
2430
</a>
2531
</div>
2632
<div className={styles.right}>

src/components/Snippet.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Input from './Input'
44
import styles from './Snippet.module.css'
55
import Tag from './Tag'
66
import TextArea from './TextArea'
7-
import { FilterContext } from '../Context'
7+
import { AppContext } from '../Context'
88
import { FilterTypes } from '../FilterTypes'
99
import Pulldown from './Pulldown'
1010

@@ -74,8 +74,8 @@ export default function Snippet({
7474
}, [skipAutoRun, callRunner])
7575

7676
return (
77-
<FilterContext.Consumer>
78-
{(filter) =>
77+
<AppContext.Consumer>
78+
{({ filter }) =>
7979
((filter === FilterTypes.LIFF && isInLIFF) ||
8080
(filter === FilterTypes.MINI && isInMINI)) && (
8181
<div className={styles.snippet}>
@@ -154,6 +154,6 @@ export default function Snippet({
154154
</div>
155155
)
156156
}
157-
</FilterContext.Consumer>
157+
</AppContext.Consumer>
158158
)
159159
}

src/constants.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const base = new URL(location.href).origin;
1+
import { FilterTypes } from "./FilterTypes"
2+
3+
const base = new URL(location.href).origin
24
export const SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST = [
35
{
46
label: 'text',
@@ -54,3 +56,9 @@ export const SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST = [
5456
label,
5557
value: JSON.stringify(value, null, 4),
5658
}))
59+
60+
export const QR_IMG_MAP = {
61+
[FilterTypes.LIFF]: `${base}/assets/qr_liff.png`,
62+
[FilterTypes.MINI]: `${base}/assets/qr_mini.png`,
63+
[FilterTypes.MINI_PREVIEW]: `${base}/assets/qr_mini_preview.png`,
64+
}

src/main.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { LiffCommonProfilePlugin } from '@line/liff-common-profile-plugin'
55
import './main.css'
66
import App from './App'
77
import { FilterTypes } from './FilterTypes'
8+
import { AppContext } from './Context'
89

910
const isMINI = new URLSearchParams(location.search).has('mini')
1011
const isPreviewMINI = new URLSearchParams(location.search).has('mini_preview')
@@ -39,7 +40,9 @@ liff
3940
.then(() => {
4041
ReactDOM.render(
4142
<React.StrictMode>
42-
<App appUrl={appUrl} filter={filter} />
43+
<AppContext.Provider value={{ filter, appId, appUrl }}>
44+
<App />
45+
</AppContext.Provider>
4346
</React.StrictMode>,
4447
document.getElementById('root')
4548
)

0 commit comments

Comments
 (0)