mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-25 09:20:33 +00:00
parent
9e20ddbfa4
commit
b365dd2349
1 changed files with 24 additions and 14 deletions
38
ui/src/components/post-form.tsx
vendored
38
ui/src/components/post-form.tsx
vendored
|
@ -74,6 +74,8 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
|
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
this.fetchSimilarPosts = debounce(this.fetchSimilarPosts).bind(this);
|
||||||
|
this.fetchPageTitle = debounce(this.fetchPageTitle).bind(this);
|
||||||
|
|
||||||
this.state = this.emptyState;
|
this.state = this.emptyState;
|
||||||
|
|
||||||
|
@ -350,9 +352,14 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
|
|
||||||
handlePostUrlChange(i: PostForm, event: any) {
|
handlePostUrlChange(i: PostForm, event: any) {
|
||||||
i.state.postForm.url = event.target.value;
|
i.state.postForm.url = event.target.value;
|
||||||
if (validURL(i.state.postForm.url)) {
|
i.setState(i.state);
|
||||||
|
i.fetchPageTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchPageTitle() {
|
||||||
|
if (validURL(this.state.postForm.url)) {
|
||||||
let form: SearchForm = {
|
let form: SearchForm = {
|
||||||
q: i.state.postForm.url,
|
q: this.state.postForm.url,
|
||||||
type_: SearchType[SearchType.Url],
|
type_: SearchType[SearchType.Url],
|
||||||
sort: SortType[SortType.TopAll],
|
sort: SortType[SortType.TopAll],
|
||||||
page: 1,
|
page: 1,
|
||||||
|
@ -362,36 +369,39 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
WebSocketService.Instance.search(form);
|
WebSocketService.Instance.search(form);
|
||||||
|
|
||||||
// Fetch the page title
|
// Fetch the page title
|
||||||
getPageTitle(i.state.postForm.url).then(d => {
|
getPageTitle(this.state.postForm.url).then(d => {
|
||||||
i.state.suggestedTitle = d;
|
this.state.suggestedTitle = d;
|
||||||
i.setState(i.state);
|
this.setState(this.state);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
i.state.suggestedTitle = undefined;
|
this.state.suggestedTitle = undefined;
|
||||||
i.state.crossPosts = [];
|
this.state.crossPosts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
i.setState(i.state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePostNameChange(i: PostForm, event: any) {
|
handlePostNameChange(i: PostForm, event: any) {
|
||||||
i.state.postForm.name = event.target.value;
|
i.state.postForm.name = event.target.value;
|
||||||
|
i.setState(i.state);
|
||||||
|
i.fetchSimilarPosts();
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchSimilarPosts() {
|
||||||
let form: SearchForm = {
|
let form: SearchForm = {
|
||||||
q: i.state.postForm.name,
|
q: this.state.postForm.name,
|
||||||
type_: SearchType[SearchType.Posts],
|
type_: SearchType[SearchType.Posts],
|
||||||
sort: SortType[SortType.TopAll],
|
sort: SortType[SortType.TopAll],
|
||||||
community_id: i.state.postForm.community_id,
|
community_id: this.state.postForm.community_id,
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 6,
|
limit: 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (i.state.postForm.name !== '') {
|
if (this.state.postForm.name !== '') {
|
||||||
WebSocketService.Instance.search(form);
|
WebSocketService.Instance.search(form);
|
||||||
} else {
|
} else {
|
||||||
i.state.suggestedPosts = [];
|
this.state.suggestedPosts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
i.setState(i.state);
|
this.setState(this.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePostBodyChange(i: PostForm, event: any) {
|
handlePostBodyChange(i: PostForm, event: any) {
|
||||||
|
|
Loading…
Reference in a new issue