Skip to content

Instantly share code, notes, and snippets.

@jmn
Created February 20, 2019 23:06
Show Gist options
  • Save jmn/7f1184d3c145b588912a1623d37bf9c0 to your computer and use it in GitHub Desktop.
Save jmn/7f1184d3c145b588912a1623d37bf9c0 to your computer and use it in GitHub Desktop.
AddFeed
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