Merge branch 'main' into nicer-error-hnadling

This commit is contained in:
abias 2023-05-22 07:47:17 -04:00
commit fe69f8ee5f
4 changed files with 59 additions and 3 deletions

View file

@ -251,5 +251,12 @@
<symbol id="icon-superscript" viewBox="0 0 20 20">
<path d="M17.5 1h.5V0h-.5a1.49 1.49 0 0 0-1 .39 1.49 1.49 0 0 0-1-.39H15v1h.5a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-.5.5H15v1h.5a1.49 1.49 0 0 0 1-.39 1.49 1.49 0 0 0 1 .39h.5V8h-.5a.5.5 0 0 1-.5-.5v-6a.5.5 0 0 1 .5-.5zm-3.82 15h-2.42a.67.67 0 0 1-.46-.15 1.33 1.33 0 0 1-.28-.34l-2.77-4.44a2.65 2.65 0 0 1-.28.69L5 15.51a2.22 2.22 0 0 1-.29.34.58.58 0 0 1-.42.15H2l4.15-6.19L2.17 4h2.42a.81.81 0 0 1 .41.09.8.8 0 0 1 .24.26L8 8.59a2.71 2.71 0 0 1 .33-.74L10.6 4.4a.69.69 0 0 1 .6-.4h2.32l-4 5.71z" />
</symbol>
<symbol id="icon-share" viewBox="0 0 24 24">
<path d="M21 6C21 7.65685 19.6569 9 18 9C16.3431 9 15 7.65685 15 6C15 4.34315 16.3431 3 18 3C19.6569 3 21 4.34315 21 6Z" stroke-width="2"/>
<path d="M21 18C21 19.6569 19.6569 21 18 21C16.3431 21 15 19.6569 15 18C15 16.3431 16.3431 15 18 15C19.6569 15 21 16.3431 21 18Z" stroke-width="2"/>
<path d="M9 12C9 13.6569 7.65685 15 6 15C4.34315 15 3 13.6569 3 12C3 10.3431 4.34315 9 6 9C7.65685 9 9 10.3431 9 12Z" stroke-width="2"/>
<path d="M8.72046 10.6397L14.9999 7.5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8.70605 13.353L15 16.5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</symbol>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View file

@ -42,6 +42,7 @@ import {
colorList,
commentTreeMaxDepth,
futureDaysToUnixTime,
getCommentParentId,
isAdmin,
isBanned,
isMod,
@ -282,8 +283,15 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
)}
</button>
{this.linkBtn(true)}
<span className="mx-1 badge badge-secondary">
{
this.props.allLanguages.find(
lang => lang.id === cv.comment.language_id
)?.name
}
</span>
{/* This is an expanding spacer for mobile */}
<div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2"></div>
<div className="mr-lg-5 flex-grow-1 flex-lg-grow-0 unselectable pointer mx-2" />
{showScores() && (
<>
<a
@ -1044,11 +1052,14 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
? i18n.t("show_context")
: i18n.t("link");
// The context button should show the parent comment by default
const parentCommentId = getCommentParentId(cv.comment) ?? cv.comment.id;
return (
<>
<Link
className={classnames}
to={`/comment/${cv.comment.id}`}
to={`/comment/${parentCommentId}`}
title={title}
>
<Icon icon="link" classes="icon-inline" />

View file

@ -22,7 +22,7 @@ import {
SavePost,
TransferCommunity,
} from "lemmy-js-client";
import { getExternalHost } from "../../env";
import { getExternalHost, getHttpBase } from "../../env";
import { i18n } from "../../i18next";
import { BanType, PostFormParams, PurgeType } from "../../interfaces";
import { UserService, WebSocketService } from "../../services";
@ -32,6 +32,7 @@ import {
amMod,
canAdmin,
canMod,
canShare,
futureDaysToUnixTime,
hostname,
isAdmin,
@ -46,6 +47,7 @@ import {
numToSI,
relTags,
setupTippy,
share,
showScores,
wsClient,
} from "../../utils";
@ -342,6 +344,13 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
</span>
)}
</li>
<span className="mx-1 badge badge-secondary">
{
this.props.allLanguages.find(
lang => lang.id === post_view.post.language_id
)?.name
}
</span>
<li className="list-inline-item"></li>
{url && !(hostname(url) === getExternalHost()) && (
<>
@ -560,9 +569,19 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
commentsLine(mobile = false) {
let post = this.props.post_view.post;
return (
<div className="d-flex justify-content-start flex-wrap text-muted font-weight-bold mb-1">
{this.commentsButton}
{canShare() && (
<button
className="btn btn-link"
onClick={linkEvent(this, this.handleShare)}
type="button"
>
<Icon icon="share" inline />
</button>
)}
{!post.local && (
<a
className="btn btn-link btn-animate text-muted py-0"
@ -1399,6 +1418,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
this.setState({ showEdit: false });
}
handleShare(i: PostListing) {
const { name, body, id } = i.props.post_view.post;
share({
title: name,
text: body?.slice(0, 50),
url: `${getHttpBase()}/post/${id}`,
});
}
handleShowReportDialog(i: PostListing) {
i.setState({ showReportDialog: !i.state.showReportDialog });
}

View file

@ -1591,3 +1591,13 @@ export function isAuthPath(pathname: string) {
pathname
);
}
export function canShare() {
return isBrowser() && !!navigator.canShare;
}
export function share(shareData: ShareData) {
if (isBrowser()) {
navigator.share(shareData);
}
}