Skip to content

Commit

Permalink
Merge pull request #21 from ytak-sagit/feature/#17-set-placeholder-image
Browse files Browse the repository at this point in the history
#17: QRコード生成前にプレースホルダ画像を表示しておくように対応
  • Loading branch information
ytak-sagit authored Dec 28, 2024
2 parents 3cf2009 + 1b84d32 commit 66675bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>QR Code Generator</title>
<base data-trunk-public-url />
<link data-trunk rel="copy-dir" href="public" />
</head>

<body></body>
Expand Down
5 changes: 5 additions & 0 deletions public/icon-success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ fn app() -> Html {
</label>
<button type="submit">{"Generate QR Code"}</button>
</form>
<QrCodeImage url={(*url_updator).clone()} />
<div>
<QrCodeImage url={(*url_updator).clone()} />
</div>
</main>
}
}
Expand All @@ -50,10 +52,14 @@ struct QrCodeProps {
#[function_component(QrCodeImage)]
fn qr_code_image(props: &QrCodeProps) -> Html {
let QrCodeProps { url } = props.clone();
let url = url.clone();

if url.is_empty() {
// TODO: ここにQRコードが出力されることを示す、プレースホルダ画像を表示したい
return Html::default();
return html! {
<>
<p>{"QR code will be displayed below."}</p>
<img src="public/placeholder.svg" alt="placeholder" />
</>
};
}

let base64_encoded_image_data =
Expand All @@ -62,6 +68,10 @@ fn qr_code_image(props: &QrCodeProps) -> Html {
// TODO: QRコードが表示されるまで loading 表示をしたい
html! {
<>
<p>
<img style="display: inline-block; width: 1.2em; height: 1.2em; vertical-align: middle;" src="public/icon-success.svg" alt="success" />
{"QR code was generated."}
</p>
<img src={img} alt={&url} />
</>
}
Expand Down

0 comments on commit 66675bc

Please sign in to comment.