Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appearances for MINI #40

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
Binary file added public/assets/qr_mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/qr_mini_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ body {
height: auto;
}

.applicationNotice {
color: #777777;
font-size: 15px;
}

@media only screen and (max-width: 375px) {
.container {
width: auto;
Expand Down
34 changes: 20 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import React from 'react'
import React, { useContext } from 'react'
import liff from '@line/liff'
import styles from './App.module.css'
import Header from './components/Header'
import Snippet from './components/Snippet'
import Input from './components/Input'
import { FilterContext, FilterType } from './Context'
import qrCode from './qr-code.png'
import { SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST } from './constants'
import { SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST, QR_IMG_MAP } from './constants'
import { FilterTypes } from './FilterTypes'
import { AppContext } from './Context'

type Props = {
appUrl: string
filter: FilterType
}
function App() {
const { appUrl, filter } = useContext(AppContext)

function App({ appUrl, filter }: Props) {
let isLoggedIn = false
try {
isLoggedIn = liff.isLoggedIn()
} catch (e) {
console.log(e)
}

return (
<FilterContext.Provider value={filter}>
<>
<Header />
<div className={styles.container}>
{filter === FilterTypes.MINI || filter === FilterTypes.MINI_PREVIEW ? (
<div className={styles.applicationNotice}>
本「LINEミニアプリプレイグラウンド」は日本限定のサービスです。
<br />
This “LINE MINI App Playground” is available only in Japan.
</div>
) : null}
<div className={styles.liffIdBox}>
<Input readonly value={`URL: ${appUrl}`} />
<img src={qrCode} className={styles.qrCode} />
<img src={QR_IMG_MAP[filter]} className={styles.qrCode} />
</div>
<h1>Client APIs</h1>
{!isLoggedIn ? (
Expand Down Expand Up @@ -226,7 +230,9 @@ function App({ appUrl, filter }: Props) {
docUrl="https://developers.line.biz/en/reference/liff/#share-target-picker"
needRequestPayload={true}
hideResponse={true}
defaultRequestPayload={SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST[0].value}
defaultRequestPayload={
SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST[0].value
}
pulldownOptions={SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST}
skipAutoRun={true}
runner={async (options) => {
Expand Down Expand Up @@ -308,7 +314,7 @@ function App({ appUrl, filter }: Props) {
)}
runner={async (payload) => {
const parsed = JSON.parse(payload)
await liff.createShortcutOnHomeScreen(parsed);
await liff.createShortcutOnHomeScreen(parsed)
}}
skipAutoRun={true}
isInLIFF={false}
Expand Down Expand Up @@ -353,7 +359,7 @@ function App({ appUrl, filter }: Props) {
</>
)}
</div>
</FilterContext.Provider>
</>
)
}

Expand Down
10 changes: 9 additions & 1 deletion src/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ import { FilterTypes } from './FilterTypes'

export type FilterType = keyof typeof FilterTypes

export const FilterContext = React.createContext<FilterType>(FilterTypes.LIFF)
export const AppContext = React.createContext<{
filter: FilterType,
appId: string,
appUrl: string
}>({
filter: FilterTypes.LIFF,
appId: import.meta.env.VITE_LIFF_ID,
appUrl: `https://liff.line.me/${import.meta.env.VITE_LIFF_ID}`
})
7 changes: 7 additions & 0 deletions src/components/Header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
align-items: center;
}

.left {
flex: 1;
}

.left a {
text-decoration: none;
color: #000;
Expand All @@ -41,4 +45,7 @@
.gitHubButton {
display: none;
}
.right {
flex-basis: 100px;
}
}
12 changes: 9 additions & 3 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import liff from '@line/liff'
import React from 'react'
import React, { useContext, useMemo } from 'react'
import styles from './Header.module.css'
import Button from './Button'
import { AppContext } from '../Context'

export default function Header() {
const {filter, appId} = useContext(AppContext);
const appName = useMemo(() => {
return filter === 'LIFF' ? 'LIFF Playground' : 'LINE MINI App Playground'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the style of the Open in LINE button is broken.
Applying the following diff can prevent the button's style from breaking.

diff --git a/src/components/Header.module.css b/src/components/Header.module.css
index 87edea9..02e74ac 100644
--- a/src/components/Header.module.css
+++ b/src/components/Header.module.css
@@ -17,6 +17,14 @@
   align-items: center;
 }
 
+.left {
+  flex: 1;
+}
+
+.right {
+  flex-basis: 100px;
+}
+
 .left a {
   text-decoration: none;
   color: #000;

localhost_3000__mini(iPhone SE)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been fine-tuned and corrected. Thank you for the suggestions. 12f3c52

}, [filter])

const openGitHub = () => {
window.open(`https://github.com/line/liff-playground`, '_blank')
}

const openInApp = () => {
window.open(
`https://line.me/R/app/${import.meta.env.VITE_LIFF_ID}`,
`https://line.me/R/app/${appId}`,
'_blank'
)
}
Expand All @@ -20,7 +26,7 @@ export default function Header() {
<div className={styles.header}>
<div className={styles.left}>
<a href='/'>
<h1>LIFF Playground</h1>
<h1>{appName}</h1>
</a>
</div>
<div className={styles.right}>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Snippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Input from './Input'
import styles from './Snippet.module.css'
import Tag from './Tag'
import TextArea from './TextArea'
import { FilterContext } from '../Context'
import { AppContext } from '../Context'
import { FilterTypes } from '../FilterTypes'
import Pulldown from './Pulldown'

Expand Down Expand Up @@ -74,8 +74,8 @@ export default function Snippet({
}, [skipAutoRun, callRunner])

return (
<FilterContext.Consumer>
{(filter) =>
<AppContext.Consumer>
{({ filter }) =>
((filter === FilterTypes.LIFF && isInLIFF) ||
(filter === FilterTypes.MINI && isInMINI)) && (
<div className={styles.snippet}>
Expand Down Expand Up @@ -154,6 +154,6 @@ export default function Snippet({
</div>
)
}
</FilterContext.Consumer>
</AppContext.Consumer>
)
}
10 changes: 9 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const base = new URL(location.href).origin;
import { FilterTypes } from "./FilterTypes"

const base = new URL(location.href).origin
export const SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST = [
{
label: 'text',
Expand Down Expand Up @@ -54,3 +56,9 @@ export const SHARE_TARGET_PICKER_FIXED_ARGUMENT_LIST = [
label,
value: JSON.stringify(value, null, 4),
}))

export const QR_IMG_MAP = {
[FilterTypes.LIFF]: `${base}/assets/qr_liff.png`,
[FilterTypes.MINI]: `${base}/assets/qr_mini.png`,
[FilterTypes.MINI_PREVIEW]: `${base}/assets/qr_mini_preview.png`,
}
5 changes: 4 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LiffCommonProfilePlugin } from '@line/liff-common-profile-plugin'
import './main.css'
import App from './App'
import { FilterTypes } from './FilterTypes'
import { AppContext } from './Context'

const isMINI = new URLSearchParams(location.search).has('mini')
const isPreviewMINI = new URLSearchParams(location.search).has('mini_preview')
Expand Down Expand Up @@ -39,7 +40,9 @@ liff
.then(() => {
ReactDOM.render(
<React.StrictMode>
<App appUrl={appUrl} filter={filter} />
<AppContext.Provider value={{ filter, appId, appUrl }}>
<App />
</AppContext.Provider>
</React.StrictMode>,
document.getElementById('root')
)
Expand Down
Loading