Skip to content

Commit 41d8f2c

Browse files
authored
Merge pull request #39 from line/add-apis
Provide a UI where the API for the MINI can be tried out
2 parents 6a91d29 + 6d8cd77 commit 41d8f2c

File tree

7 files changed

+647
-555
lines changed

7 files changed

+647
-555
lines changed

.env

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
VITE_LIFF_ID=1656508316-k7jNojXm
2-
3-
# TODO
4-
VITE_LIFF_ID_MINI=
1+
VITE_LIFF_ID=2006142821-boxjqY7m
2+
VITE_LIFF_ID_MINI=2006593963-DPoAqdzG
3+
VITE_LIFF_ID_MINI_PREVIEW=2006593962-KMmZJVxl

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"lint": "eslint \"src/**/*.{ts,tsx}\""
1616
},
1717
"dependencies": {
18-
"@line/liff": "2.23.1",
18+
"@line/liff": "2.25.1",
19+
"@line/liff-common-profile-plugin": "0.1.0",
1920
"react": "^17.0.2",
2021
"react-dom": "^17.0.2"
2122
},

src/App.tsx

+67-20
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import Input from './components/Input'
77
import { FilterContext, FilterType } from './Context'
88
import qrCode from './qr-code.png'
99
import { SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST } from './constants'
10+
import { FilterTypes } from './FilterTypes'
1011

1112
type Props = {
12-
filter: FilterType;
13-
};
13+
appUrl: string
14+
filter: FilterType
15+
}
1416

15-
function App({ filter }: Props) {
17+
function App({ appUrl, filter }: Props) {
1618
let isLoggedIn = false
1719
try {
1820
isLoggedIn = liff.isLoggedIn()
@@ -24,10 +26,7 @@ function App({ filter }: Props) {
2426
<Header />
2527
<div className={styles.container}>
2628
<div className={styles.liffIdBox}>
27-
<Input
28-
readonly
29-
value={`LIFF URL: https://liff.line.me/${import.meta.env.VITE_LIFF_ID.toString()}`}
30-
/>
29+
<Input readonly value={`URL: ${appUrl}`} />
3130
<img src={qrCode} className={styles.qrCode} />
3231
</div>
3332
<h1>Client APIs</h1>
@@ -292,22 +291,70 @@ function App({ filter }: Props) {
292291
return await liff.permanentLink.createUrlBy(url)
293292
}}
294293
/>
295-
<Snippet
296-
apiName="liff.i18n.setLang"
297-
version="2.21.0"
298-
docUrl="https://developers.line.biz/ja/reference/liff/#i18n-set-lang"
299-
needRequestPayload={true}
300-
skipAutoRun={true}
301-
hideResponse={true}
302-
defaultRequestPayload={'en'}
303-
runner={async (lang) => {
304-
return await liff.i18n.setLang(lang)
305-
}}
306-
/>
294+
{(filter === FilterTypes.MINI ||
295+
filter === FilterTypes.MINI_PREVIEW) && (
296+
<>
297+
<Snippet
298+
apiName="liff.createShortcutOnHomeScreen"
299+
version="2.23.0"
300+
docUrl="https://developers.line.biz/en/reference/liff/#create-shortcut-on-home-screen"
301+
needRequestPayload={true}
302+
defaultRequestPayload={JSON.stringify(
303+
{
304+
url: appUrl,
305+
},
306+
null,
307+
4
308+
)}
309+
runner={async (payload) => {
310+
const parsed = JSON.parse(payload)
311+
await liff.createShortcutOnHomeScreen(parsed);
312+
}}
313+
skipAutoRun={true}
314+
isInLIFF={false}
315+
/>
316+
<Snippet
317+
apiName="liff.$commonProfile.getDummy"
318+
version="2.19.0"
319+
docUrl="https://developers.line.biz/en/docs/partner-docs/quick-fill/overview/"
320+
needRequestPayload={true}
321+
defaultRequestPayload={JSON.stringify(
322+
[
323+
[
324+
'family-name',
325+
'given-name',
326+
'family-name-kana',
327+
'given-name-kana',
328+
'sex-enum',
329+
'bday-year',
330+
'bday-month',
331+
'bday-day',
332+
'tel',
333+
'email',
334+
'postal-code',
335+
'address-level1',
336+
'address-level2',
337+
'address-level3',
338+
'address-level4',
339+
],
340+
1,
341+
],
342+
null,
343+
4
344+
)}
345+
runner={async (p) => {
346+
const payload = JSON.parse(p)
347+
return await liff.$commonProfile.getDummy(...payload)
348+
}}
349+
inClientOnly={true}
350+
skipAutoRun={true}
351+
isInLIFF={false}
352+
/>
353+
</>
354+
)}
307355
</div>
308356
</FilterContext.Provider>
309357
)
310358
}
311359

312-
313360
export default App

src/FilterTypes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const FilterTypes = {
22
LIFF: 'LIFF',
3-
MINI: 'MINI'
3+
MINI: 'MINI',
4+
MINI_PREVIEW: 'MINI_PREVIEW'
45
} as const

src/main.tsx

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
import liff from '@line/liff'
22
import React from 'react'
33
import ReactDOM from 'react-dom'
4+
import { LiffCommonProfilePlugin } from '@line/liff-common-profile-plugin'
45
import './main.css'
56
import App from './App'
67
import { FilterTypes } from './FilterTypes'
78

89
const isMINI = new URLSearchParams(location.search).has('mini')
9-
const filter = isMINI ? FilterTypes.MINI : FilterTypes.LIFF
10-
const liffId = isMINI ? import.meta.env.VITE_LIFF_ID_MINI : import.meta.env.VITE_LIFF_ID
10+
const isPreviewMINI = new URLSearchParams(location.search).has('mini_preview')
11+
12+
const filter = isPreviewMINI
13+
? FilterTypes.MINI_PREVIEW
14+
: isMINI
15+
? FilterTypes.MINI
16+
: FilterTypes.LIFF
17+
18+
const appId = {
19+
[FilterTypes.LIFF]: import.meta.env.VITE_LIFF_ID,
20+
[FilterTypes.MINI]: import.meta.env.VITE_LIFF_ID_MINI,
21+
[FilterTypes.MINI_PREVIEW]: import.meta.env.VITE_LIFF_ID_MINI_PREVIEW
22+
}[filter]
23+
24+
const appUrl =
25+
filter === FilterTypes.LIFF
26+
? `https://liff.line.me/${appId}`
27+
: `https://miniapp.line.me/${appId}`
28+
29+
const injectPlugins = () => {
30+
liff.use(new LiffCommonProfilePlugin())
31+
}
32+
33+
if (filter === FilterTypes.MINI || filter === FilterTypes.MINI_PREVIEW) {
34+
injectPlugins()
35+
}
1136

1237
liff
13-
.init({ liffId })
38+
.init({ liffId: appId })
1439
.then(() => {
1540
ReactDOM.render(
1641
<React.StrictMode>
17-
<App filter={filter} />
42+
<App appUrl={appUrl} filter={filter} />
1843
</React.StrictMode>,
1944
document.getElementById('root')
2045
)

src/vite-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
interface ImportMetaEnv {
44
readonly VITE_LIFF_ID: string;
55
readonly VITE_LIFF_ID_MINI: string;
6+
readonly VITE_LIFF_ID_MINI_PREVIEW: string;
67
}
78

89
interface ImportMeta {

0 commit comments

Comments
 (0)