Breadkenty / SmashHub

A full-stack web app where users can upload and share combos from Super Smash Bros. Ultimate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reformat video ID keywords filter

Breadkenty opened this issue · comments

Ideally, we would like to have a bank of keywords that can be added to a component. Currently, the filter is barebones and would like it to be refactored into something more efficient. You can find this in both EditCombo.jsx and SubmitCombo.jsx

function checkVideoExists(event) {
    const keyWords = [
      'super',
      'smash',
      'bros',
      'ultimate',
      'ssbu',
      'combo',
      'combos',
    ]

    fetch(
      `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${event.target.value}&key=${process.env.REACT_APP_YOUTUBE_KEY}`
    )
      .then(response => {
        return response.json()
      })
      .then(apiData => {
        if (apiData.items.length === 0) {
          setVideoExists(false)
        } else if (
          apiData.items[0].snippet.title
            .toLowerCase()
            .includes(characterSelected.name.toLowerCase()) ||
          apiData.items[0].snippet.description
            .toLowerCase()
            .includes(characterSelected.name.toLowerCase()) ||
          keyWords.some(keyWord =>
            apiData.items[0].snippet.title.toLowerCase().includes(keyWord)
          ) ||
          keyWords.some(keyWord =>
            apiData.items[0].snippet.description.toLowerCase().includes(keyWord)
          )
        ) {
          setVideoInformationById(apiData.items[0].snippet)
          setVideoExists(true)
        } else {
          setVideoExists(false)
        }
      })
  }
  • Refactor this code as a component
  • Improve keywords that will allow non-English videos to be validated