mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-23 03:11:25 +00:00
Swapping out iframely. (#374)
* Swapping out iframely. * Renaming iframely-card to metadata-card
This commit is contained in:
parent
62e410c382
commit
2356b0d62f
6 changed files with 884 additions and 1277 deletions
|
@ -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",
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
|
@ -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 {
|
||||||
|
|
|
@ -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 &&
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue