X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fmodlog.tsx;h=ca1cb3326b2cfef3a2ca454d00d071d454e72abc;hb=ed0fd264de3d2162a3837733632fee69696681aa;hp=d917f5f35ed675842e43169fa6da129b696335b6;hpb=31e61e7449a0aef46b7d9ccd0ecff3304e3614f5;p=lemmy-ui.git diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index d917f5f..ca1cb33 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -1,3 +1,21 @@ +import { + fetchUsers, + getUpdatedSearchId, + myAuth, + personToChoice, + setIsoData, +} from "@utils/app"; +import { + debounce, + formatPastDate, + getIdFromString, + getPageFromString, + getQueryParams, + getQueryString, +} from "@utils/helpers"; +import { amAdmin, amMod } from "@utils/roles"; +import type { QueryParams } from "@utils/types"; +import { Choice, RouteDataResponse } from "@utils/types"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -13,6 +31,7 @@ import { GetModlog, GetModlogResponse, GetPersonDetails, + GetPersonDetailsResponse, ModAddCommunityView, ModAddView, ModBanFromCommunityView, @@ -26,28 +45,10 @@ import { ModlogActionType, Person, } from "lemmy-js-client"; -import moment from "moment"; -import { i18n } from "../i18next"; +import { fetchLimit } from "../config"; import { InitialFetchRequest } from "../interfaces"; -import { FirstLoadService } from "../services/FirstLoadService"; +import { FirstLoadService, I18NextService } from "../services"; import { HttpService, RequestState } from "../services/HttpService"; -import { - Choice, - QueryParams, - amAdmin, - amMod, - debounce, - fetchLimit, - fetchUsers, - getIdFromString, - getPageFromString, - getQueryParams, - getQueryString, - getUpdatedSearchId, - myAuth, - personToChoice, - setIsoData, -} from "../utils"; import { HtmlTags } from "./common/html-tags"; import { Icon, Spinner } from "./common/icon"; import { MomentTime } from "./common/moment-time"; @@ -74,6 +75,13 @@ type View = | AdminPurgePostView | AdminPurgeCommentView; +type ModlogData = RouteDataResponse<{ + res: GetModlogResponse; + communityRes: GetCommunityResponse; + modUserResponse: GetPersonDetailsResponse; + userResponse: GetPersonDetailsResponse; +}>; + interface ModlogType { id: number; type_: ModlogActionType; @@ -304,6 +312,7 @@ function renderModlogType({ type_, view }: ModlogType) { const { mod_feature_post: { featured, is_featured_community }, post: { id, name }, + community, } = view as ModFeaturePostView; return ( @@ -312,7 +321,12 @@ function renderModlogType({ type_, view }: ModlogType) { Post {name} - {is_featured_community ? " In Community" : " In Local"} + + {is_featured_community + ? " in community " + : " in Local, from community "} + + > ); } @@ -363,7 +377,7 @@ function renderModlogType({ type_, view }: ModlogType) { )} {expires && ( - expires: {moment.utc(expires).fromNow()} + expires: {formatPastDate(expires)} )} > @@ -395,7 +409,7 @@ function renderModlogType({ type_, view }: ModlogType) { )} {expires && ( - expires: {moment.utc(expires).fromNow()} + expires: {formatPastDate(expires)} )} > @@ -459,7 +473,7 @@ function renderModlogType({ type_, view }: ModlogType) { )} {expires && ( - expires: {moment.utc(expires).fromNow()} + expires: {formatPastDate(expires)} )} > @@ -524,7 +538,7 @@ function renderModlogType({ type_, view }: ModlogType) { return ( <> - Purged a Post from from + Purged a Post from {reason && ( @@ -575,16 +589,16 @@ const Filter = ({ options: Choice[]; loading: boolean; }) => ( - - - {i18n.t(`filter_by_${filterType}` as NoOptionI18nKeys)} + + + {I18NextService.i18n.t(`filter_by_${filterType}` as NoOptionI18nKeys)} , ModlogState > { - private isoData = setIsoData(this.context); + private isoData = setIsoData(this.context); state: ModlogState = { res: { state: "empty" }, @@ -653,30 +667,35 @@ export class Modlog extends Component< // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { - const [res, communityRes, filteredModRes, filteredUserRes] = + const { res, communityRes, modUserResponse, userResponse } = this.isoData.routeData; + this.state = { ...this.state, res, communityRes, }; - if (filteredModRes.state === "success") { + if (modUserResponse.state === "success") { this.state = { ...this.state, - modSearchOptions: [personToChoice(filteredModRes.data.person_view)], + modSearchOptions: [personToChoice(modUserResponse.data.person_view)], }; } - if (filteredUserRes.state === "success") { + if (userResponse.state === "success") { this.state = { ...this.state, - userSearchOptions: [personToChoice(filteredUserRes.data.person_view)], + userSearchOptions: [personToChoice(userResponse.data.person_view)], }; } } } + async componentDidMount() { + await this.refetch(); + } + get combined() { const res = this.state.res; const combined = res.state == "success" ? buildCombined(res.data) : []; @@ -714,8 +733,8 @@ export class Modlog extends Component< this.isoData.site_res.admins.some( ({ person: { id } }) => id === person.id ) - ? i18n.t("admin") - : i18n.t("mod"); + ? I18NextService.i18n.t("admin") + : I18NextService.i18n.t("mod"); } get documentTitle(): string { @@ -732,48 +751,50 @@ export class Modlog extends Component< const { actionType, modId, userId } = getModlogQueryParams(); return ( - + - - - - - ### - - - {this.state.communityRes.state === "success" && ( - - - /c/{this.state.communityRes.data.community_view.community.name}{" "} - - {i18n.t("modlog")} - - )} - + {I18NextService.i18n.t("modlog")} + + + + + ### + + + {this.state.communityRes.state === "success" && ( + + + /c/{this.state.communityRes.data.community_view.community.name}{" "} + + {I18NextService.i18n.t("modlog")} + + )} + + - {i18n.t("filter_by_action")} + {I18NextService.i18n.t("filter_by_action")} - {i18n.t("all")} + {I18NextService.i18n.t("all")} Removing Posts Locking Posts Featuring Posts @@ -790,29 +811,29 @@ export class Modlog extends Component< Banning From Site - + + + + {!this.isoData.site_res.site_view.local_site + .hide_modlog_mod_names && ( - {!this.isoData.site_res.site_view.local_site - .hide_modlog_mod_names && ( - - )} - - {this.renderModlogTable()} + )} + {this.renderModlogTable()} ); } @@ -832,9 +853,9 @@ export class Modlog extends Component< - {i18n.t("time")} - {i18n.t("mod")} - {i18n.t("action")} + {I18NextService.i18n.t("time")} + {I18NextService.i18n.t("mod")} + {I18NextService.i18n.t("action")} {this.combined} @@ -958,17 +979,14 @@ export class Modlog extends Component< } } - static fetchInitialData({ + static async fetchInitialData({ client, path, query: { modId: urlModId, page, userId: urlUserId, actionType }, auth, site, - }: InitialFetchRequest>): Promise< - RequestState - >[] { + }: InitialFetchRequest>): Promise { const pathSplit = path.split("/"); - const promises: Promise>[] = []; const communityId = getIdFromString(pathSplit[2]); const modId = !site.site_view.local_site.hide_modlog_mod_names ? getIdFromString(urlModId) @@ -985,40 +1003,50 @@ export class Modlog extends Component< auth, }; - promises.push(client.getModlog(modlogForm)); + let communityResponse: RequestState = { + state: "empty", + }; if (communityId) { const communityForm: GetCommunity = { id: communityId, auth, }; - promises.push(client.getCommunity(communityForm)); - } else { - promises.push(Promise.resolve({ state: "empty" })); + + communityResponse = await client.getCommunity(communityForm); } + let modUserResponse: RequestState = { + state: "empty", + }; + if (modId) { const getPersonForm: GetPersonDetails = { person_id: modId, auth, }; - promises.push(client.getPersonDetails(getPersonForm)); - } else { - promises.push(Promise.resolve({ state: "empty" })); + modUserResponse = await client.getPersonDetails(getPersonForm); } + let userResponse: RequestState = { + state: "empty", + }; + if (userId) { const getPersonForm: GetPersonDetails = { person_id: userId, auth, }; - promises.push(client.getPersonDetails(getPersonForm)); - } else { - promises.push(Promise.resolve({ state: "empty" })); + userResponse = await client.getPersonDetails(getPersonForm); } - return promises; + return { + res: await client.getModlog(modlogForm), + communityRes: communityResponse, + modUserResponse, + userResponse, + }; } }