Skip to content

Commit

Permalink
Add ability to fill magnet link title on post creation. (#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored Aug 9, 2024
1 parent 62c62bf commit 9c4424f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import { MarkdownTextArea } from "../common/markdown-textarea";
import { SearchableSelect } from "../common/searchable-select";
import { PostListings } from "./post-listings";
import { isBrowser } from "@utils/browser";
import isMagnetLink, {
extractMagnetLinkDownloadName,
} from "@utils/media/is-magnet-link";

const MAX_POST_TITLE_LENGTH = 200;

Expand Down Expand Up @@ -806,10 +809,25 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
async fetchPageTitle() {
const url = this.state.form.url;
if (url && validURL(url)) {
this.setState({ metadataRes: LOADING_REQUEST });
this.setState({
metadataRes: await HttpService.client.getSiteMetadata({ 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: await HttpService.client.getSiteMetadata({ url }),
});
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/shared/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ export function getEmojiMart(
}

export async function setupTribute() {
if (Tribute === null) {
// eslint-disable-next-line eqeqeq
if (Tribute == null) {
console.debug("Tribute is null, importing...");
Tribute = (await import("tributejs")).default;
}
Expand Down

0 comments on commit 9c4424f

Please sign in to comment.