From 658aee2e53fbc4fa2fddf4dcce17aa050ef11aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20=C4=BDach?= Date: Tue, 23 Feb 2021 21:36:53 +0000 Subject: [PATCH 01/21] Improve rendering in older browsers ...like SailfishOS. --- src/assets/css/main.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 36f022b8..5f67199e 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -228,17 +228,20 @@ hr { height: 1.5em; width: 1.5em; background: rgba(0, 0, 0, 0.4); + background-color: rgba(0, 0, 0, 0.4); border-bottom-left-radius: 0.25rem !important; border-top-right-radius: 0.25rem !important; } .link-overlay:hover { transition: 0.1s; + -webkit-transition: 0.1s; opacity: 1; } .link-overlay { transition: opacity 0.1s ease-in-out; + -webkit-transition: opacity 0.1s ease-in-out; position: absolute; opacity: 0; left: 0; @@ -246,6 +249,7 @@ hr { width: 100%; padding: 10px; background: rgba(0, 0, 0, 0.6); + background-color: rgba(0, 0, 0, 0.6); } .placeholder { @@ -285,6 +289,7 @@ pre { } .hide-input { background: transparent !important; + background-color: transparent !important; width: 0px !important; padding: 0 !important; } From 19c0223b79d6dbb50afbd19d1779fe35b077ceb2 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Mon, 1 Mar 2021 21:00:43 +0100 Subject: [PATCH 02/21] Generate typescript i18n types --- generate_translations.js | 57 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/generate_translations.js b/generate_translations.js index 0cab8e36..313e8003 100644 --- a/generate_translations.js +++ b/generate_translations.js @@ -1,27 +1,64 @@ -fs = require('fs'); +const fs = require("fs"); -let translationDir = 'lemmy-translations/translations/'; -let outDir = 'src/shared/translations/'; +const translationDir = "lemmy-translations/translations/"; +const outDir = "src/shared/translations/"; fs.mkdirSync(outDir, { recursive: true }); fs.readdir(translationDir, (_err, files) => { files.forEach(filename => { - const lang = filename.split('.')[0]; + const lang = filename.split(".")[0]; try { const json = JSON.parse( - fs.readFileSync(translationDir + filename, 'utf8') + fs.readFileSync(translationDir + filename, "utf8") ); - var data = `export const ${lang} = {\n translation: {`; - for (var key in json) { + let data = `export const ${lang} = {\n translation: {`; + for (const key in json) { if (key in json) { const value = json[key].replace(/"/g, '\\"'); - data = `${data}\n ${key}: "${value}",`; + data += `\n ${key}: "${value}",`; } } - data += '\n },\n};'; - const target = outDir + lang + '.ts'; + data += "\n },\n};"; + const target = outDir + lang + ".ts"; fs.writeFileSync(target, data); } catch (err) { console.error(err); } }); }); + +// generate types for i18n keys +const baseLanguage = "en"; + +fs.readFile(`${translationDir}${baseLanguage}.json`, "utf8", (_, fileStr) => { + const keys = Object.keys(JSON.parse(fileStr)); + + const data = `import * as i18n from "i18next"; + +type I18nKeys = +${keys.map(key => ` | "${key}"`).join("\n")}; + +declare module "i18next" { + export interface TFunction { + // basic usage + < + TResult extends TFunctionResult = string, + TInterpolationMap extends object = StringMap + >( + key: I18nKeys | I18nKeys[], + options?: TOptions | string + ): TResult; + // overloaded usage + < + TResult extends TFunctionResult = string, + TInterpolationMap extends object = StringMap + >( + key: I18nKeys | I18nKeys[], + defaultValue?: string, + options?: TOptions | string + ): TResult; + } +} +`; + + fs.writeFileSync(`${outDir}i18next.d.ts`, data); +}); From 66cc9416e4b8072414bb24c26f75ab859537db25 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Mon, 1 Mar 2021 21:33:57 +0100 Subject: [PATCH 03/21] Improve type safety --- generate_translations.js | 18 +++++++++++------- src/shared/i18next.ts | 6 ++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/generate_translations.js b/generate_translations.js index 313e8003..594f574c 100644 --- a/generate_translations.js +++ b/generate_translations.js @@ -32,17 +32,17 @@ const baseLanguage = "en"; fs.readFile(`${translationDir}${baseLanguage}.json`, "utf8", (_, fileStr) => { const keys = Object.keys(JSON.parse(fileStr)); - const data = `import * as i18n from "i18next"; - -type I18nKeys = -${keys.map(key => ` | "${key}"`).join("\n")}; + const data = `import { i18n } from "i18next"; declare module "i18next" { - export interface TFunction { + export type I18nKeys = +${keys.map(key => ` | "${key}"`).join("\n")}; + + export interface TFunctionTyped { // basic usage < TResult extends TFunctionResult = string, - TInterpolationMap extends object = StringMap + TInterpolationMap extends Record = StringMap >( key: I18nKeys | I18nKeys[], options?: TOptions | string @@ -50,13 +50,17 @@ declare module "i18next" { // overloaded usage < TResult extends TFunctionResult = string, - TInterpolationMap extends object = StringMap + TInterpolationMap extends Record = StringMap >( key: I18nKeys | I18nKeys[], defaultValue?: string, options?: TOptions | string ): TResult; } + + export interface i18nTyped extends i18n { + t: TFunctionTyped; + } } `; diff --git a/src/shared/i18next.ts b/src/shared/i18next.ts index 99289032..3d3d5a1f 100644 --- a/src/shared/i18next.ts +++ b/src/shared/i18next.ts @@ -1,4 +1,4 @@ -import i18next from "i18next"; +import i18next, { i18nTyped } from "i18next"; import { getLanguage } from "./utils"; import { en } from "./translations/en"; import { el } from "./translations/el"; @@ -82,4 +82,6 @@ i18next.init({ interpolation: { format }, }); -export { i18next as i18n, resources }; +export const i18n = i18next as i18nTyped; + +export { resources }; From 1939664d736ce3ddbaa84c7106b510df4b950d86 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Mon, 1 Mar 2021 21:44:02 +0100 Subject: [PATCH 04/21] Add I18nKeys type to errCode --- src/shared/components/no-match.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared/components/no-match.tsx b/src/shared/components/no-match.tsx index b11c0e54..175f4a9b 100644 --- a/src/shared/components/no-match.tsx +++ b/src/shared/components/no-match.tsx @@ -1,8 +1,11 @@ +import { I18nKeys } from "i18next"; import { Component } from "inferno"; import { i18n } from "../i18next"; export class NoMatch extends Component { - private errCode = new URLSearchParams(this.props.location.search).get("err"); + private errCode = new URLSearchParams(this.props.location.search).get( + "err" + ) as I18nKeys; constructor(props: any, context: any) { super(props, context); From aea005b4ccdcf4b4353769147920ee45e946bd53 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 1 Mar 2021 16:20:08 -0500 Subject: [PATCH 05/21] Adding thai language. --- src/shared/i18next.ts | 2 ++ src/shared/utils.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/shared/i18next.ts b/src/shared/i18next.ts index 99289032..8f300055 100644 --- a/src/shared/i18next.ts +++ b/src/shared/i18next.ts @@ -31,6 +31,7 @@ import { sr_Latn } from "./translations/sr_Latn"; import { da } from "./translations/da"; import { oc } from "./translations/oc"; import { hr } from "./translations/hr"; +import { th } from "./translations/th"; // https://github.com/nimbusec-oss/inferno-i18next/blob/master/tests/T.test.js#L66 const resources = { @@ -65,6 +66,7 @@ const resources = { da, oc, hr, + th, }; function format(value: any, format: any): any { diff --git a/src/shared/utils.ts b/src/shared/utils.ts index cb7569df..887030fb 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -118,6 +118,7 @@ export const languages = [ { code: "sv", name: "Svenska" }, { code: "sq", name: "Shqip" }, { code: "sr_Latn", name: "srpski" }, + { code: "th", name: "ภาษาไทย" }, { code: "tr", name: "Türkçe" }, { code: "uk", name: "Українська Mова" }, { code: "ru", name: "Русский" }, @@ -445,6 +446,8 @@ export function getMomentLanguage(): string { lang = "oc"; } else if (lang.startsWith("hr")) { lang = "hr"; + } else if (lang.startsWith("th")) { + lang = "th"; } else { lang = "en"; } From e5fa94c8c8435735bec6ff5a10acbddd97f621cb Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 1 Mar 2021 16:23:10 -0500 Subject: [PATCH 06/21] Updating translations. --- lemmy-translations | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemmy-translations b/lemmy-translations index 6171d85e..bc781022 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 6171d85e4cc9249356f75739aebf319d49ec3889 +Subproject commit bc7810220f45a07df4e5773c6a85e4fc25ea62ba From 5248c9e58c76bbd144fd42ad43ed464de9fc6cf5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 1 Mar 2021 16:23:25 -0500 Subject: [PATCH 07/21] Fixing private message disclaimer. --- src/shared/components/private-message-form.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/components/private-message-form.tsx b/src/shared/components/private-message-form.tsx index 0a68e252..e98c893e 100644 --- a/src/shared/components/private-message-form.tsx +++ b/src/shared/components/private-message-form.tsx @@ -119,8 +119,8 @@ export class PrivateMessageForm extends Component< onClick={linkEvent(this, this.handleShowDisclaimer)} role="button" class="ml-2 pointer text-danger" - data-tippy-content={i18n.t("disclaimer")} - aria-label={i18n.t("disclaimer")} + data-tippy-content={i18n.t("private_message_disclaimer")} + aria-label={i18n.t("private_message_disclaimer")} > From e02075d52d5c6adb45169b0db472b5b8d317a9e2 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 3 Mar 2021 17:59:57 +0100 Subject: [PATCH 08/21] Remove categories --- package.json | 2 +- src/shared/components/communities.tsx | 2 -- src/shared/components/community-form.tsx | 26 ---------------------- src/shared/components/community.tsx | 13 ----------- src/shared/components/create-community.tsx | 25 +-------------------- src/shared/components/post.tsx | 12 ---------- src/shared/components/sidebar.tsx | 8 ------- src/shared/routes.ts | 1 - yarn.lock | 8 +++---- 9 files changed, 6 insertions(+), 91 deletions(-) diff --git a/package.json b/package.json index e427117a..96fd0c26 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "eslint": "^7.20.0", "eslint-plugin-prettier": "^3.3.1", "husky": "^5.1.0", - "lemmy-js-client": "0.9.9", + "lemmy-js-client": "0.10.0-rc.1", "lint-staged": "^10.5.4", "mini-css-extract-plugin": "^1.3.8", "node-fetch": "^2.6.1", diff --git a/src/shared/components/communities.tsx b/src/shared/components/communities.tsx index def03dfc..74a1ac32 100644 --- a/src/shared/components/communities.tsx +++ b/src/shared/components/communities.tsx @@ -124,7 +124,6 @@ export class Communities extends Component { {i18n.t("name")} - {i18n.t("category")} {i18n.t("subscribers")} {i18n.t("users")} / {i18n.t("month")} @@ -144,7 +143,6 @@ export class Communities extends Component { - {cv.category.name} {cv.counts.subscribers} {cv.counts.users_active_month} diff --git a/src/shared/components/community-form.tsx b/src/shared/components/community-form.tsx index 5b8034c5..97d335e2 100644 --- a/src/shared/components/community-form.tsx +++ b/src/shared/components/community-form.tsx @@ -5,7 +5,6 @@ import { EditCommunity, CreateCommunity, UserOperation, - Category, CommunityResponse, CommunityView, } from "lemmy-js-client"; @@ -28,7 +27,6 @@ import { Icon, Spinner } from "./icon"; interface CommunityFormProps { community_view?: CommunityView; // If a community is given, that means this is an edit - categories: Category[]; onCancel?(): any; onCreate?(community: CommunityView): any; onEdit?(community: CommunityView): any; @@ -51,7 +49,6 @@ export class CommunityForm extends Component< communityForm: { name: null, title: null, - category_id: this.props.categories[0].id, nsfw: false, icon: null, banner: null, @@ -80,7 +77,6 @@ export class CommunityForm extends Component< this.state.communityForm = { name: cv.community.name, title: cv.community.title, - category_id: cv.category.id, description: cv.community.description, nsfw: cv.community.nsfw, icon: cv.community.icon, @@ -205,23 +201,6 @@ export class CommunityForm extends Component< /> -
- -
- -
-
{this.props.enableNsfw && (
@@ -304,11 +283,6 @@ export class CommunityForm extends Component< this.setState(this.state); } - handleCommunityCategoryChange(i: CommunityForm, event: any) { - i.state.communityForm.category_id = Number(event.target.value); - i.setState(i.state); - } - handleCommunityNsfwChange(i: CommunityForm, event: any) { i.state.communityForm.nsfw = event.target.checked; i.setState(i.state); diff --git a/src/shared/components/community.tsx b/src/shared/components/community.tsx index ef5c7833..9f492cd3 100644 --- a/src/shared/components/community.tsx +++ b/src/shared/components/community.tsx @@ -19,8 +19,6 @@ import { GetCommentsResponse, CommentResponse, GetSiteResponse, - Category, - ListCategoriesResponse, } from "lemmy-js-client"; import { UserService, WebSocketService } from "../services"; import { PostListings } from "./post-listings"; @@ -72,7 +70,6 @@ interface State { dataType: DataType; sort: SortType; page: number; - categories: Category[]; } interface CommunityProps { @@ -103,7 +100,6 @@ export class Community extends Component { sort: getSortTypeFromProps(this.props), page: getPageFromProps(this.props), siteRes: this.isoData.site_res, - categories: [], }; constructor(props: any, context: any) { @@ -124,14 +120,12 @@ export class Community extends Component { } else { this.state.comments = this.isoData.routeData[1].comments; } - this.state.categories = this.isoData.routeData[2].categories; this.state.communityLoading = false; this.state.postsLoading = false; this.state.commentsLoading = false; } else { this.fetchCommunity(); this.fetchData(); - WebSocketService.Instance.send(wsClient.listCategories()); } setupTippy(); } @@ -211,8 +205,6 @@ export class Community extends Component { promises.push(req.client.getComments(getCommentsForm)); } - promises.push(req.client.listCategories()); - return promises; } @@ -268,7 +260,6 @@ export class Community extends Component { admins={this.state.siteRes.admins} online={this.state.communityRes.online} enableNsfw={this.state.siteRes.site_view.site.enable_nsfw} - categories={this.state.categories} />
@@ -541,10 +532,6 @@ export class Community extends Component { let data = wsJsonToRes(msg).data; createCommentLikeRes(data.comment_view, this.state.comments); this.setState(this.state); - } else if (op == UserOperation.ListCategories) { - let data = wsJsonToRes(msg).data; - this.state.categories = data.categories; - this.setState(this.state); } } } diff --git a/src/shared/components/create-community.tsx b/src/shared/components/create-community.tsx index da449978..e1a9cf8f 100644 --- a/src/shared/components/create-community.tsx +++ b/src/shared/components/create-community.tsx @@ -5,27 +5,19 @@ import { HtmlTags } from "./html-tags"; import { Spinner } from "./icon"; import { CommunityView, - UserOperation, SiteView, - ListCategoriesResponse, - Category, } from "lemmy-js-client"; import { setIsoData, toast, - wsJsonToRes, wsSubscribe, isBrowser, - wsUserOp, - wsClient, } from "../utils"; -import { WebSocketService, UserService } from "../services"; +import { UserService } from "../services"; import { i18n } from "../i18next"; -import { InitialFetchRequest } from "shared/interfaces"; interface CreateCommunityState { site_view: SiteView; - categories: Category[]; loading: boolean; } @@ -34,7 +26,6 @@ export class CreateCommunity extends Component { private subscription: Subscription; private emptyState: CreateCommunityState = { site_view: this.isoData.site_res.site_view, - categories: [], loading: true, }; constructor(props: any, context: any) { @@ -52,10 +43,7 @@ export class CreateCommunity extends Component { // Only fetch the data if coming from another route if (this.isoData.path == this.context.router.route.match.url) { - this.state.categories = this.isoData.routeData[0].categories; this.state.loading = false; - } else { - WebSocketService.Instance.send(wsClient.listCategories()); } } @@ -85,7 +73,6 @@ export class CreateCommunity extends Component {
{i18n.t("create_community")}
@@ -100,20 +87,10 @@ export class CreateCommunity extends Component { this.props.history.push(`/c/${cv.community.name}`); } - static fetchInitialData(req: InitialFetchRequest): Promise[] { - return [req.client.listCategories()]; - } - parseMessage(msg: any) { - let op = wsUserOp(msg); if (msg.error) { // Toast errors are already handled by community-form return; - } else if (op == UserOperation.ListCategories) { - let data = wsJsonToRes(msg).data; - this.state.categories = data.categories; - this.state.loading = false; - this.setState(this.state); } } } diff --git a/src/shared/components/post.tsx b/src/shared/components/post.tsx index 61024991..b1bd9aaa 100644 --- a/src/shared/components/post.tsx +++ b/src/shared/components/post.tsx @@ -21,8 +21,6 @@ import { SearchResponse, GetSiteResponse, GetCommunityResponse, - ListCategoriesResponse, - Category, } from "lemmy-js-client"; import { CommentSortType, @@ -74,7 +72,6 @@ interface PostState { loading: boolean; crossPosts: PostView[]; siteRes: GetSiteResponse; - categories: Category[]; } export class Post extends Component { @@ -91,7 +88,6 @@ export class Post extends Component { loading: true, crossPosts: [], siteRes: this.isoData.site_res, - categories: [], }; constructor(props: any, context: any) { @@ -109,7 +105,6 @@ export class Post extends Component { this.state.postRes.comments, this.state.commentSort ); - this.state.categories = this.isoData.routeData[1].categories; this.state.loading = false; if (isBrowser()) { @@ -120,7 +115,6 @@ export class Post extends Component { } } else { this.fetchPost(); - WebSocketService.Instance.send(wsClient.listCategories()); } } @@ -158,7 +152,6 @@ export class Post extends Component { setOptionalAuth(postForm, req.auth); promises.push(req.client.getPost(postForm)); - promises.push(req.client.listCategories()); return promises; } @@ -402,7 +395,6 @@ export class Post extends Component { online={this.state.postRes.online} enableNsfw={this.state.siteRes.site_view.site.enable_nsfw} showIcon - categories={this.state.categories} />
); @@ -570,10 +562,6 @@ export class Post extends Component { this.state.postRes.post_view.community = data.community_view.community; this.state.postRes.moderators = data.moderators; this.setState(this.state); - } else if (op == UserOperation.ListCategories) { - let data = wsJsonToRes(msg).data; - this.state.categories = data.categories; - this.setState(this.state); } } } diff --git a/src/shared/components/sidebar.tsx b/src/shared/components/sidebar.tsx index 436d6cfa..47de96da 100644 --- a/src/shared/components/sidebar.tsx +++ b/src/shared/components/sidebar.tsx @@ -8,7 +8,6 @@ import { RemoveCommunity, UserViewSafe, AddModToCommunity, - Category, } from "lemmy-js-client"; import { WebSocketService, UserService } from "../services"; import { mdToHtml, getUnixTime, wsClient, authField } from "../utils"; @@ -21,7 +20,6 @@ import { i18n } from "../i18next"; interface SidebarProps { community_view: CommunityView; - categories: Category[]; moderators: CommunityModeratorView[]; admins: UserViewSafe[]; online: number; @@ -60,7 +58,6 @@ export class Sidebar extends Component { this.sidebar() ) : ( { count: counts.comments, })} -
  • - - {community_view.category.name} - -
  • CreateCommunity.fetchInitialData(req), }, { path: `/create_private_message/recipient/:recipient_id`, diff --git a/yarn.lock b/yarn.lock index 357f2b34..349810ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5022,10 +5022,10 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lemmy-js-client@0.9.9: - version "0.9.9" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.9.9.tgz#cd1effe165147d04da93d1265e30dd1daf09c0de" - integrity sha512-+tHghqb02WM/Deizneg/8wO6W6ZqG67y5gZwZb9QQLDcowLZWTmFCwdoYVxLxcH6LBmZ1TvPq7ppumB5vQI1qg== +lemmy-js-client@0.10.0-rc.1: + version "0.10.0-rc.1" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.10.0-rc.1.tgz#4a9b9db8fcc8229d634920d7e66f63ab5db8b28e" + integrity sha512-18TQO+EpE+mgCWSwynfFvDCASUjzTkr73/CbneMMHcqexq2R4donE+pNDFFSDHOeYIbdna0f4GZEJhyeh6826g== levn@^0.4.1: version "0.4.1" From c79f10688e30e30b498eb8137ac4741ada86489d Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 3 Mar 2021 18:02:55 +0100 Subject: [PATCH 09/21] Dont fetch on ARM CI except for tags --- .drone.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.drone.yml b/.drone.yml index 61525604..64871add 100644 --- a/.drone.yml +++ b/.drone.yml @@ -78,6 +78,9 @@ steps: - apk add git - git submodule init - git submodule update --recursive --remote + when: + ref: + - refs/tags/* - name: make release build and push to docker hub image: plugins/docker From b778ca8e2269d9ec2c0ab8a4329fae51e540a7a4 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 3 Mar 2021 22:42:11 -0500 Subject: [PATCH 10/21] Fixing an issue with remove categories --- src/shared/components/create-community.tsx | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/shared/components/create-community.tsx b/src/shared/components/create-community.tsx index e1a9cf8f..4817f40c 100644 --- a/src/shared/components/create-community.tsx +++ b/src/shared/components/create-community.tsx @@ -3,16 +3,8 @@ import { Subscription } from "rxjs"; import { CommunityForm } from "./community-form"; import { HtmlTags } from "./html-tags"; import { Spinner } from "./icon"; -import { - CommunityView, - SiteView, -} from "lemmy-js-client"; -import { - setIsoData, - toast, - wsSubscribe, - isBrowser, -} from "../utils"; +import { CommunityView, SiteView } from "lemmy-js-client"; +import { setIsoData, toast, wsSubscribe, isBrowser } from "../utils"; import { UserService } from "../services"; import { i18n } from "../i18next"; @@ -26,7 +18,7 @@ export class CreateCommunity extends Component { private subscription: Subscription; private emptyState: CreateCommunityState = { site_view: this.isoData.site_res.site_view, - loading: true, + loading: false, }; constructor(props: any, context: any) { super(props, context); @@ -40,11 +32,6 @@ export class CreateCommunity extends Component { toast(i18n.t("not_logged_in"), "danger"); this.context.router.history.push(`/login`); } - - // Only fetch the data if coming from another route - if (this.isoData.path == this.context.router.route.match.url) { - this.state.loading = false; - } } componentWillUnmount() { From ed96c77c9f785f8a42cfda6e87a5ced8a45f8ecc Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 6 Mar 2021 15:06:38 -0500 Subject: [PATCH 11/21] Updating translations. --- lemmy-translations | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemmy-translations b/lemmy-translations index bc781022..a15d6bcb 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit bc7810220f45a07df4e5773c6a85e4fc25ea62ba +Subproject commit a15d6bcb944b63478e9499ca77d6023a675cb002 From 440fda9d51385c1eef38f6c1e0e6ed931b12b915 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 15 Mar 2021 14:09:31 -0400 Subject: [PATCH 12/21] user_ -> person table migration. --- package.json | 2 +- src/server/index.tsx | 2 +- src/shared/components/admin-settings.tsx | 6 +- src/shared/components/app.tsx | 2 +- src/shared/components/comment-form.tsx | 4 +- src/shared/components/comment-node.tsx | 84 +++--- src/shared/components/comment-nodes.tsx | 4 +- src/shared/components/community.tsx | 8 +- src/shared/components/create-community.tsx | 2 +- src/shared/components/create-post.tsx | 2 +- .../components/create-private-message.tsx | 36 +-- src/shared/components/image-upload-form.tsx | 2 +- src/shared/components/inbox.tsx | 99 ++++--- src/shared/components/listing-type-select.tsx | 8 +- src/shared/components/main.tsx | 46 +-- src/shared/components/markdown-textarea.tsx | 6 +- src/shared/components/modlog.tsx | 14 +- src/shared/components/navbar.tsx | 48 +-- .../{user-details.tsx => person-details.tsx} | 42 +-- .../{user-listing.tsx => person-listing.tsx} | 32 +- .../components/{user.tsx => person.tsx} | 277 +++++++++--------- src/shared/components/post-form.tsx | 14 +- src/shared/components/post-listing.tsx | 67 +++-- src/shared/components/post.tsx | 24 +- .../components/private-message-form.tsx | 8 +- src/shared/components/private-message.tsx | 21 +- src/shared/components/search.tsx | 20 +- src/shared/components/sidebar.tsx | 25 +- src/shared/components/theme.tsx | 12 +- src/shared/initialize.ts | 2 +- src/shared/interfaces.ts | 6 +- src/shared/routes.ts | 18 +- src/shared/services/UserService.ts | 8 +- src/shared/services/WebSocketService.ts | 6 +- src/shared/utils.ts | 72 +++-- yarn.lock | 8 +- 36 files changed, 556 insertions(+), 481 deletions(-) rename src/shared/components/{user-details.tsx => person-details.tsx} (80%) rename src/shared/components/{user-listing.tsx => person-listing.tsx} (52%) rename src/shared/components/{user.tsx => person.tsx} (80%) diff --git a/package.json b/package.json index 96fd0c26..ef7b0883 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "eslint": "^7.20.0", "eslint-plugin-prettier": "^3.3.1", "husky": "^5.1.0", - "lemmy-js-client": "0.10.0-rc.1", + "lemmy-js-client": "0.10.0-rc.5", "lint-staged": "^10.5.4", "mini-css-extract-plugin": "^1.3.8", "node-fetch": "^2.6.1", diff --git a/src/server/index.tsx b/src/server/index.tsx index bb0ac3ad..748494cb 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -67,7 +67,7 @@ server.get("/*", async (req, res) => { ? req.headers["accept-language"].split(",")[0] : "en"; let lang = site.my_user - ? site.my_user.lang == "browser" + ? site.my_user.local_user.lang == "browser" ? acceptLang : "en" : acceptLang; diff --git a/src/shared/components/admin-settings.tsx b/src/shared/components/admin-settings.tsx index accefe13..0836a16d 100644 --- a/src/shared/components/admin-settings.tsx +++ b/src/shared/components/admin-settings.tsx @@ -23,7 +23,7 @@ import { } from "../utils"; import autosize from "autosize"; import { SiteForm } from "./site-form"; -import { UserListing } from "./user-listing"; +import { PersonListing } from "./person-listing"; import { HtmlTags } from "./html-tags"; import { Spinner } from "./icon"; import { i18n } from "../i18next"; @@ -135,7 +135,7 @@ export class AdminSettings extends Component {
      {this.state.siteRes.admins.map(admin => (
    • - +
    • ))}
    @@ -150,7 +150,7 @@ export class AdminSettings extends Component {
      {this.state.siteRes.banned.map(banned => (
    • - +
    • ))}
    diff --git a/src/shared/components/app.tsx b/src/shared/components/app.tsx index 6f49e2cd..262e4b54 100644 --- a/src/shared/components/app.tsx +++ b/src/shared/components/app.tsx @@ -26,7 +26,7 @@ export class App extends Component { <>
    - + {siteRes && siteRes.site_view && this.props.siteRes.site_view.site.icon && ( diff --git a/src/shared/components/comment-form.tsx b/src/shared/components/comment-form.tsx index 5c21b2dc..26775943 100644 --- a/src/shared/components/comment-form.tsx +++ b/src/shared/components/comment-form.tsx @@ -68,7 +68,7 @@ export class CommentForm extends Component { render() { return (
    - {UserService.Instance.user ? ( + {UserService.Instance.localUserView ? ( { let op = wsUserOp(msg); // Only do the showing and hiding if logged in - if (UserService.Instance.user) { + if (UserService.Instance.localUserView) { if ( op == UserOperation.CreateComment || op == UserOperation.EditComment diff --git a/src/shared/components/comment-node.tsx b/src/shared/components/comment-node.tsx index 6b5fc0e2..c6ba1a5d 100644 --- a/src/shared/components/comment-node.tsx +++ b/src/shared/components/comment-node.tsx @@ -5,18 +5,18 @@ import { DeleteComment, RemoveComment, MarkCommentAsRead, - MarkUserMentionAsRead, + MarkPersonMentionAsRead, SaveComment, BanFromCommunity, - BanUser, + BanPerson, CommunityModeratorView, - UserViewSafe, + PersonViewSafe, AddModToCommunity, AddAdmin, TransferCommunity, TransferSite, CommentView, - UserMentionView, + PersonMentionView, } from "lemmy-js-client"; import { CommentNode as CommentNodeI, BanType } from "../interfaces"; import { WebSocketService, UserService } from "../services"; @@ -34,7 +34,7 @@ import moment from "moment"; import { MomentTime } from "./moment-time"; import { CommentForm } from "./comment-form"; import { CommentNodes } from "./comment-nodes"; -import { UserListing } from "./user-listing"; +import { PersonListing } from "./person-listing"; import { CommunityLink } from "./community-link"; import { Icon, Spinner } from "./icon"; import { i18n } from "../i18next"; @@ -74,7 +74,7 @@ interface CommentNodeProps { markable?: boolean; showContext?: boolean; moderators: CommunityModeratorView[]; - admins: UserViewSafe[]; + admins: PersonViewSafe[]; // TODO is this necessary, can't I get it from the node itself? postCreatorId?: number; showCommunity?: boolean; @@ -156,7 +156,7 @@ export class CommentNode extends Component { >
    - + {this.isMod && ( @@ -270,7 +270,7 @@ export class CommentNode extends Component { )} )} - {UserService.Instance.user && !this.props.viewOnly && ( + {UserService.Instance.localUserView && !this.props.viewOnly && ( <>
    @@ -142,9 +142,9 @@ export class CreatePrivateMessage extends Component< this.state.loading = false; this.setState(this.state); return; - } else if (op == UserOperation.GetUserDetails) { - let data = wsJsonToRes(msg).data; - this.state.recipient = data.user_view; + } else if (op == UserOperation.GetPersonDetails) { + let data = wsJsonToRes(msg).data; + this.state.recipient = data.person_view; this.state.loading = false; this.setState(this.state); } diff --git a/src/shared/components/image-upload-form.tsx b/src/shared/components/image-upload-form.tsx index fb9c9ca1..b8b94c22 100644 --- a/src/shared/components/image-upload-form.tsx +++ b/src/shared/components/image-upload-form.tsx @@ -65,7 +65,7 @@ export class ImageUploadForm extends Component< accept="image/*,video/*" name={this.id} class="d-none" - disabled={!UserService.Instance.user} + disabled={!UserService.Instance.localUserView} onChange={linkEvent(this, this.handleImageUpload)} /> diff --git a/src/shared/components/inbox.tsx b/src/shared/components/inbox.tsx index 5c7f7989..677d9051 100644 --- a/src/shared/components/inbox.tsx +++ b/src/shared/components/inbox.tsx @@ -6,16 +6,16 @@ import { SortType, GetReplies, GetRepliesResponse, - GetUserMentions, - GetUserMentionsResponse, - UserMentionResponse, + GetPersonMentions, + GetPersonMentionsResponse, + PersonMentionResponse, CommentResponse, PrivateMessageView, GetPrivateMessages, PrivateMessagesResponse, PrivateMessageResponse, SiteView, - UserMentionView, + PersonMentionView, } from "lemmy-js-client"; import { WebSocketService, UserService } from "../services"; import { @@ -62,7 +62,7 @@ enum ReplyEnum { type ReplyType = { id: number; type_: ReplyEnum; - view: CommentView | PrivateMessageView | UserMentionView; + view: CommentView | PrivateMessageView | PersonMentionView; published: string; }; @@ -70,7 +70,7 @@ interface InboxState { unreadOrAll: UnreadOrAll; messageType: MessageType; replies: CommentView[]; - mentions: UserMentionView[]; + mentions: PersonMentionView[]; messages: PrivateMessageView[]; combined: ReplyType[]; sort: SortType; @@ -101,7 +101,7 @@ export class Inbox extends Component { this.state = this.emptyState; this.handleSortChange = this.handleSortChange.bind(this); - if (!UserService.Instance.user && isBrowser()) { + if (!UserService.Instance.localUserView && isBrowser()) { toast(i18n.t("not_logged_in"), "danger"); this.context.router.history.push(`/login`); } @@ -128,9 +128,9 @@ export class Inbox extends Component { } get documentTitle(): string { - return `@${UserService.Instance.user.name} ${i18n.t("inbox")} - ${ - this.state.site_view.site.name - }`; + return `@${UserService.Instance.localUserView.person.name} ${i18n.t( + "inbox" + )} - ${this.state.site_view.site.name}`; } render() { @@ -307,9 +307,9 @@ export class Inbox extends Component { }; } - mentionToReplyType(r: UserMentionView): ReplyType { + mentionToReplyType(r: PersonMentionView): ReplyType { return { - id: r.user_mention.id, + id: r.person_mention.id, type_: ReplyEnum.Mention, view: r, published: r.comment.published, @@ -359,7 +359,7 @@ export class Inbox extends Component { return ( {
    {this.state.mentions.map(umv => ( { }; promises.push(req.client.getReplies(repliesForm)); - let userMentionsForm: GetUserMentions = { + let personMentionsForm: GetPersonMentions = { sort: SortType.New, unread_only: true, page: 1, limit: fetchLimit, auth: req.auth, }; - promises.push(req.client.getUserMentions(userMentionsForm)); + promises.push(req.client.getPersonMentions(personMentionsForm)); let privateMessagesForm: GetPrivateMessages = { unread_only: true, @@ -521,14 +521,16 @@ export class Inbox extends Component { }; WebSocketService.Instance.send(wsClient.getReplies(repliesForm)); - let userMentionsForm: GetUserMentions = { + let personMentionsForm: GetPersonMentions = { sort: this.state.sort, unread_only: this.state.unreadOrAll == UnreadOrAll.Unread, page: this.state.page, limit: fetchLimit, auth: authField(), }; - WebSocketService.Instance.send(wsClient.getUserMentions(userMentionsForm)); + WebSocketService.Instance.send( + wsClient.getPersonMentions(personMentionsForm) + ); let privateMessagesForm: GetPrivateMessages = { unread_only: this.state.unreadOrAll == UnreadOrAll.Unread, @@ -579,8 +581,8 @@ export class Inbox extends Component { window.scrollTo(0, 0); this.setState(this.state); setupTippy(); - } else if (op == UserOperation.GetUserMentions) { - let data = wsJsonToRes(msg).data; + } else if (op == UserOperation.GetPersonMentions) { + let data = wsJsonToRes(msg).data; this.state.mentions = data.mentions; this.state.combined = this.buildCombined(); this.sendUnreadCount(); @@ -698,48 +700,49 @@ export class Inbox extends Component { this.sendUnreadCount(); this.setState(this.state); setupTippy(); - } else if (op == UserOperation.MarkUserMentionAsRead) { - let data = wsJsonToRes(msg).data; + } else if (op == UserOperation.MarkPersonMentionAsRead) { + let data = wsJsonToRes(msg).data; // TODO this might not be correct, it might need to use the comment id let found = this.state.mentions.find( - c => c.user_mention.id == data.user_mention_view.user_mention.id + c => c.person_mention.id == data.person_mention_view.person_mention.id ); if (found) { let combinedView = this.state.combined.find( - i => i.id == data.user_mention_view.user_mention.id - ).view as UserMentionView; + i => i.id == data.person_mention_view.person_mention.id + ).view as PersonMentionView; found.comment.content = combinedView.comment.content = - data.user_mention_view.comment.content; + data.person_mention_view.comment.content; found.comment.updated = combinedView.comment.updated = - data.user_mention_view.comment.updated; + data.person_mention_view.comment.updated; found.comment.removed = combinedView.comment.removed = - data.user_mention_view.comment.removed; + data.person_mention_view.comment.removed; found.comment.deleted = combinedView.comment.deleted = - data.user_mention_view.comment.deleted; + data.person_mention_view.comment.deleted; found.counts.upvotes = combinedView.counts.upvotes = - data.user_mention_view.counts.upvotes; + data.person_mention_view.counts.upvotes; found.counts.downvotes = combinedView.counts.downvotes = - data.user_mention_view.counts.downvotes; + data.person_mention_view.counts.downvotes; found.counts.score = combinedView.counts.score = - data.user_mention_view.counts.score; + data.person_mention_view.counts.score; // If youre in the unread view, just remove it from the list if ( this.state.unreadOrAll == UnreadOrAll.Unread && - data.user_mention_view.user_mention.read + data.person_mention_view.person_mention.read ) { this.state.mentions = this.state.mentions.filter( - r => r.user_mention.id !== data.user_mention_view.user_mention.id + r => + r.person_mention.id !== data.person_mention_view.person_mention.id ); this.state.combined = this.state.combined.filter( - r => r.id !== data.user_mention_view.user_mention.id + r => r.id !== data.person_mention_view.person_mention.id ); } else { // TODO test to make sure these mentions are getting marked as read - found.user_mention.read = combinedView.user_mention.read = - data.user_mention_view.user_mention.read; + found.person_mention.read = combinedView.person_mention.read = + data.person_mention_view.person_mention.read; } } this.sendUnreadCount(); @@ -747,18 +750,26 @@ export class Inbox extends Component { } else if (op == UserOperation.CreateComment) { let data = wsJsonToRes(msg).data; - if (data.recipient_ids.includes(UserService.Instance.user.id)) { + if ( + data.recipient_ids.includes( + UserService.Instance.localUserView.local_user.id + ) + ) { this.state.replies.unshift(data.comment_view); this.state.combined.unshift(this.replyToReplyType(data.comment_view)); this.setState(this.state); - } else if (data.comment_view.creator.id == UserService.Instance.user.id) { + } else if ( + data.comment_view.creator.id == + UserService.Instance.localUserView.person.id + ) { // TODO this seems wrong, you should be using form_id toast(i18n.t("reply_sent")); } } else if (op == UserOperation.CreatePrivateMessage) { let data = wsJsonToRes(msg).data; if ( - data.private_message_view.recipient.id == UserService.Instance.user.id + data.private_message_view.recipient.id == + UserService.Instance.localUserView.person.id ) { this.state.messages.unshift(data.private_message_view); this.state.combined.unshift( @@ -785,13 +796,13 @@ export class Inbox extends Component { unreadCount(): number { return ( this.state.replies.filter(r => !r.comment.read).length + - this.state.mentions.filter(r => !r.user_mention.read).length + + this.state.mentions.filter(r => !r.person_mention.read).length + this.state.messages.filter( r => - UserService.Instance.user && + UserService.Instance.localUserView && !r.private_message.read && - // TODO also seems very strang and wrong - r.creator.id !== UserService.Instance.user.id + // TODO also seems very strange and wrong + r.creator.id !== UserService.Instance.localUserView.person.id ).length ); } diff --git a/src/shared/components/listing-type-select.tsx b/src/shared/components/listing-type-select.tsx index c576e9b9..695211e4 100644 --- a/src/shared/components/listing-type-select.tsx +++ b/src/shared/components/listing-type-select.tsx @@ -42,7 +42,11 @@ export class ListingTypeSelect extends Component< diff --git a/src/shared/components/main.tsx b/src/shared/components/main.tsx index c6b20524..ba34ed47 100644 --- a/src/shared/components/main.tsx +++ b/src/shared/components/main.tsx @@ -21,7 +21,7 @@ import { GetCommentsResponse, CommentResponse, AddAdminResponse, - BanUserResponse, + BanPersonResponse, } from "lemmy-js-client"; import { DataType, InitialFetchRequest } from "../interfaces"; import { WebSocketService, UserService } from "../services"; @@ -31,7 +31,7 @@ import { SortSelect } from "./sort-select"; import { ListingTypeSelect } from "./listing-type-select"; import { DataTypeSelect } from "./data-type-select"; import { SiteForm } from "./site-form"; -import { UserListing } from "./user-listing"; +import { PersonListing } from "./person-listing"; import { CommunityLink } from "./community-link"; import { BannerIconHeader } from "./banner-icon-header"; import { Icon, Spinner } from "./icon"; @@ -130,14 +130,14 @@ export class Main extends Component { this.state.comments = this.isoData.routeData[0].comments; } this.state.trendingCommunities = this.isoData.routeData[1].communities; - if (UserService.Instance.user) { + if (UserService.Instance.localUserView) { this.state.subscribedCommunities = this.isoData.routeData[2].communities; } this.state.loading = false; } else { this.fetchTrendingCommunities(); this.fetchData(); - if (UserService.Instance.user) { + if (UserService.Instance.localUserView) { WebSocketService.Instance.send( wsClient.getFollowedCommunities({ auth: authField(), @@ -194,15 +194,17 @@ export class Main extends Component { // TODO figure out auth default_listingType, default_sort_type let type_: ListingType = pathSplit[5] ? ListingType[pathSplit[5]] - : UserService.Instance.user + : UserService.Instance.localUserView ? Object.values(ListingType)[ - UserService.Instance.user.default_listing_type + UserService.Instance.localUserView.local_user.default_listing_type ] : ListingType.Local; let sort: SortType = pathSplit[7] ? SortType[pathSplit[7]] - : UserService.Instance.user - ? Object.values(SortType)[UserService.Instance.user.default_sort_type] + : UserService.Instance.localUserView + ? Object.values(SortType)[ + UserService.Instance.localUserView.local_user.default_sort_type + ] : SortType.Active; let page = pathSplit[9] ? Number(pathSplit[9]) : 1; @@ -294,7 +296,7 @@ export class Main extends Component {
    - {UserService.Instance.user && + {UserService.Instance.localUserView && this.state.subscribedCommunities.length > 0 && (
    {this.subscribedCommunities()}
    @@ -413,7 +415,7 @@ export class Main extends Component {
  • {i18n.t("admins")}:
  • {this.state.siteRes.admins.map(av => (
  • - +
  • ))} @@ -609,7 +611,7 @@ export class Main extends Component { )} - {UserService.Instance.user && + {UserService.Instance.localUserView && this.state.listingType == ListingType.Subscribed && ( { get canAdmin(): boolean { return ( - UserService.Instance.user && + UserService.Instance.localUserView && this.state.siteRes.admins - .map(a => a.user.id) - .includes(UserService.Instance.user.id) + .map(a => a.person.id) + .includes(UserService.Instance.localUserView.person.id) ); } @@ -755,8 +757,8 @@ export class Main extends Component { let nsfwCheck = !nsfw || (nsfw && - UserService.Instance.user && - UserService.Instance.user.show_nsfw); + UserService.Instance.localUserView && + UserService.Instance.localUserView.local_user.show_nsfw); // Only push these if you're on the first page, and you pass the nsfw check if (this.state.page == 1 && nsfwCheck) { @@ -801,23 +803,23 @@ export class Main extends Component { let data = wsJsonToRes(msg).data; this.state.siteRes.admins = data.admins; this.setState(this.state); - } else if (op == UserOperation.BanUser) { - let data = wsJsonToRes(msg).data; + } else if (op == UserOperation.BanPerson) { + let data = wsJsonToRes(msg).data; let found = this.state.siteRes.banned.find( - u => (u.user.id = data.user_view.user.id) + p => (p.person.id = data.person_view.person.id) ); // Remove the banned if its found in the list, and the action is an unban if (found && !data.banned) { this.state.siteRes.banned = this.state.siteRes.banned.filter( - i => i.user.id !== data.user_view.user.id + i => i.person.id !== data.person_view.person.id ); } else { - this.state.siteRes.banned.push(data.user_view); + this.state.siteRes.banned.push(data.person_view); } this.state.posts - .filter(p => p.creator.id == data.user_view.user.id) + .filter(p => p.creator.id == data.person_view.person.id) .forEach(p => (p.creator.banned = data.banned)); this.setState(this.state); diff --git a/src/shared/components/markdown-textarea.tsx b/src/shared/components/markdown-textarea.tsx index 1aaf4db1..0acfc4c5 100644 --- a/src/shared/components/markdown-textarea.tsx +++ b/src/shared/components/markdown-textarea.tsx @@ -206,7 +206,9 @@ export class MarkdownTextArea extends Component<
    @@ -332,7 +332,7 @@ export class Modlog extends Component { return [ {ma.mod_add.removed ? "Removed " : "Appointed "} , - + , as an admin , ]; @@ -353,7 +353,7 @@ export class Modlog extends Component { - + {this.renderModlogType(i)} diff --git a/src/shared/components/navbar.tsx b/src/shared/components/navbar.tsx index 9577a631..cedccb43 100644 --- a/src/shared/components/navbar.tsx +++ b/src/shared/components/navbar.tsx @@ -6,8 +6,8 @@ import { UserOperation, GetReplies, GetRepliesResponse, - GetUserMentions, - GetUserMentionsResponse, + GetPersonMentions, + GetPersonMentionsResponse, GetPrivateMessages, PrivateMessagesResponse, SortType, @@ -174,7 +174,8 @@ export class Navbar extends Component { // TODO class active corresponding to current page navbar() { - let user = UserService.Instance.user || this.props.site_res.my_user; + let localUserView = + UserService.Instance.localUserView || this.props.site_res.my_user; return (