From 1ed148d3d230a5c30dea241d8065eee5c4abf381 Mon Sep 17 00:00:00 2001 From: ayan4m1 Date: Thu, 15 Jun 2023 08:23:55 -0400 Subject: [PATCH 1/8] fix:
is almost invisible in darkly theme --- src/shared/components/post/post-listings.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shared/components/post/post-listings.tsx b/src/shared/components/post/post-listings.tsx index 098a015d..294b9494 100644 --- a/src/shared/components/post/post-listings.tsx +++ b/src/shared/components/post/post-listings.tsx @@ -68,7 +68,7 @@ export class PostListings extends Component { return (
{this.posts.length > 0 ? ( - this.posts.map(post_view => ( + this.posts.map((post_view: PostView, idx: number) => ( <> { onAddAdmin={this.props.onAddAdmin} onTransferCommunity={this.props.onTransferCommunity} /> -
+ {idx + 1 !== this.posts.length && ( +
+ )} )) ) : ( From 1dd8cb09949255593b3a58bd447ac9915b1d41c6 Mon Sep 17 00:00:00 2001 From: ayan4m1 Date: Thu, 15 Jun 2023 08:31:36 -0400 Subject: [PATCH 2/8] remove explicit types --- src/shared/components/post/post-listings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/components/post/post-listings.tsx b/src/shared/components/post/post-listings.tsx index 294b9494..00370f03 100644 --- a/src/shared/components/post/post-listings.tsx +++ b/src/shared/components/post/post-listings.tsx @@ -68,7 +68,7 @@ export class PostListings extends Component { return (
{this.posts.length > 0 ? ( - this.posts.map((post_view: PostView, idx: number) => ( + this.posts.map((post_view, idx) => ( <> Date: Thu, 15 Jun 2023 11:48:30 -0400 Subject: [PATCH 3/8] add user-scalable=no to meta tag --- src/server/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/index.tsx b/src/server/index.tsx index 06dc33a4..3a12ad7e 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -421,7 +421,7 @@ async function createSsrHtml(root: string, isoData: IsoDataOptionalSite) { - + Date: Thu, 15 Jun 2023 12:29:24 -0400 Subject: [PATCH 4/8] go back if last history action was push, fix bug preventing navigation to / working from login --- src/shared/components/home/home.tsx | 7 ++++--- src/shared/components/home/login.tsx | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 8be98304..1abb1ee3 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -244,9 +244,10 @@ export class Home extends Component { } 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 { } trendingCommunities(isMobile = false) { - switch (this.state.trendingCommunitiesRes.state) { + switch (this.state.trendingCommunitiesRes?.state) { case "loading": return (
@@ -573,7 +574,7 @@ export class Home extends Component { const siteRes = this.state.siteRes; if (dataType === DataType.Post) { - switch (this.state.postsRes.state) { + switch (this.state.postsRes?.state) { case "loading": return (
diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index 94915542..29972151 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -186,7 +186,9 @@ export class Login extends Component { UserService.Instance.myUserInfo = site.data.my_user; } - i.props.history.replace("/"); + i.props.history.action === "PUSH" + ? i.props.history.back() + : i.props.history.push("/"); break; } From 114ad262c3fd0da01fca98a4ea8fe094b953beb9 Mon Sep 17 00:00:00 2001 From: Alec Armbruster Date: Thu, 15 Jun 2023 12:38:42 -0400 Subject: [PATCH 5/8] use .replace() instead --- src/shared/components/home/login.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index 29972151..381c13bb 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -188,7 +188,7 @@ export class Login extends Component { i.props.history.action === "PUSH" ? i.props.history.back() - : i.props.history.push("/"); + : i.props.history.replace("/"); break; } From e470db3fde147855789f0442f0bc9e26e32a67e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Mro=CC=81z?= Date: Thu, 15 Jun 2023 19:21:42 +0200 Subject: [PATCH 6/8] feat(post-listing): Add link to post for mobile preview --- src/shared/components/post/post-listing.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index d5fc785c..60e188a3 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1382,9 +1382,12 @@ export class PostListing extends Component { } showMobilePreview() { - const body = this.postView.post.body; + const { body, id } = this.postView.post; + return !this.showBody && body ? ( -
{body}
+ +
{body}
+ ) : ( <> ); From 79f40095416ad623f18aa0042f7be9c7ed691582 Mon Sep 17 00:00:00 2001 From: Andrew DeLisa Date: Thu, 15 Jun 2023 17:42:22 -0400 Subject: [PATCH 7/8] Improve the look of tables (#1299) * feat(css): remove table styling that overrides bootstrap * feat(utils): style MD tables appropriately with bootstrap class --- src/assets/css/main.css | 24 ------------------------ src/shared/utils.ts | 5 ++++- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/assets/css/main.css b/src/assets/css/main.css index e1adfc53..82f8433e 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -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; } diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 4a3b298a..067b78ac 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -739,7 +739,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 +758,9 @@ function setupMarkdown() { const alt_text = item.content; return `${alt_text}`; }; + md.renderer.rules.table_open = function () { + return ''; + }; } export function getEmojiMart( From 882efe128a870f33c5bff6a97caced79d1b57f6f Mon Sep 17 00:00:00 2001 From: Yuri Pieters Date: Fri, 16 Jun 2023 15:49:23 +0100 Subject: [PATCH 8/8] Match more specific locales to supported ones (#1241) To do this, replace the current system for choosing the language with one that makes use of i18next features. Co-authored-by: Yuri Pieters Co-authored-by: Dessalines --- src/shared/components/common/html-tags.tsx | 6 ++-- src/shared/components/common/moment-time.tsx | 6 ++-- src/shared/components/person/settings.tsx | 7 ++--- src/shared/i18next.ts | 26 ++++++++++++++++-- src/shared/utils.ts | 29 ++------------------ 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/shared/components/common/html-tags.tsx b/src/shared/components/common/html-tags.tsx index 0e6cb2d0..f32b0fc0 100644 --- a/src/shared/components/common/html-tags.tsx +++ b/src/shared/components/common/html-tags.tsx @@ -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 { const url = httpExternalPath(this.props.path); const desc = this.props.description; const image = this.props.image; - const lang = getLanguages()[0]; return ( - + {["title", "og:title", "twitter:title"].map(t => ( diff --git a/src/shared/components/common/moment-time.tsx b/src/shared/components/common/moment-time.tsx index 10714f5b..30c1682c 100644 --- a/src/shared/components/common/moment-time.tsx +++ b/src/shared/components/common/moment-time.tsx @@ -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 { constructor(props: any, context: any) { super(props, context); - const lang = getLanguages(); - - moment.locale(lang); + moment.locale([...i18n.languages]); } createdAndModifiedTimes() { diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index a29f61b0..56d57a7a 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -25,7 +25,6 @@ import { fetchCommunities, fetchThemeList, fetchUsers, - getLanguages, myAuth, myAuthRequired, personToChoice, @@ -1058,12 +1057,12 @@ export class Settings extends Component { } 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[]) { diff --git a/src/shared/i18next.ts b/src/shared/i18next.ts index eaedbbf8..47ca6501 100644 --- a/src/shared/i18next.ts +++ b/src/shared/i18next.ts @@ -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 }, diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 067b78ac..766e38a8 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -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( } 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 { return fetch("/css/themelist").then(res => res.json()); } @@ -1276,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 ?? []); }