From 20fec100b5c0d99f71e7e38c219f39686b990938 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 22 Aug 2019 16:13:26 -0700 Subject: [PATCH] Cross posting working. --- ui/src/components/create-post.tsx | 15 +++++++++++- ui/src/components/post-form.tsx | 37 +++++++++++++++++++----------- ui/src/components/post-listing.tsx | 16 ++++++------- ui/src/components/post.tsx | 35 +++++++++++++++++++--------- ui/src/components/sidebar.tsx | 2 +- ui/src/index.tsx | 1 - ui/src/interfaces.ts | 7 ++++++ 7 files changed, 77 insertions(+), 36 deletions(-) diff --git a/ui/src/components/create-post.tsx b/ui/src/components/create-post.tsx index dd93a3c53..3e00bd80a 100644 --- a/ui/src/components/create-post.tsx +++ b/ui/src/components/create-post.tsx @@ -1,6 +1,7 @@ import { Component } from 'inferno'; import { PostForm } from './post-form'; import { WebSocketService } from '../services'; +import { PostFormParams } from '../interfaces'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -21,13 +22,25 @@ export class CreatePost extends Component {
#
- +
) } + get params(): PostFormParams { + let urlParams = new URLSearchParams(this.props.location.search); + let params: PostFormParams = { + name: urlParams.get("name"), + community: urlParams.get("community") || this.prevCommunityName, + body: urlParams.get("body"), + url: urlParams.get("url"), + }; + + return params; + } + get prevCommunityName(): string { if (this.props.match.params.name) { return this.props.match.params.name; diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index d21b2fb4c..f502e7f3e 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno'; import { PostListings } from './post-listings'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; -import { PostForm as PostFormI, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces'; +import { PostForm as PostFormI, PostFormParams, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter } from '../utils'; import * as autosize from 'autosize'; @@ -11,7 +11,7 @@ import { T } from 'inferno-i18next'; interface PostFormProps { post?: Post; // If a post is given, that means this is an edit - prevCommunityName?: string; + params?: PostFormParams; onCancel?(): any; onCreate?(id: number): any; onEdit?(post: Post): any; @@ -62,20 +62,30 @@ export class PostForm extends Component { } } + if (this.props.params) { + this.state.postForm.name = this.props.params.name; + if (this.props.params.url) { + this.state.postForm.url = this.props.params.url; + } + if (this.props.params.body) { + this.state.postForm.body = this.props.params.body; + } + } + this.subscription = WebSocketService.Instance.subject - .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) - .subscribe( - (msg) => this.parseMessage(msg), + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) + .subscribe( + (msg) => this.parseMessage(msg), (err) => console.error(err), () => console.log('complete') - ); + ); - let listCommunitiesForm: ListCommunitiesForm = { - sort: SortType[SortType.TopAll], - limit: 9999, - } + let listCommunitiesForm: ListCommunitiesForm = { + sort: SortType[SortType.TopAll], + limit: 9999, + } - WebSocketService.Instance.listCommunities(listCommunitiesForm); + WebSocketService.Instance.listCommunities(listCommunitiesForm); } componentDidMount() { @@ -123,7 +133,6 @@ export class PostForm extends Component {