mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-24 21:31:12 +00:00
Add ability to fill magnet link title on post creation. (#2654)
This commit is contained in:
parent
62c62bf038
commit
9c4424f792
2 changed files with 24 additions and 5 deletions
|
@ -45,6 +45,9 @@ import { MarkdownTextArea } from "../common/markdown-textarea";
|
||||||
import { SearchableSelect } from "../common/searchable-select";
|
import { SearchableSelect } from "../common/searchable-select";
|
||||||
import { PostListings } from "./post-listings";
|
import { PostListings } from "./post-listings";
|
||||||
import { isBrowser } from "@utils/browser";
|
import { isBrowser } from "@utils/browser";
|
||||||
|
import isMagnetLink, {
|
||||||
|
extractMagnetLinkDownloadName,
|
||||||
|
} from "@utils/media/is-magnet-link";
|
||||||
|
|
||||||
const MAX_POST_TITLE_LENGTH = 200;
|
const MAX_POST_TITLE_LENGTH = 200;
|
||||||
|
|
||||||
|
@ -806,12 +809,27 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
async fetchPageTitle() {
|
async fetchPageTitle() {
|
||||||
const url = this.state.form.url;
|
const url = this.state.form.url;
|
||||||
if (url && validURL(url)) {
|
if (url && validURL(url)) {
|
||||||
|
// If its a magnet link, fill in the download name
|
||||||
|
if (isMagnetLink(url)) {
|
||||||
|
const title = extractMagnetLinkDownloadName(url);
|
||||||
|
if (title) {
|
||||||
|
this.setState({
|
||||||
|
metadataRes: {
|
||||||
|
state: "success",
|
||||||
|
data: {
|
||||||
|
metadata: { title },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.setState({ metadataRes: LOADING_REQUEST });
|
this.setState({ metadataRes: LOADING_REQUEST });
|
||||||
this.setState({
|
this.setState({
|
||||||
metadataRes: await HttpService.client.getSiteMetadata({ url }),
|
metadataRes: await HttpService.client.getSiteMetadata({ url }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fetchSimilarPosts() {
|
async fetchSimilarPosts() {
|
||||||
const q = this.state.form.name;
|
const q = this.state.form.name;
|
||||||
|
|
|
@ -336,7 +336,8 @@ export function getEmojiMart(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupTribute() {
|
export async function setupTribute() {
|
||||||
if (Tribute === null) {
|
// eslint-disable-next-line eqeqeq
|
||||||
|
if (Tribute == null) {
|
||||||
console.debug("Tribute is null, importing...");
|
console.debug("Tribute is null, importing...");
|
||||||
Tribute = (await import("tributejs")).default;
|
Tribute = (await import("tributejs")).default;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue