X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fmodlog.tsx;h=48be10b6245849c0b511bc9ba9137599eb364566;hb=9265fc58948341856513c06ba44e1a0c0d5a4241;hp=d917f5f35ed675842e43169fa6da129b696335b6;hpb=d75e0506daeb460fa4952211a46ded944d57aa88;p=lemmy-ui.git diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index d917f5f..48be10b 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -13,6 +13,7 @@ import { GetModlog, GetModlogResponse, GetPersonDetails, + GetPersonDetailsResponse, ModAddCommunityView, ModAddView, ModBanFromCommunityView, @@ -34,6 +35,7 @@ import { HttpService, RequestState } from "../services/HttpService"; import { Choice, QueryParams, + RouteDataResponse, amAdmin, amMod, debounce, @@ -74,6 +76,13 @@ type View = | AdminPurgePostView | AdminPurgeCommentView; +type ModlogData = RouteDataResponse<{ + modlogResponse: GetModlogResponse; + communityResponse?: GetCommunityResponse; + modUserResponse?: GetPersonDetailsResponse; + userResponse?: GetPersonDetailsResponse; +}>; + interface ModlogType { id: number; type_: ModlogActionType; @@ -631,7 +640,7 @@ export class Modlog extends Component< RouteComponentProps<{ communityId?: string }>, ModlogState > { - private isoData = setIsoData(this.context); + private isoData = setIsoData(this.context); state: ModlogState = { res: { state: "empty" }, @@ -653,25 +662,36 @@ export class Modlog extends Component< // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { - const [res, communityRes, filteredModRes, filteredUserRes] = - this.isoData.routeData; + const { + modlogResponse: res, + communityResponse: communityRes, + modUserResponse, + userResponse, + } = this.isoData.routeData; + this.state = { ...this.state, res, - communityRes, }; - if (filteredModRes.state === "success") { + if (communityRes?.state === "success") { this.state = { ...this.state, - modSearchOptions: [personToChoice(filteredModRes.data.person_view)], + communityRes, }; } - if (filteredUserRes.state === "success") { + if (modUserResponse?.state === "success") { this.state = { ...this.state, - userSearchOptions: [personToChoice(filteredUserRes.data.person_view)], + modSearchOptions: [personToChoice(modUserResponse.data.person_view)], + }; + } + + if (userResponse?.state === "success") { + this.state = { + ...this.state, + userSearchOptions: [personToChoice(userResponse.data.person_view)], }; } } @@ -958,17 +978,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 +1002,47 @@ export class Modlog extends Component< auth, }; - promises.push(client.getModlog(modlogForm)); + let communityResponse: RequestState | undefined = + undefined; 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 | undefined = + undefined; + 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 | undefined = + undefined; + 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 { + modlogResponse: await client.getModlog(modlogForm), + communityResponse, + modUserResponse, + userResponse, + }; } }