From: Dessalines Date: Thu, 22 Aug 2019 23:13:26 +0000 (-0700) Subject: Cross posting working. X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%7B%7D/%7Bthis.state.post.url%7D?a=commitdiff_plain;h=20fec100b5c0d99f71e7e38c219f39686b990938;p=lemmy.git Cross posting working. --- diff --git a/ui/src/components/create-post.tsx b/ui/src/components/create-post.tsx index dd93a3c5..3e00bd80 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 d21b2fb4..f502e7f3 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 {