-
Notifications
You must be signed in to change notification settings - Fork 12
[TypeScript演習]Google拡張機能の課題追加 #80
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
Open
aAnnaChiba
wants to merge
9
commits into
master
Choose a base branch
from
create_google_extention_question
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d2c987
create google extention question
aAnnaChiba c87168c
Update README.md
aAnnaChiba 080583e
chnage semi: false -> true
aAnnaChiba 3bdb4c3
change variable name: deleteBtn -> deleteButton
aAnnaChiba 4bd0bfb
add lib and source map to tsconfig
aAnnaChiba 165516b
use document fragment in render bookmarks function
aAnnaChiba e03e073
fix typo: optional chain -> ternary operator
aAnnaChiba 2863806
delete package-lock and vite config from gitignore
aAnnaChiba d1967fe
add package-lock and config
aAnnaChiba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.vscode/ | ||
node_modules/ | ||
dist/ | ||
|
||
*.log | ||
|
||
.DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# はじめに | ||
|
||
Google 拡張機能を作成する問題案です。 | ||
TypeScript の問題が早く終了する受講者がいる場合の暇つぶし用として作成しました。 | ||
|
||
## TODO | ||
|
||
- `reduce`, `map` など、利用頻度が高いものを問題としたものをつくりたい | ||
|
||
## 目次 | ||
|
||
- [Q1. 型定義をする](#q1-型定義をする) | ||
- [Q2. インターフェースの継承を使ってみる](#q2-インターフェースの継承を使ってみる) | ||
- [Q3. オプショナルチェーンを使って、リファクタリングしてみる](#q3-オプショナルチェーンを使ってリファクタリングしてみる) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) ここのタイトルを修正し忘れているようです。 |
||
- [Q4. 登録日を表示してみる](#q4-登録日を表示してみる) | ||
- [Q5. 削除ボタン機能を作成してみる](#q5-削除ボタン機能を作成してみる) | ||
- [Q6. forEach()を使ってブックマーク一覧を表示してみる](#q6-foreachを使ってブックマーク一覧を表示してみる) | ||
- [Q7. 新しいブックマークの作成](#q7-新しいブックマークの作成) | ||
- [Q8. ブックマークの更新](#q8-ブックマークの更新) | ||
- [Q9. 自由に改造してみよう](#q9-自由に改造してみよう) | ||
|
||
## Q1. 型定義をする | ||
|
||
`interface`を用いて型定義の作成をしてください。 | ||
|
||
```ts | ||
// ブックマークの基本情報 | ||
interface BookmarkRecord { | ||
id: string; | ||
createdAt: Date; | ||
} | ||
|
||
// ブックマークのリソース情報 | ||
// TODO title, urlを定義する | ||
interface BookmarkResource {} | ||
|
||
// オプショナルなプロパティ | ||
// TODO categoryを定義する | ||
interface BookmarkOptionalInfo {} | ||
``` | ||
|
||
## Q2. インターフェースの継承を使ってみる | ||
|
||
`extends` あるいは `type` を用いて、Bookmark 全体の型定義をしてみてください。 | ||
|
||
```ts | ||
// TODO Bookmarkの型定義をする | ||
interface Bookmark = | ||
// あるいは type = Bookmark = | ||
``` | ||
|
||
## Q3. 三項演算子を使って、リファクタリングしてみる | ||
|
||
下記のコードは、if else を多く用いているため、かなり煩雑です。 | ||
三項演算子を使って修正してください。 | ||
|
||
```ts | ||
// localStorage からデータを読み込む関数 | ||
const loadBookmarks = (): Bookmark[] => { | ||
const data = localStorage.getItem(STORAGE_KEY); | ||
if (data) { | ||
return JSON.parse(data, (key, value) => { | ||
if (key === 'createdAt') { | ||
return new Date(value); | ||
} | ||
return value; | ||
}); | ||
} else { | ||
return []; | ||
} | ||
}; | ||
``` | ||
|
||
## Q4. 登録日を表示してみる | ||
|
||
`renderCategory()` 関数を参考にして、`renderRegistrationDate()` 関数を作成してください。 | ||
|
||
```ts | ||
const renderRegistrationDate = (createdAt: Date, title: HTMLElement) => {}; | ||
``` | ||
|
||
## Q5. 削除ボタン機能を作成してみる | ||
|
||
「削除」と書かれたボタンを登録日の右側に作成したいです。 | ||
`addEventListener` を用いて、削除ボタンの機能を作成してください。 | ||
|
||
```ts | ||
const renderDeleteButton = (bookmarkId: string, parent: HTMLElement) => { | ||
const deleteButton = createElement<HTMLButtonElement>('button', { | ||
textContent: '削除', | ||
}); | ||
deleteButton.style.marginLeft = '10px'; | ||
deleteButton.addEventListener('click', () => {}); | ||
parent.appendChild(deleteButton); | ||
}; | ||
``` | ||
|
||
## Q6. forEach()を使ってブックマーク一覧を表示してみる | ||
|
||
ブックマーク一覧を表示したいです。今まで作った関数を使って、表示してみてください。 | ||
|
||
```ts | ||
// ブックマークを一覧表示する関数 | ||
const renderBookmarks = (bookmarks: Bookmark[]): void => { | ||
bookmarkList.innerHTML = ''; | ||
const fragment = document.createDocumentFragment(); | ||
// TODO forEachを使ってブックマークリストの要素を表示してみよう | ||
bookmarks.forEach((bookmark) => { | ||
// タイトルとURLのリンクを作成 | ||
const title = document.createElement('li'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (want) このコメントと変数名だと、このタグにタイトルが入っていそうですが、実際はそうではないので違和感があります。 |
||
const link = document.createElement('a'); | ||
link.href = bookmark.url; | ||
link.target = '_blank'; | ||
link.textContent = bookmark.title; | ||
title.appendChild(link); | ||
|
||
// TODO カテゴリがあったらカテゴリを表示してみよう | ||
|
||
// TODO 登録日時の表示 | ||
|
||
// TODO 削除ボタンの作成 | ||
|
||
bookmarkList.appendChild(fragment); | ||
}); | ||
}; | ||
``` | ||
|
||
## Q7. 新しいブックマークの作成をしてみる | ||
|
||
id にランダムな UUID、createdAt には Date 関数を用いて、新しいブックマークを作成してください | ||
|
||
<details><summary>ランダムなUUIDを作成するヒント</summary> | ||
|
||
[Crypto](https://developer.mozilla.org/ja/docs/Web/API/Crypto)を使ってみましょう | ||
|
||
</details> | ||
|
||
```ts | ||
// 新しいブックマークの作成 | ||
const newBookmark: Bookmark = {}; | ||
``` | ||
|
||
## Q8. ブックマークの更新をしてみる | ||
|
||
スプレッド演算子と、Q7 で作成した newBookmark を用いて、ブックマークをアップデートしてください | ||
|
||
```ts | ||
const updatedBookmarks = []; | ||
``` | ||
|
||
## Q9. 自由に改造してみよう | ||
|
||
ブックマークリスト拡張機能が作成できたら、自由に改造してみよう。 | ||
例:フィルタリング機能をつけてみる、カテゴリごとに色で分けてみるなど |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# TypeScriptでGoolgle拡張機能を作ってみよう | ||
|
||
タイトル、URL、カテゴリを入力できるブックマーク管理アプリを作成してみよう | ||
|
||
## サンプル | ||
|
||
https://github.com/user-attachments/assets/83738bcc-a676-4684-b7a8-bdd9970d88dc | ||
SekiT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## やり方 | ||
|
||
### google拡張機能を管理する | ||
|
||
#### URL横にある拡張機能を管理をクリック | ||
|
||
<img width="456" alt="スクリーンショット 2025-03-06 16 00 29" src="https://github.com/user-attachments/assets/bfcbf1a6-0986-454c-b739-900ada4bf857" /> | ||
|
||
#### パッケージ化されていない拡張機能を読み込むをクリック | ||
|
||
<img width="1392" alt="スクリーンショット 2025-03-06 16 01 43" src="https://github.com/user-attachments/assets/2c6aa5c2-c60f-4148-9eef-a42f040b3861" /> | ||
|
||
#### google-extention-tutorialディレクトリを選択 | ||
|
||
<img width="1479" alt="スクリーンショット 2025-03-06 17 01 43" src="https://github.com/user-attachments/assets/2b319f7e-0488-4e69-9736-7b5b7bd68312" /> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "ブックマーク管理アプリ", | ||
"version": "1.0", | ||
"description": "ブックマークの追加、一覧表示、削除ができるシンプルな拡張機能。", | ||
"action": { | ||
"default_popup": "popup.html" | ||
}, | ||
"permissions": [] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit/optional) 細かいですが、テキストファイルの末尾には改行があるべきです。参考