Swapping out iframely. (#374)

* Swapping out iframely.

* Renaming iframely-card to metadata-card
This commit is contained in:
Dessalines 2021-08-19 11:24:13 -04:00 committed by GitHub
parent 62e410c382
commit 2356b0d62f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 884 additions and 1277 deletions

View File

@ -69,7 +69,7 @@
"husky": "^7.0.1",
"import-sort-style-module": "^6.0.0",
"iso-639-1": "^2.1.9",
"lemmy-js-client": "0.11.4-rc.10",
"lemmy-js-client": "0.11.4-rc.12",
"lint-staged": "^11.0.1",
"mini-css-extract-plugin": "^2.1.0",
"node-fetch": "^2.6.1",

View File

@ -3,19 +3,19 @@ import { Post } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { Icon } from "../common/icon";
interface FramelyCardProps {
interface MetadataCardProps {
post: Post;
}
interface FramelyCardState {
interface MetadataCardState {
expanded: boolean;
}
export class IFramelyCard extends Component<
FramelyCardProps,
FramelyCardState
export class MetadataCard extends Component<
MetadataCardProps,
MetadataCardState
> {
private emptyState: FramelyCardState = {
private emptyState: MetadataCardState = {
expanded: false,
};
@ -82,7 +82,7 @@ export class IFramelyCard extends Component<
);
}
handleIframeExpand(i: IFramelyCard) {
handleIframeExpand(i: MetadataCard) {
i.state.expanded = !i.state.expanded;
i.setState(i.state);
}

View File

@ -28,7 +28,7 @@ import {
communityToChoice,
debounce,
fetchCommunities,
getPageTitle,
getSiteMetadata,
isBrowser,
isImage,
pictrsDeleteToast,
@ -414,8 +414,8 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
WebSocketService.Instance.send(wsClient.search(form));
// Fetch the page title
getPageTitle(this.state.postForm.url).then(d => {
this.state.suggestedTitle = d;
getSiteMetadata(this.state.postForm.url).then(d => {
this.state.suggestedTitle = d.metadata.title;
this.setState(this.state);
});
} else {

View File

@ -41,7 +41,7 @@ import { MomentTime } from "../common/moment-time";
import { PictrsImage } from "../common/pictrs-image";
import { CommunityLink } from "../community/community-link";
import { PersonListing } from "../person/person-listing";
import { IFramelyCard } from "./iframely-card";
import { MetadataCard } from "./metadata-card";
import { PostForm } from "./post-form";
interface PostListingState {
@ -150,7 +150,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
<div class="row">
<div class="col-12">
{post.url && this.showBody && post.embed_title && (
<IFramelyCard post={post} />
<MetadataCard post={post} />
)}
{this.showBody &&
post.body &&

View File

@ -2,6 +2,7 @@ import emojiShortName from "emoji-short-name";
import {
CommentView,
CommunityView,
GetSiteMetadata,
GetSiteResponse,
LemmyHttp,
LemmyWebsocket,
@ -328,10 +329,12 @@ export function routeSearchTypeToEnum(type: string): SearchType {
return SearchType[type];
}
export async function getPageTitle(url: string) {
let res = await fetch(`/iframely/oembed?url=${url}`).then(res => res.json());
let title = await res.title;
return title;
export async function getSiteMetadata(url: string) {
let form: GetSiteMetadata = {
url,
};
let client = new LemmyHttp(httpBase);
return client.getSiteMetadata(form);
}
export function debounce(func: any, wait = 1000, immediate = false) {

2124
yarn.lock

File diff suppressed because it is too large Load Diff