Commit e5e0c06b authored by Even Gultvedt's avatar Even Gultvedt
Browse files

Fixed some flow errors. Many remain, but they don't seem very fixable... Many...

Fixed some flow errors. Many remain, but they don't seem very fixable... Many are related to either my use of polymorphism in the write/edit article, or use of either null/Object for both Article's and strings.
parent f7ff7d99
Pipeline #58758 passed with stage
in 1 minute and 16 seconds
......@@ -15,7 +15,7 @@ const Article = require('../src/Article');
export class ArticleGrid extends Component<{ category?: number }> {
mounted() {
articleStore.getAllArticles().catch(error => console.log(error));
articleStore.getAllArticles();
}
render() {
......@@ -44,14 +44,11 @@ export class ArticleGrid extends Component<{ category?: number }> {
}
export class SingleArticle extends Component<{ match: { params: { id: number } } }> {
constructor(props) {
constructor(props: any) {
super(props);
if (this.props.match != null && this.props.match.params.id) {
console.log("Fetching " + this.props.match.params.id);
articleStore.getArticle(this.props.match.params.id).catch(error => console.log(error));
} else if (this.props.id != null && this.props.id) {
console.log("Fetching " + this.props.id);
articleStore.getArticle(this.props.id).catch(error => console.log(error));
articleStore.getArticle(this.props.match.params.id);
}
}
......@@ -89,17 +86,23 @@ export class SingleArticle extends Component<{ match: { params: { id: number } }
class AddOrEditArticle extends Component {
author: string;
title: string;
imageURL: string;
imageURL: string | null;
content: string;
category: number;
important: boolean;
time: string;
authorRef: any;
titleRef: any;
imageRef: any;
contentRef: any;
categoryRef: any;
importantRef: any;
validateURL(URL: string) {
return (URL.match(/\.(jpeg|jpg|gif|png)$/) != null);
}
constructor(props) {
constructor(props: any) {
super(props);
this.authorRef = React.createRef();
this.titleRef = React.createRef();
......
......@@ -17,6 +17,17 @@ class ArticleStore {
currentArticle: Article = null;
categories: any = {};
assignArticle(article: Article){
this.currentArticle.id = article.id;
this.currentArticle.title = article.title;
this.currentArticle.content = article.content;
this.currentArticle.imageURL = article.imageURL;
this.currentArticle.time = article.time;
this.currentArticle.comments = article.comments;
this.currentArticle.category = article.category;
this.currentArticle.important = article.important;
}
getIds(){
return axios.get("http://localhost:4000/ids").then(response => {
if (response.status === 500){
......@@ -48,10 +59,10 @@ class ArticleStore {
});
}
createArticle(response): Article{
createArticle(response: any): Article{
return new Article(response.id,
response.author, response.title, response.imageURL, response.time, response.content, response.category,
response.important === 1, []);
response.important === 1);
}
getArticle(id: number): Article{
......@@ -65,7 +76,7 @@ class ArticleStore {
this.currentArticle = this.createArticle(response.data[0]);
let article: Article = this.articles.find(a => this.currentArticle.id === a.id);
if (article){
Object.assign(article, {...this.currentArticle});
this.assignArticle(article);
}
}
else{
......@@ -184,7 +195,7 @@ class ArticleStore {
let articleFromList: Article = this.articles.find(a => this.currentArticle.id === a.id);
if (articleFromList){
Object.assign(articleFromList, {...this.currentArticle});
this.assignArticle(articleFromList);
}
let data: {author: string, title: string, imageURL: string, time: string, content: string, category: number, important: boolean} = {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment