mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 22:31:13 +00:00
Merge branch 'main' into fix-nsfw-blur-spill
This commit is contained in:
commit
b44ae192d2
11 changed files with 54 additions and 75 deletions
|
@ -80,30 +80,6 @@
|
|||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.md-div table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin-bottom: 1rem;
|
||||
border: 1px solid var(--dark);
|
||||
}
|
||||
|
||||
.md-div table th,
|
||||
.md-div table td {
|
||||
padding: 0.3rem;
|
||||
vertical-align: top;
|
||||
border-top: 1px solid var(--dark);
|
||||
border: 1px solid var(--dark);
|
||||
}
|
||||
|
||||
.md-div table thead th {
|
||||
vertical-align: bottom;
|
||||
border-bottom: 2px solid var(--dark);
|
||||
}
|
||||
|
||||
.md-div table tbody + tbody {
|
||||
border-top: 2px solid var(--dark);
|
||||
}
|
||||
|
||||
.vote-bar {
|
||||
margin-top: -6.5px;
|
||||
}
|
||||
|
|
|
@ -421,7 +421,7 @@ async function createSsrHtml(root: string, isoData: IsoDataOptionalSite) {
|
|||
<!-- Required meta tags -->
|
||||
<meta name="Description" content="Lemmy">
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no">
|
||||
<link
|
||||
id="favicon"
|
||||
rel="shortcut icon"
|
||||
|
|
|
@ -2,7 +2,8 @@ import { htmlToText } from "html-to-text";
|
|||
import { Component } from "inferno";
|
||||
import { Helmet } from "inferno-helmet";
|
||||
import { httpExternalPath } from "../../env";
|
||||
import { getLanguages, md } from "../../utils";
|
||||
import { i18n } from "../../i18next";
|
||||
import { md } from "../../utils";
|
||||
|
||||
interface HtmlTagsProps {
|
||||
title: string;
|
||||
|
@ -17,11 +18,10 @@ export class HtmlTags extends Component<HtmlTagsProps, any> {
|
|||
const url = httpExternalPath(this.props.path);
|
||||
const desc = this.props.description;
|
||||
const image = this.props.image;
|
||||
const lang = getLanguages()[0];
|
||||
|
||||
return (
|
||||
<Helmet title={this.props.title}>
|
||||
<html lang={lang == "browser" ? "en" : lang} />
|
||||
<html lang={i18n.resolvedLanguage} />
|
||||
|
||||
{["title", "og:title", "twitter:title"].map(t => (
|
||||
<meta key={t} property={t} content={this.props.title} />
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Component } from "inferno";
|
||||
import moment from "moment";
|
||||
import { i18n } from "../../i18next";
|
||||
import { capitalizeFirstLetter, getLanguages } from "../../utils";
|
||||
import { capitalizeFirstLetter } from "../../utils";
|
||||
import { Icon } from "./icon";
|
||||
|
||||
interface MomentTimeProps {
|
||||
|
@ -15,9 +15,7 @@ export class MomentTime extends Component<MomentTimeProps, any> {
|
|||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
|
||||
const lang = getLanguages();
|
||||
|
||||
moment.locale(lang);
|
||||
moment.locale([...i18n.languages]);
|
||||
}
|
||||
|
||||
createdAndModifiedTimes() {
|
||||
|
|
|
@ -244,9 +244,10 @@ export class Home extends Component<any, HomeState> {
|
|||
}
|
||||
|
||||
async componentDidMount() {
|
||||
if (!this.state.isIsomorphic) {
|
||||
if (!this.state.isIsomorphic || !this.isoData.routeData.length) {
|
||||
await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
|
||||
}
|
||||
|
||||
setupTippy();
|
||||
}
|
||||
|
||||
|
@ -456,7 +457,7 @@ export class Home extends Component<any, HomeState> {
|
|||
}
|
||||
|
||||
trendingCommunities(isMobile = false) {
|
||||
switch (this.state.trendingCommunitiesRes.state) {
|
||||
switch (this.state.trendingCommunitiesRes?.state) {
|
||||
case "loading":
|
||||
return (
|
||||
<h5>
|
||||
|
@ -573,7 +574,7 @@ export class Home extends Component<any, HomeState> {
|
|||
const siteRes = this.state.siteRes;
|
||||
|
||||
if (dataType === DataType.Post) {
|
||||
switch (this.state.postsRes.state) {
|
||||
switch (this.state.postsRes?.state) {
|
||||
case "loading":
|
||||
return (
|
||||
<h5>
|
||||
|
|
|
@ -186,7 +186,9 @@ export class Login extends Component<any, State> {
|
|||
UserService.Instance.myUserInfo = site.data.my_user;
|
||||
}
|
||||
|
||||
i.props.history.replace("/");
|
||||
i.props.history.action === "PUSH"
|
||||
? i.props.history.back()
|
||||
: i.props.history.replace("/");
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import {
|
|||
fetchCommunities,
|
||||
fetchThemeList,
|
||||
fetchUsers,
|
||||
getLanguages,
|
||||
myAuth,
|
||||
myAuthRequired,
|
||||
personToChoice,
|
||||
|
@ -1058,12 +1057,12 @@ export class Settings extends Component<any, SettingsState> {
|
|||
}
|
||||
|
||||
handleInterfaceLangChange(i: Settings, event: any) {
|
||||
const newLang = event.target.value ?? "browser";
|
||||
i18n.changeLanguage(newLang === "browser" ? navigator.languages : newLang);
|
||||
|
||||
i.setState(
|
||||
s => ((s.saveUserSettingsForm.interface_language = event.target.value), s)
|
||||
);
|
||||
i18n.changeLanguage(
|
||||
getLanguages(i.state.saveUserSettingsForm.interface_language).at(0)
|
||||
);
|
||||
}
|
||||
|
||||
handleDiscussionLanguageChange(val: number[]) {
|
||||
|
|
|
@ -1382,9 +1382,12 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
}
|
||||
|
||||
showMobilePreview() {
|
||||
const body = this.postView.post.body;
|
||||
const { body, id } = this.postView.post;
|
||||
|
||||
return !this.showBody && body ? (
|
||||
<Link className="text-body" to={`/post/${id}`}>
|
||||
<div className="md-div mb-1 preview-lines">{body}</div>
|
||||
</Link>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
|
|
|
@ -68,7 +68,7 @@ export class PostListings extends Component<PostListingsProps, any> {
|
|||
return (
|
||||
<div>
|
||||
{this.posts.length > 0 ? (
|
||||
this.posts.map(post_view => (
|
||||
this.posts.map((post_view, idx) => (
|
||||
<>
|
||||
<PostListing
|
||||
post_view={post_view}
|
||||
|
@ -96,7 +96,9 @@ export class PostListings extends Component<PostListingsProps, any> {
|
|||
onAddAdmin={this.props.onAddAdmin}
|
||||
onTransferCommunity={this.props.onTransferCommunity}
|
||||
/>
|
||||
<hr className="my-3" />
|
||||
{idx + 1 !== this.posts.length && (
|
||||
<hr className="my-3 border border-primary" />
|
||||
)}
|
||||
</>
|
||||
))
|
||||
) : (
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import i18next, { i18nTyped, Resource } from "i18next";
|
||||
import { UserService } from "./services";
|
||||
import { ar } from "./translations/ar";
|
||||
import { bg } from "./translations/bg";
|
||||
import { ca } from "./translations/ca";
|
||||
|
@ -30,7 +31,7 @@ import { sv } from "./translations/sv";
|
|||
import { vi } from "./translations/vi";
|
||||
import { zh } from "./translations/zh";
|
||||
import { zh_Hant } from "./translations/zh_Hant";
|
||||
import { getLanguages } from "./utils";
|
||||
import { isBrowser } from "./utils";
|
||||
|
||||
export const languages = [
|
||||
{ resource: ar, code: "ar", name: "العربية" },
|
||||
|
@ -73,12 +74,31 @@ function format(value: any, format: any): any {
|
|||
return format === "uppercase" ? value.toUpperCase() : value;
|
||||
}
|
||||
|
||||
i18next.init({
|
||||
class LanguageDetector {
|
||||
static readonly type = "languageDetector";
|
||||
|
||||
detect() {
|
||||
const langs: string[] = [];
|
||||
|
||||
const myLang =
|
||||
UserService.Instance.myUserInfo?.local_user_view.local_user
|
||||
.interface_language ?? "browser";
|
||||
|
||||
if (myLang !== "browser") langs.push(myLang);
|
||||
|
||||
if (isBrowser()) langs.push(...navigator.languages);
|
||||
|
||||
return langs;
|
||||
}
|
||||
}
|
||||
|
||||
i18next.use(LanguageDetector).init({
|
||||
debug: false,
|
||||
compatibilityJSON: "v3",
|
||||
supportedLngs: languages.map(l => l.code),
|
||||
nonExplicitSupportedLngs: true,
|
||||
// load: 'languageOnly',
|
||||
// initImmediate: false,
|
||||
lng: getLanguages()[0],
|
||||
fallbackLng: "en",
|
||||
resources,
|
||||
interpolation: { format },
|
||||
|
|
|
@ -42,7 +42,7 @@ import moment from "moment";
|
|||
import tippy from "tippy.js";
|
||||
import Toastify from "toastify-js";
|
||||
import { getHttpBase } from "./env";
|
||||
import { i18n, languages } from "./i18next";
|
||||
import { i18n } from "./i18next";
|
||||
import { CommentNodeI, DataType, IsoData, VoteType } from "./interfaces";
|
||||
import { HttpService, UserService } from "./services";
|
||||
|
||||
|
@ -399,31 +399,6 @@ export function debounce<T extends any[], R>(
|
|||
} as (...e: T) => R;
|
||||
}
|
||||
|
||||
export function getLanguages(
|
||||
override?: string,
|
||||
myUserInfo = UserService.Instance.myUserInfo
|
||||
): string[] {
|
||||
const myLang = myUserInfo?.local_user_view.local_user.interface_language;
|
||||
const lang = override || myLang || "browser";
|
||||
|
||||
if (lang == "browser" && isBrowser()) {
|
||||
return getBrowserLanguages();
|
||||
} else {
|
||||
return [lang];
|
||||
}
|
||||
}
|
||||
|
||||
function getBrowserLanguages(): string[] {
|
||||
// Intersect lemmy's langs, with the browser langs
|
||||
const langs = languages ? languages.map(l => l.code) : ["en"];
|
||||
|
||||
// NOTE, mobile browsers seem to be missing this list, so append en
|
||||
const allowedLangs = navigator.languages
|
||||
.concat("en")
|
||||
.filter(v => langs.includes(v));
|
||||
return allowedLangs;
|
||||
}
|
||||
|
||||
export async function fetchThemeList(): Promise<string[]> {
|
||||
return fetch("/css/themelist").then(res => res.json());
|
||||
}
|
||||
|
@ -739,7 +714,7 @@ function setupMarkdown() {
|
|||
defs: emojiDefs,
|
||||
})
|
||||
.disable("image");
|
||||
var defaultRenderer = md.renderer.rules.image;
|
||||
const defaultRenderer = md.renderer.rules.image;
|
||||
md.renderer.rules.image = function (
|
||||
tokens: Token[],
|
||||
idx: number,
|
||||
|
@ -758,6 +733,9 @@ function setupMarkdown() {
|
|||
const alt_text = item.content;
|
||||
return `<img class="icon icon-emoji" src="${src}" title="${title}" alt="${alt_text}"/>`;
|
||||
};
|
||||
md.renderer.rules.table_open = function () {
|
||||
return '<table class="table">';
|
||||
};
|
||||
}
|
||||
|
||||
export function getEmojiMart(
|
||||
|
@ -1273,7 +1251,7 @@ export function personSelectName({
|
|||
|
||||
export function initializeSite(site?: GetSiteResponse) {
|
||||
UserService.Instance.myUserInfo = site?.my_user;
|
||||
i18n.changeLanguage(getLanguages()[0]);
|
||||
i18n.changeLanguage();
|
||||
if (site) {
|
||||
setupEmojiDataModel(site.custom_emojis ?? []);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue