From ec4bbf7dfa0b253ffabb5740f389dc7d2c56d722 Mon Sep 17 00:00:00 2001 From: Yasuaki Uechi Date: Wed, 14 Aug 2019 15:13:57 +0900 Subject: [PATCH] feat: spectrum --- api/services/spectrum.js | 23 +++++++++++++++++++ web/public/locales/en/translation.json | 3 ++- web/public/locales/ja/translation.json | 3 ++- web/src/App.js | 2 ++ web/src/components/Icons.js | 14 ++++++++++++ web/src/components/Welcome.js | 4 ++++ web/src/components/cards/SpectrumCard.js | 29 ++++++++++++++++++++++++ web/src/i18n.js | 6 ++++- 8 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 api/services/spectrum.js create mode 100644 web/src/components/Icons.js create mode 100644 web/src/components/cards/SpectrumCard.js diff --git a/api/services/spectrum.js b/api/services/spectrum.js new file mode 100644 index 0000000..7a4273f --- /dev/null +++ b/api/services/spectrum.js @@ -0,0 +1,23 @@ +const { send, sendError, fetch } = require('../util/http') + +module.exports = async (req, res) => { + const { query } = req.query + + if (!query) { + return sendError(res, new Error('no query given')) + } + + try { + const response = await fetch( + `https://spectrum.chat/${encodeURIComponent(query)}`, + 'GET' + ) + const body = await response.text() + const availability = body.includes( + 'You may be trying to view something that is deleted' + ) + send(res, { availability }) + } catch (err) { + sendError(res, err) + } +} diff --git a/web/public/locales/en/translation.json b/web/public/locales/en/translation.json index e89dcdc..cee6134 100644 --- a/web/public/locales/en/translation.json +++ b/web/public/locales/en/translation.json @@ -17,7 +17,8 @@ "jsorg": "js.org", "githubSearch": "Github Repository", "appStore": "App Store", - "google": "Google Search" + "google": "Google Search", + "spectrum": "Spectrum" }, "countryCode": "us", "try": "Suggested Name" diff --git a/web/public/locales/ja/translation.json b/web/public/locales/ja/translation.json index d0bf71c..b2d9b73 100644 --- a/web/public/locales/ja/translation.json +++ b/web/public/locales/ja/translation.json @@ -17,7 +17,8 @@ "jsorg": "js.org", "githubSearch": "Github リポジトリ", "appStore": "App Store", - "google": "Google 検索" + "google": "Google 検索", + "spectrum": "Spectrum" }, "countryCode": "jp", "try": "全自動名前考え機" diff --git a/web/src/App.js b/web/src/App.js index 148ccdc..bb2ce34 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -12,6 +12,7 @@ import CratesioCard from './components/cards/CratesioCard' import HomebrewCard from './components/cards/HomebrewCard' import LinuxCard from './components/cards/LinuxCard' import TwitterCard from './components/cards/TwitterCard' +import SpectrumCard from './components/cards/SpectrumCard' import SlackCard from './components/cards/SlackCard' import S3Card from './components/cards/S3Card' import JsOrgCard from './components/cards/JsOrgCard' @@ -101,6 +102,7 @@ export default function App() { + diff --git a/web/src/components/Icons.js b/web/src/components/Icons.js new file mode 100644 index 0000000..7f060e4 --- /dev/null +++ b/web/src/components/Icons.js @@ -0,0 +1,14 @@ +import React from 'react' + +export const SpectrumIcon = () => ( + + + +) diff --git a/web/src/components/Welcome.js b/web/src/components/Welcome.js index 7865054..22fe071 100644 --- a/web/src/components/Welcome.js +++ b/web/src/components/Welcome.js @@ -17,6 +17,7 @@ import { } from 'react-icons/fa' import { IoIosBeer } from 'react-icons/io' import { DiRust } from 'react-icons/di' +import { SpectrumIcon } from './Icons' import { mobile } from '../util/css' @@ -57,6 +58,9 @@ export default function Welcome() { {t('providers.twitter')} + + {t('providers.spectrum')} + {t('providers.slack')} diff --git a/web/src/components/cards/SpectrumCard.js b/web/src/components/cards/SpectrumCard.js new file mode 100644 index 0000000..4a02be7 --- /dev/null +++ b/web/src/components/cards/SpectrumCard.js @@ -0,0 +1,29 @@ +import React from 'react' +import { useTranslation } from 'react-i18next' +import { Card, Repeater, DedicatedAvailability } from '../Cards' +import { SpectrumIcon } from '../Icons' + +export default function SpectrumCard({ query }) { + const { t } = useTranslation() + const names = [query] + + return ( + + + {(name) => ( + <> + } + /> + + )} + + + ) +} diff --git a/web/src/i18n.js b/web/src/i18n.js index 305287a..bfeb48b 100644 --- a/web/src/i18n.js +++ b/web/src/i18n.js @@ -12,7 +12,11 @@ i18n .init({ backend: { backends: [LocalStorageBackend, XHR], - backendOptions: [], + backendOptions: [ + { + versions: { en: '1.1', ja: '1.1' }, + }, + ], }, fallbackLng: 'en', debug: false,