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", "husky": "^7.0.1",
"import-sort-style-module": "^6.0.0", "import-sort-style-module": "^6.0.0",
"iso-639-1": "^2.1.9", "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", "lint-staged": "^11.0.1",
"mini-css-extract-plugin": "^2.1.0", "mini-css-extract-plugin": "^2.1.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",

View file

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

View file

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

View file

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

View file

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

2124
yarn.lock

File diff suppressed because it is too large Load diff