From 3ca24607fbf5c08f83243fc259dcd159bb0a24f2 Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Sat, 17 Jun 2023 09:37:03 +0100 Subject: [PATCH 01/13] add hours as sorting options --- src/shared/components/common/sort-select.tsx | 3 +++ src/shared/utils.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/shared/components/common/sort-select.tsx b/src/shared/components/common/sort-select.tsx index dac6e20d..1fd32076 100644 --- a/src/shared/components/common/sort-select.tsx +++ b/src/shared/components/common/sort-select.tsx @@ -66,6 +66,9 @@ export class SortSelect extends Component { + + + diff --git a/src/shared/utils.ts b/src/shared/utils.ts index c7fbca6b..abb30629 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -986,6 +986,9 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { export function convertCommentSortType(sort: SortType): CommentSortType { if ( sort == "TopAll" || + sort == "TopHour" || + sort == "TopSixHour" || + sort == "TopTwelveHour" || sort == "TopDay" || sort == "TopWeek" || sort == "TopMonth" || From 5e9a414dfcbde436d803953871bbe3ada464d90a Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Sun, 18 Jun 2023 00:51:32 +0100 Subject: [PATCH 02/13] clean code --- src/shared/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/utils.ts b/src/shared/utils.ts index abb30629..86a32d16 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -986,9 +986,9 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { export function convertCommentSortType(sort: SortType): CommentSortType { if ( sort == "TopAll" || - sort == "TopHour" || - sort == "TopSixHour" || - sort == "TopTwelveHour" || + sort == "TopHour" || + sort == "TopSixHour" || + sort == "TopTwelveHour" || sort == "TopDay" || sort == "TopWeek" || sort == "TopMonth" || From 747bc943a966d45bb2547287a630f1714991e860 Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Wed, 21 Jun 2023 01:21:14 +0100 Subject: [PATCH 03/13] refactor if into switch case --- src/shared/utils.ts | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/shared/utils.ts b/src/shared/utils.ts index be7b11b0..d6946cce 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -853,24 +853,28 @@ export function commentsToFlatNodes(comments: CommentView[]): CommentNodeI[] { } export function convertCommentSortType(sort: SortType): CommentSortType { - if ( - sort == "TopAll" || - sort == "TopHour" || - sort == "TopSixHour" || - sort == "TopTwelveHour" || - sort == "TopDay" || - sort == "TopWeek" || - sort == "TopMonth" || - sort == "TopYear" - ) { - return "Top"; - } else if (sort == "New") { - return "New"; - } else if (sort == "Hot" || sort == "Active") { - return "Hot"; - } else { - return "Hot"; - } + switch(sort) { + case "TopAll": + case "TopHour": + case "TopSixHour": + case "TopTwelveHour": + case "TopDay": + case "TopWeek": + case "TopMonth": + case "TopYear": { + return "Top"; + } + case "New": { + return "New"; + } + case "Hot": + case "Active": { + return "Hot"; + } + default: { + return "Hot"; + } + } } export function buildCommentsTree( From c06d38633766f466d8b744aa44c7418765ad57de Mon Sep 17 00:00:00 2001 From: Ivo Barros Date: Thu, 22 Jun 2023 04:52:04 +0100 Subject: [PATCH 07/13] prettier --- src/shared/components/common/sort-select.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/shared/components/common/sort-select.tsx b/src/shared/components/common/sort-select.tsx index 33c5c85f..4d03ab5d 100644 --- a/src/shared/components/common/sort-select.tsx +++ b/src/shared/components/common/sort-select.tsx @@ -68,11 +68,17 @@ export class SortSelect extends Component { ───── - - + + - + From 5512ee205ad1b6ee40b99c66af3472db5acc019e Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 22 Jun 2023 10:32:39 -0400 Subject: [PATCH 08/13] add fallback style tag --- src/server/utils/create-ssr-html.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index ae766b3a..a7a87ac9 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -8,6 +8,8 @@ import { fetchIconPng } from "./fetch-icon-png"; const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || ""; +const fallbackStyleTag = ``; + let appleTouchIcon: string | undefined = undefined; export async function createSsrHtml( @@ -85,7 +87,7 @@ export async function createSsrHtml( - ${helmet.link.toString()} + ${helmet.link.toString() || fallbackStyleTag} From a1d935991b04e491eab392e2115bda3c3442e830 Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 22 Jun 2023 10:43:03 -0400 Subject: [PATCH 09/13] rethink it a bit --- src/server/utils/create-ssr-html.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index a7a87ac9..39725fa5 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -4,12 +4,11 @@ import serialize from "serialize-javascript"; import sharp from "sharp"; import { favIconPngUrl, favIconUrl } from "../../shared/config"; import { ILemmyConfig, IsoDataOptionalSite } from "../../shared/interfaces"; +import { buildThemeList } from "./build-themes-list"; import { fetchIconPng } from "./fetch-icon-png"; const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || ""; -const fallbackStyleTag = ``; - let appleTouchIcon: string | undefined = undefined; export async function createSsrHtml( @@ -18,6 +17,10 @@ export async function createSsrHtml( ) { const site = isoData.site_res; + const fallbackTheme = ``; + if (!appleTouchIcon) { appleTouchIcon = site?.site_view.site.icon ? `data:image/png;base64,${sharp( @@ -87,7 +90,7 @@ export async function createSsrHtml( - ${helmet.link.toString() || fallbackStyleTag} + ${helmet.link.toString() || fallbackTheme} From 63b14accec80de9e440266f3e7d92235a85f24dd Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:22:36 -0400 Subject: [PATCH 10/13] rethink it a bit --- src/shared/components/community/community.tsx | 6 ------ src/shared/components/home/home.tsx | 6 ------ src/shared/utils/browser/restore-scroll-position.ts | 1 + src/shared/utils/browser/save-scroll-position.ts | 1 + 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 7eefe0eb..111b47cd 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -15,7 +15,6 @@ import { updateCommunityBlock, updatePersonBlock, } from "@utils/app"; -import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -229,10 +228,6 @@ export class Community extends Component< setupTippy(); } - componentWillUnmount() { - saveScrollPosition(this.context); - } - static async fetchInitialData({ client, path, @@ -609,7 +604,6 @@ export class Community extends Component< }); } - restoreScrollPosition(this.context); setupTippy(); } diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 0d91bdbc..4a84664b 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -13,7 +13,6 @@ import { showLocal, updatePersonBlock, } from "@utils/app"; -import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -293,10 +292,6 @@ export class Home extends Component { setupTippy(); } - componentWillUnmount() { - saveScrollPosition(this.context); - } - static async fetchInitialData({ client, auth, @@ -800,7 +795,6 @@ export class Home extends Component { }); } - restoreScrollPosition(this.context); setupTippy(); } diff --git a/src/shared/utils/browser/restore-scroll-position.ts b/src/shared/utils/browser/restore-scroll-position.ts index f1534644..6986ae59 100644 --- a/src/shared/utils/browser/restore-scroll-position.ts +++ b/src/shared/utils/browser/restore-scroll-position.ts @@ -1,5 +1,6 @@ export default function restoreScrollPosition(context: any) { const path: string = context.router.route.location.pathname; const y = Number(sessionStorage.getItem(`scrollPosition_${path}`)); + window.scrollTo(0, y); } diff --git a/src/shared/utils/browser/save-scroll-position.ts b/src/shared/utils/browser/save-scroll-position.ts index 48353287..596d5d9f 100644 --- a/src/shared/utils/browser/save-scroll-position.ts +++ b/src/shared/utils/browser/save-scroll-position.ts @@ -1,5 +1,6 @@ export default function saveScrollPosition(context: any) { const path: string = context.router.route.location.pathname; const y = window.scrollY; + sessionStorage.setItem(`scrollPosition_${path}`, y.toString()); } From 955ca826cd4d8e764578ddd37d302897c91340b8 Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Thu, 22 Jun 2023 12:28:27 -0400 Subject: [PATCH 11/13] Enable users to zoom on mobile --- src/server/utils/create-ssr-html.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index 39725fa5..55788ec5 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -73,7 +73,7 @@ export async function createSsrHtml( - + Date: Thu, 22 Jun 2023 12:50:05 -0400 Subject: [PATCH 12/13] Omit user-scalable to use default --- src/server/utils/create-ssr-html.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index 55788ec5..13775981 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -73,7 +73,7 @@ export async function createSsrHtml( - + Date: Thu, 22 Jun 2023 16:52:47 +0000 Subject: [PATCH 13/13] Fix avatar alignment issue (#1475) --- src/shared/components/common/pictrs-image.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/components/common/pictrs-image.tsx b/src/shared/components/common/pictrs-image.tsx index 74437490..31fb1229 100644 --- a/src/shared/components/common/pictrs-image.tsx +++ b/src/shared/components/common/pictrs-image.tsx @@ -22,7 +22,7 @@ export class PictrsImage extends Component { render() { return ( - + @@ -31,7 +31,7 @@ export class PictrsImage extends Component { alt={this.alt()} title={this.alt()} loading="lazy" - className={classNames({ + className={classNames("overflow-hidden pictrs-image", { "img-fluid": !this.props.icon && !this.props.iconOverlay, banner: this.props.banner, "thumbnail rounded":