X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fmodlog.tsx;h=ca1cb3326b2cfef3a2ca454d00d071d454e72abc;hb=ed0fd264de3d2162a3837733632fee69696681aa;hp=8972f98546004f9f5d32d711219158d2564f2c69;hpb=3a88f6e85444ce4c9c38943645a0577d1cc93632;p=lemmy-ui.git diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index 8972f98..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"; @@ -8,7 +26,6 @@ import { AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView, - CommunityModeratorView, GetCommunity, GetCommunityResponse, GetModlog, @@ -21,42 +38,17 @@ import { ModBanView, ModFeaturePostView, ModLockPostView, - ModlogActionType, ModRemoveCommentView, ModRemoveCommunityView, ModRemovePostView, ModTransferCommunityView, - PersonSafe, - UserOperation, - wsJsonToRes, - wsUserOp, + ModlogActionType, + Person, } from "lemmy-js-client"; -import moment from "moment"; -import { Subscription } from "rxjs"; -import { i18n } from "../i18next"; +import { fetchLimit } from "../config"; import { InitialFetchRequest } from "../interfaces"; -import { WebSocketService } from "../services"; -import { - amAdmin, - amMod, - Choice, - debounce, - fetchLimit, - fetchUsers, - getIdFromString, - getPageFromString, - getQueryParams, - getQueryString, - getUpdatedSearchId, - isBrowser, - myAuth, - personToChoice, - QueryParams, - setIsoData, - toast, - wsClient, - wsSubscribe, -} from "../utils"; +import { FirstLoadService, I18NextService } from "../services"; +import { HttpService, RequestState } from "../services/HttpService"; import { HtmlTags } from "./common/html-tags"; import { Icon, Spinner } from "./common/icon"; import { MomentTime } from "./common/moment-time"; @@ -83,10 +75,17 @@ type View = | AdminPurgePostView | AdminPurgeCommentView; +type ModlogData = RouteDataResponse<{ + res: GetModlogResponse; + communityRes: GetCommunityResponse; + modUserResponse: GetPersonDetailsResponse; + userResponse: GetPersonDetailsResponse; +}>; + interface ModlogType { id: number; type_: ModlogActionType; - moderator?: PersonSafe; + moderator?: Person; view: View; when_: string; } @@ -100,10 +99,8 @@ const getModlogQueryParams = () => }); interface ModlogState { - res?: GetModlogResponse; - communityMods?: CommunityModeratorView[]; - communityName?: string; - loadingModlog: boolean; + res: RequestState; + communityRes: RequestState; loadingModSearch: boolean; loadingUserSearch: boolean; modSearchOptions: Choice[]; @@ -117,17 +114,16 @@ interface ModlogProps { actionType: ModlogActionType; } -const getActionFromString = (action?: string) => - action - ? ModlogActionType[action] ?? ModlogActionType.All - : ModlogActionType.All; +function getActionFromString(action?: string): ModlogActionType { + return action !== undefined ? (action as ModlogActionType) : "All"; +} const getModlogActionMapper = ( actionType: ModlogActionType, getAction: (view: View) => { id: number; when_: string } ) => - (view: View & { moderator?: PersonSafe; admin?: PersonSafe }): ModlogType => { + (view: View & { moderator?: Person; admin?: Person }): ModlogType => { const { id, when_ } = getAction(view); return { @@ -158,14 +154,14 @@ function buildCombined({ const combined = removed_posts .map( getModlogActionMapper( - ModlogActionType.ModRemovePost, + "ModRemovePost", ({ mod_remove_post }: ModRemovePostView) => mod_remove_post ) ) .concat( locked_posts.map( getModlogActionMapper( - ModlogActionType.ModLockPost, + "ModLockPost", ({ mod_lock_post }: ModLockPostView) => mod_lock_post ) ) @@ -173,7 +169,7 @@ function buildCombined({ .concat( featured_posts.map( getModlogActionMapper( - ModlogActionType.ModFeaturePost, + "ModFeaturePost", ({ mod_feature_post }: ModFeaturePostView) => mod_feature_post ) ) @@ -181,7 +177,7 @@ function buildCombined({ .concat( removed_comments.map( getModlogActionMapper( - ModlogActionType.ModRemoveComment, + "ModRemoveComment", ({ mod_remove_comment }: ModRemoveCommentView) => mod_remove_comment ) ) @@ -189,7 +185,7 @@ function buildCombined({ .concat( removed_communities.map( getModlogActionMapper( - ModlogActionType.ModRemoveCommunity, + "ModRemoveCommunity", ({ mod_remove_community }: ModRemoveCommunityView) => mod_remove_community ) @@ -198,7 +194,7 @@ function buildCombined({ .concat( banned_from_community.map( getModlogActionMapper( - ModlogActionType.ModBanFromCommunity, + "ModBanFromCommunity", ({ mod_ban_from_community }: ModBanFromCommunityView) => mod_ban_from_community ) @@ -207,7 +203,7 @@ function buildCombined({ .concat( added_to_community.map( getModlogActionMapper( - ModlogActionType.ModAddCommunity, + "ModAddCommunity", ({ mod_add_community }: ModAddCommunityView) => mod_add_community ) ) @@ -215,7 +211,7 @@ function buildCombined({ .concat( transferred_to_community.map( getModlogActionMapper( - ModlogActionType.ModTransferCommunity, + "ModTransferCommunity", ({ mod_transfer_community }: ModTransferCommunityView) => mod_transfer_community ) @@ -223,24 +219,18 @@ function buildCombined({ ) .concat( added.map( - getModlogActionMapper( - ModlogActionType.ModAdd, - ({ mod_add }: ModAddView) => mod_add - ) + getModlogActionMapper("ModAdd", ({ mod_add }: ModAddView) => mod_add) ) ) .concat( banned.map( - getModlogActionMapper( - ModlogActionType.ModBan, - ({ mod_ban }: ModBanView) => mod_ban - ) + getModlogActionMapper("ModBan", ({ mod_ban }: ModBanView) => mod_ban) ) ) .concat( admin_purged_persons.map( getModlogActionMapper( - ModlogActionType.AdminPurgePerson, + "AdminPurgePerson", ({ admin_purge_person }: AdminPurgePersonView) => admin_purge_person ) ) @@ -248,7 +238,7 @@ function buildCombined({ .concat( admin_purged_communities.map( getModlogActionMapper( - ModlogActionType.AdminPurgeCommunity, + "AdminPurgeCommunity", ({ admin_purge_community }: AdminPurgeCommunityView) => admin_purge_community ) @@ -257,7 +247,7 @@ function buildCombined({ .concat( admin_purged_posts.map( getModlogActionMapper( - ModlogActionType.AdminPurgePost, + "AdminPurgePost", ({ admin_purge_post }: AdminPurgePostView) => admin_purge_post ) ) @@ -265,7 +255,7 @@ function buildCombined({ .concat( admin_purged_comments.map( getModlogActionMapper( - ModlogActionType.AdminPurgeComment, + "AdminPurgeComment", ({ admin_purge_comment }: AdminPurgeCommentView) => admin_purge_comment ) @@ -280,7 +270,7 @@ function buildCombined({ function renderModlogType({ type_, view }: ModlogType) { switch (type_) { - case ModlogActionType.ModRemovePost: { + case "ModRemovePost": { const mrpv = view as ModRemovePostView; const { mod_remove_post: { reason, removed }, @@ -302,7 +292,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.ModLockPost: { + case "ModLockPost": { const { mod_lock_post: { locked }, post: { id, name }, @@ -318,10 +308,11 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.ModFeaturePost: { + case "ModFeaturePost": { const { mod_feature_post: { featured, is_featured_community }, post: { id, name }, + community, } = view as ModFeaturePostView; return ( @@ -330,11 +321,16 @@ function renderModlogType({ type_, view }: ModlogType) { Post {name} - {is_featured_community ? " In Community" : " In Local"} + + {is_featured_community + ? " in community " + : " in Local, from community "} + + ); } - case ModlogActionType.ModRemoveComment: { + case "ModRemoveComment": { const mrc = view as ModRemoveCommentView; const { mod_remove_comment: { reason, removed }, @@ -361,7 +357,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.ModRemoveCommunity: { + case "ModRemoveCommunity": { const mrco = view as ModRemoveCommunityView; const { mod_remove_community: { reason, expires, removed }, @@ -381,14 +377,14 @@ function renderModlogType({ type_, view }: ModlogType) { )} {expires && ( -
expires: {moment.utc(expires).fromNow()}
+
expires: {formatPastDate(expires)}
)} ); } - case ModlogActionType.ModBanFromCommunity: { + case "ModBanFromCommunity": { const mbfc = view as ModBanFromCommunityView; const { mod_ban_from_community: { reason, expires, banned }, @@ -413,14 +409,14 @@ function renderModlogType({ type_, view }: ModlogType) { )} {expires && ( -
expires: {moment.utc(expires).fromNow()}
+
expires: {formatPastDate(expires)}
)} ); } - case ModlogActionType.ModAddCommunity: { + case "ModAddCommunity": { const { mod_add_community: { removed }, modded_person, @@ -441,16 +437,12 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.ModTransferCommunity: { - const { - mod_transfer_community: { removed }, - community, - modded_person, - } = view as ModTransferCommunityView; + case "ModTransferCommunity": { + const { community, modded_person } = view as ModTransferCommunityView; return ( <> - {removed ? "Removed " : "Transferred "} + Transferred @@ -462,7 +454,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.ModBan: { + case "ModBan": { const { mod_ban: { reason, expires, banned }, banned_person, @@ -481,14 +473,14 @@ function renderModlogType({ type_, view }: ModlogType) { )} {expires && ( -
expires: {moment.utc(expires).fromNow()}
+
expires: {formatPastDate(expires)}
)} ); } - case ModlogActionType.ModAdd: { + case "ModAdd": { const { mod_add: { removed }, modded_person, @@ -504,7 +496,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.AdminPurgePerson: { + case "AdminPurgePerson": { const { admin_purge_person: { reason }, } = view as AdminPurgePersonView; @@ -521,7 +513,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.AdminPurgeCommunity: { + case "AdminPurgeCommunity": { const { admin_purge_community: { reason }, } = view as AdminPurgeCommunityView; @@ -538,7 +530,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.AdminPurgePost: { + case "AdminPurgePost": { const { admin_purge_post: { reason }, community, @@ -546,7 +538,7 @@ function renderModlogType({ type_, view }: ModlogType) { return ( <> - Purged a Post from from + Purged a Post from {reason && ( @@ -557,7 +549,7 @@ function renderModlogType({ type_, view }: ModlogType) { ); } - case ModlogActionType.AdminPurgeComment: { + case "AdminPurgeComment": { const { admin_purge_comment: { reason }, post: { id, name }, @@ -597,16 +589,16 @@ const Filter = ({ options: Choice[]; loading: boolean; }) => ( -
-