youngeek-0410 / cloveeee-app-frontend

hacku-kosen-2022-frontend.vercel.app
0 stars 0 forks source link

Spotify 楽曲を検索・選択できるコンポーネントを作る #4

Closed sora-ichigo closed 1 year ago

sora-ichigo commented 1 year ago

いい感じ Project に SpotifyMusic を設定できるようにしたい

Screen Shot 2022-12-11 at 12 33 38 https://www.figma.com/file/Yw7dlVVMVTuaNHoymdbr9U/YounGeek_HackU?node-id=0%3A1&t=Gy1GP4LZYccUw5G5-0

sora-ichigo commented 1 year ago

楽曲設定側の考慮(編集面)

type SpotifyMusic = {
  uri: string;
  // 楽曲再生側に必要そうな情報を保持しておきたい
}

type Props = {
  spotifyMusic: SpotifyMusic;
  onChange: (spotifyMusic: SpotifyMusic) => void);
}

const SpotifyMusicSelect: React.FC<Props> = (props) => {
  // いい感じにSpotify楽曲の検索・選択ができるように作る
  return ...
}

こんな感じのコンポーネントを作って、

// Project詳細画面

const ProjectShowPage: React.FC = () => {
  const [projectSpotifyMusic, setProjectSpotifyMusic] = useState<SpotifyMusic | null>(null)

  return (
    <>
      ...
      <SpotifyMusicSelect spotifyMusic={projectSpotifyMusic} onChange={setProjectSpotifyMusic} />
      ...
    </>
  )
}

こんな感じで Project 詳細画面から呼び出せればいい?

sora-ichigo commented 1 year ago

楽曲再生側の考慮(閲覧面)

from https://github.com/youngeek-0410/hacku-kosen-2022-frontend/issues/4#issuecomment-1345447194

type SpotifyMusic = {
  uri: string;
  // 楽曲再生側に必要そうな情報を保持しておきたい
}

📝後でちゃんと調べる

sora-ichigo commented 1 year ago

📝 track = song

sora-ichigo commented 1 year ago

楽曲再生側の考慮(閲覧面)

https://github.com/youngeek-0410/hacku-kosen-2022-frontend/issues/4#issuecomment-1345447868 の続き

~https://developer.spotify.com/documentation/web-playback-sdk を使う~ → こいつは premium user しか使えないらしい(そのユーザのライブラリetc..を再生してくれる感じ) track のなかに preview_url という 30s だけ音楽を流せるデータがあったので今回はこれを使えば良さそう。

track(song) のデータ構造を見てみる

今回必要なデータになるのは以下のもの

次に実際にAPIを叩いてみて track のどこを取れば上記のデータが得られるのか調査する

trackデータ例 ```js { album: { album_type: 'album', artists: [Array], available_markets: [Array], external_urls: [Object], href: 'https://api.spotify.com/v1/albums/74vajFwEwXJ61OW1DKSPEa', id: '74vajFwEwXJ61OW1DKSPEa', images: [Array], name: 'Positions (Deluxe)', release_date: '2021-02-19', release_date_precision: 'day', total_tracks: 19, type: 'album', uri: 'spotify:album:74vajFwEwXJ61OW1DKSPEa' }, artists: [ [Object] ], available_markets: [ 'AD', 'AE', 'AG', 'AL', 'AM', 'AO', 'AR', 'AT', 'AU', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BN', 'BO', 'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CD', 'CG', 'CH', 'CI', 'CL', 'CM', 'CO', 'CR', 'CV', 'CW', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'ET', 'FI', 'FJ', 'FM', 'FR', 'GA', 'GB', 'GD', 'GE', 'GH', 'GM', 'GN', 'GQ', 'GR', 'GT', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IQ', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KR', 'KW', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', ... 84 more items ], disc_number: 1, duration_ms: 122174, explicit: false, external_ids: { isrc: 'USUM72102132' }, external_urls: { spotify: 'https://open.spotify.com/track/3eZYOQO4UzKrUDYDghtnFw' }, href: 'https://api.spotify.com/v1/tracks/3eZYOQO4UzKrUDYDghtnFw', id: '3eZYOQO4UzKrUDYDghtnFw', is_local: false, name: 'test drive', popularity: 65, preview_url: 'https://p.scdn.co/mp3-preview/9655830b381ec59e4f4b160cbb488801aa7072b4?cid=ce4decf85a2149efa2da06676bce5ec8', track_number: 16, type: 'track', uri: 'spotify:track:3eZYOQO4UzKrUDYDghtnFw' }, ``` albumの中 ```js { album_type: 'album', artists: [ { external_urls: [Object], href: 'https://api.spotify.com/v1/artists/3MZsBdqDrRTJihTHQrO6Dq', id: '3MZsBdqDrRTJihTHQrO6Dq', name: 'Joji', type: 'artist', uri: 'spotify:artist:3MZsBdqDrRTJihTHQrO6Dq' } ], available_markets: [ 'AD', 'AE', 'AG', 'AL', 'AM', 'AO', 'AR', 'AT', 'AU', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BN', 'BO', 'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CD', 'CG', 'CH', 'CI', 'CL', 'CM', 'CO', 'CR', 'CV', 'CW', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FJ', 'FM', 'FR', 'GA', 'GB', 'GD', 'GE', 'GH', 'GM', 'GN', 'GQ', 'GR', 'GT', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IQ', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KR', 'KW', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', ... 83 more items ], external_urls: { spotify: 'https://open.spotify.com/album/34GQP3dILpyCN018y2k61L' }, href: 'https://api.spotify.com/v1/albums/34GQP3dILpyCN018y2k61L', id: '34GQP3dILpyCN018y2k61L', images: [ { height: 640, url: 'https://i.scdn.co/image/ab67616d0000b27360ba1d6104d0475c7555a6b2', width: 640 }, { height: 300, url: 'https://i.scdn.co/image/ab67616d00001e0260ba1d6104d0475c7555a6b2', width: 300 }, { height: 64, url: 'https://i.scdn.co/image/ab67616d0000485160ba1d6104d0475c7555a6b2', width: 64 } ], name: 'BALLADS 1', release_date: '2018-10-26', release_date_precision: 'day', total_tracks: 12, type: 'album', uri: 'spotify:album:34GQP3dILpyCN018y2k61L' } ```

↑ を見てみると以下のフィールドから欲しい情報がそれぞれ取得できそうだった。

sora-ichigo commented 1 year ago

バックエンドが急いでいるので先にSpotifyMusic関連で必要になるAPIの定義をする

持つべきデータは決まっているので、予想で書く https://github.com/youngeek-0410/hacku-kosen-2022-frontend/issues/4#issuecomment-1345462722

https://github.com/youngeek-0410/hacku-kosen-2022-backend/pull/17 で対応

sora-ichigo commented 1 year ago

検索インターフェース

こんな感じに検索できるようになった。 これを検索フォームに入力されるたびに実行する?

useSearchSpotifyMusic("おもかげ Vaundy")
 + Array [
    +   Object {
    +     "album": Object {
    +       "image_url": "https://i.scdn.co/image/ab67616d0000b273cc4fbd1e1ad650bea96e1fc9",
    +       "name": "裸の勇者",
    +     },
    +     "artist": Object {
    +       "external_url": "https://open.spotify.com/artist/2IUl3m1H1EQ7QfNbNWvgru",
    +       "name": "Vaundy",
    +     },
    +     "external_url": "https://open.spotify.com/track/6uqewERWZ1vzfCcin1zFIp",
    +     "name": "おもかげ -self cover-",
    +     "preview_url": "https://p.scdn.co/mp3-preview/7fa8d4a77dacfc513f2be625bbdb9bc48f0bbed4?cid=ce4decf85a2149efa2da06676bce5ec8",
    +   },
    +   Object {
    +     "album": Object {
    +       "image_url": "https://i.scdn.co/image/ab67616d0000b273ac1a5a83790ba13920affe1e",
    +       "name": "おもかげ (produced by Vaundy)",
    +     },
    +     "artist": Object {
    +       "external_url": "https://open.spotify.com/artist/45ft4DyTCEJfQwTBHXpdhM",
    +       "name": "milet",
    +     },
    +     "external_url": "https://open.spotify.com/track/6ts1KCOudfDYXYfyWtq0k1",
    +     "name": "おもかげ (produced by Vaundy)",
    +     "preview_url": "https://p.scdn.co/mp3-preview/60fb39c321a2470f4ffd35ade9a5f8acdeef334c?cid=ce4decf85a2149efa2da06676bce5ec8",
    +   },
    +   Object {
    +     "album": Object {
    +       "image_url": "https://i.scdn.co/image/ab67616d0000b2737a910ed50c45df3713b5de71",
    +       "name": "CHAINSAW BLOOD",
    +     },
    +     "artist": Object {
    +       "external_url": "https://open.spotify.com/artist/2IUl3m1H1EQ7QfNbNWvgru",
    +       "name": "Vaundy",
    +     },
    +     "external_url": "https://open.spotify.com/track/3lUOzabhWYyRImRszpJGOU",
    +     "name": "CHAINSAW BLOOD",
    +     "preview_url": "https://p.scdn.co/mp3-preview/e13a25161512163572e735e423bbcb2626c266b7?cid=ce4decf85a2149efa2da06676bce5ec8",
    +   },
    + ]
sora-ichigo commented 1 year ago

https://github.com/youngeek-0410/hacku-kosen-2022-frontend/pull/5#issuecomment-1345551810 でいい感じにSpotifyを操作できる実装を作った。これであとはスタイルをいい感じに当てていくだけのはず、、

https://hacku-kosen-2022-frontend.vercel.app/spotify_search_demo で試せる

プロジェクト詳細画面に載せるやつ 音楽選択コンポーネント
Screen Shot 2022-12-11 at 22 10 28 Screen Shot 2022-12-11 at 22 14 48

https://user-images.githubusercontent.com/66525257/206905781-b4bea4c5-6271-46f7-83f9-1b84060327db.mov