Created
February 20, 2019 23:06
-
-
Save jmn/7f1184d3c145b588912a1623d37bf9c0 to your computer and use it in GitHub Desktop.
AddFeed
This file contains 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
import React, { useState } from "react"; | |
import Parser from "rss-parser"; | |
import { Form, FormGroup, Label, Input } from "reactstrap"; | |
const getFeedTitle = feedUrl => { | |
const foo = async () => { | |
try { | |
const parser = new Parser(); | |
const CORS_PROXY = "https://cors-anywhere.herokuapp.com/"; | |
let feed = await parser.parseURL(CORS_PROXY + feedUrl); | |
console.log(feed.title); | |
return feed.title; | |
} catch (err) {} | |
}; | |
return foo(); | |
}; | |
const AddFeed = () => { | |
const [title, setTitle] = useState(""); | |
// const nameFromUrl = e => { | |
// let title = getFeedTitle(e.target.value); | |
// console.log("setting", title); | |
// setTitle(title); | |
// }; | |
return ( | |
<Form> | |
<fieldset> | |
<FormGroup> | |
<Label for="url">Feed URL</Label> | |
<Input type="text" name="url" id="url" /> | |
</FormGroup> | |
<FormGroup> | |
<Label>Feed Title</Label> | |
<Input type="text" name="title" id="title" defaultValue={title} /> | |
</FormGroup> | |
<Input type="submit" name="submit" id="submit" /> | |
</fieldset> | |
</Form> | |
); | |
}; | |
export default AddFeed; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment