import { CommunityLink } from "./community-link";
type CommunityData = RouteDataResponse<{
- communityResponse: GetCommunityResponse;
- postsResponse?: GetPostsResponse;
- commentsResponse?: GetCommentsResponse;
+ communityRes: GetCommunityResponse;
+ postsRes: GetPostsResponse;
+ commentsRes: GetCommentsResponse;
}>;
interface State {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
- const {
- communityResponse: communityRes,
- commentsResponse: commentsRes,
- postsResponse: postsRes,
- } = this.isoData.routeData;
+ const { communityRes, commentsRes, postsRes } = this.isoData.routeData;
this.state = {
...this.state,
isIsomorphic: true,
+ commentsRes,
+ communityRes,
+ postsRes,
};
-
- if (communityRes.state === "success") {
- this.state = {
- ...this.state,
- communityRes,
- };
- }
-
- if (postsRes?.state === "success") {
- this.state = {
- ...this.state,
- postsRes,
- };
- }
-
- if (commentsRes?.state === "success") {
- this.state = {
- ...this.state,
- commentsRes,
- };
- }
}
}
const page = getPageFromString(urlPage);
- let postsResponse: RequestState<GetPostsResponse> | undefined = undefined;
- let commentsResponse: RequestState<GetCommentsResponse> | undefined =
- undefined;
+ let postsResponse: RequestState<GetPostsResponse> = { state: "empty" };
+ let commentsResponse: RequestState<GetCommentsResponse> = {
+ state: "empty",
+ };
if (dataType === DataType.Post) {
const getPostsForm: GetPosts = {
}
return {
- communityResponse: await client.getCommunity(communityForm),
- commentsResponse,
- postsResponse,
+ communityRes: await client.getCommunity(communityForm),
+ commentsRes: commentsResponse,
+ postsRes: postsResponse,
};
}
import { TaglineForm } from "./tagline-form";
type AdminSettingsData = RouteDataResponse<{
- bannedPersonsResponse: BannedPersonsResponse;
- federatedInstancesResponse: GetFederatedInstancesResponse;
+ bannedRes: BannedPersonsResponse;
+ instancesRes: GetFederatedInstancesResponse;
}>;
interface AdminSettingsState {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
- const {
- bannedPersonsResponse: bannedRes,
- federatedInstancesResponse: instancesRes,
- } = this.isoData.routeData;
+ const { bannedRes, instancesRes } = this.isoData.routeData;
this.state = {
...this.state,
client,
}: InitialFetchRequest): Promise<AdminSettingsData> {
return {
- bannedPersonsResponse: await client.getBannedPersons({
+ bannedRes: await client.getBannedPersons({
auth: auth as string,
}),
- federatedInstancesResponse: await client.getFederatedInstances({
+ instancesRes: await client.getFederatedInstances({
auth: auth as string,
}),
};
}
type HomeData = RouteDataResponse<{
- postsResponse?: GetPostsResponse;
- commentsResponse?: GetCommentsResponse;
- trendingResponse: ListCommunitiesResponse;
+ postsRes: GetPostsResponse;
+ commentsRes: GetCommentsResponse;
+ trendingCommunitiesRes: ListCommunitiesResponse;
}>;
function getDataTypeFromQuery(type?: string): DataType {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
const {
- trendingResponse: trendingCommunitiesRes,
- commentsResponse: commentsRes,
- postsResponse: postsRes,
+ trendingCommunitiesRes: trendingCommunitiesRes,
+ commentsRes: commentsRes,
+ postsRes: postsRes,
} = this.isoData.routeData;
this.state = {
...this.state,
trendingCommunitiesRes,
+ commentsRes,
+ postsRes,
tagline: getRandomFromList(this.state?.siteRes?.taglines ?? [])
?.content,
isIsomorphic: true,
};
-
- if (commentsRes?.state === "success") {
- this.state = {
- ...this.state,
- commentsRes,
- };
- }
-
- if (postsRes?.state === "success") {
- this.state = {
- ...this.state,
- postsRes,
- };
- }
}
}
async componentDidMount() {
- if (!this.state.isIsomorphic || !this.isoData.routeData.length) {
+ if (
+ !this.state.isIsomorphic ||
+ !Object.values(this.isoData.routeData).some(
+ res => res.state === "success" || res.state === "failed"
+ )
+ ) {
await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
}
const page = urlPage ? Number(urlPage) : 1;
- let postsResponse: RequestState<GetPostsResponse> | undefined = undefined;
- let commentsResponse: RequestState<GetCommentsResponse> | undefined =
- undefined;
+ let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
+ let commentsRes: RequestState<GetCommentsResponse> = {
+ state: "empty",
+ };
if (dataType === DataType.Post) {
const getPostsForm: GetPosts = {
auth,
};
- postsResponse = await client.getPosts(getPostsForm);
+ postsRes = await client.getPosts(getPostsForm);
} else {
const getCommentsForm: GetComments = {
page,
auth,
};
- commentsResponse = await client.getComments(getCommentsForm);
+ commentsRes = await client.getComments(getCommentsForm);
}
const trendingCommunitiesForm: ListCommunities = {
};
return {
- trendingResponse: await client.listCommunities(trendingCommunitiesForm),
- commentsResponse,
- postsResponse,
+ trendingCommunitiesRes: await client.listCommunities(
+ trendingCommunitiesForm
+ ),
+ commentsRes,
+ postsRes,
};
}
});
}
- static async fetchInitialData(
- req: InitialFetchRequest
- ): Promise<InstancesData> {
+ static async fetchInitialData({
+ client,
+ }: InitialFetchRequest): Promise<InstancesData> {
return {
- federatedInstancesResponse: await req.client.getFederatedInstances({}),
+ federatedInstancesResponse: await client.getFederatedInstances({}),
};
}
| AdminPurgeCommentView;
type ModlogData = RouteDataResponse<{
- modlogResponse: GetModlogResponse;
- communityResponse?: GetCommunityResponse;
- modUserResponse?: GetPersonDetailsResponse;
- userResponse?: GetPersonDetailsResponse;
+ res: GetModlogResponse;
+ communityRes: GetCommunityResponse;
+ modUserResponse: GetPersonDetailsResponse;
+ userResponse: GetPersonDetailsResponse;
}>;
interface ModlogType {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
- const {
- modlogResponse: res,
- communityResponse: communityRes,
- modUserResponse,
- userResponse,
- } = this.isoData.routeData;
+ const { res, communityRes, modUserResponse, userResponse } =
+ this.isoData.routeData;
this.state = {
...this.state,
res,
+ communityRes,
};
- if (communityRes?.state === "success") {
- this.state = {
- ...this.state,
- communityRes,
- };
- }
-
- if (modUserResponse?.state === "success") {
+ if (modUserResponse.state === "success") {
this.state = {
...this.state,
modSearchOptions: [personToChoice(modUserResponse.data.person_view)],
};
}
- if (userResponse?.state === "success") {
+ if (userResponse.state === "success") {
this.state = {
...this.state,
userSearchOptions: [personToChoice(userResponse.data.person_view)],
auth,
};
- let communityResponse: RequestState<GetCommunityResponse> | undefined =
- undefined;
+ let communityResponse: RequestState<GetCommunityResponse> = {
+ state: "empty",
+ };
if (communityId) {
const communityForm: GetCommunity = {
communityResponse = await client.getCommunity(communityForm);
}
- let modUserResponse: RequestState<GetPersonDetailsResponse> | undefined =
- undefined;
+ let modUserResponse: RequestState<GetPersonDetailsResponse> = {
+ state: "empty",
+ };
if (modId) {
const getPersonForm: GetPersonDetails = {
modUserResponse = await client.getPersonDetails(getPersonForm);
}
- let userResponse: RequestState<GetPersonDetailsResponse> | undefined =
- undefined;
+ let userResponse: RequestState<GetPersonDetailsResponse> = {
+ state: "empty",
+ };
if (userId) {
const getPersonForm: GetPersonDetails = {
}
return {
- modlogResponse: await client.getModlog(modlogForm),
- communityResponse,
+ res: await client.getModlog(modlogForm),
+ communityRes: communityResponse,
modUserResponse,
userResponse,
};
}
type InboxData = RouteDataResponse<{
- repliesResponse: GetRepliesResponse;
- personMentionsResponse: GetPersonMentionsResponse;
- privateMessagesResponse: PrivateMessagesResponse;
+ repliesRes: GetRepliesResponse;
+ mentionsRes: GetPersonMentionsResponse;
+ messagesRes: PrivateMessagesResponse;
}>;
type ReplyType = {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
- const {
- personMentionsResponse: mentionsRes,
- privateMessagesResponse: messagesRes,
- repliesResponse: repliesRes,
- } = this.isoData.routeData;
+ const { mentionsRes, messagesRes, repliesRes } = this.isoData.routeData;
this.state = {
...this.state,
const sort: CommentSortType = "New";
return {
- personMentionsResponse: auth
+ mentionsRes: auth
? await client.getPersonMentions({
sort,
unread_only: true,
auth,
})
: { state: "empty" },
- privateMessagesResponse: auth
+ messagesRes: auth
? await client.getPrivateMessages({
unread_only: true,
page: 1,
auth,
})
: { state: "empty" },
- repliesResponse: auth
+ repliesRes: auth
? await client.getReplies({
sort,
unread_only: true,
}
type ReportsData = RouteDataResponse<{
- commentReportsResponse: ListCommentReportsResponse;
- postReportsResponse: ListPostReportsResponse;
- privateMessageReportsResponse?: ListPrivateMessageReportsResponse;
+ commentReportsRes: ListCommentReportsResponse;
+ postReportsRes: ListPostReportsResponse;
+ messageReportsRes: ListPrivateMessageReportsResponse;
}>;
type ItemType = {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
- const {
- commentReportsResponse: commentReportsRes,
- postReportsResponse: postReportsRes,
- privateMessageReportsResponse: messageReportsRes,
- } = this.isoData.routeData;
+ const { commentReportsRes, postReportsRes, messageReportsRes } =
+ this.isoData.routeData;
this.state = {
...this.state,
if (amAdmin()) {
this.state = {
...this.state,
- messageReportsRes: messageReportsRes ?? { state: "empty" },
+ messageReportsRes: messageReportsRes,
};
}
}
};
const data: ReportsData = {
- commentReportsResponse: await client.listCommentReports(
- commentReportsForm
- ),
- postReportsResponse: await client.listPostReports(postReportsForm),
+ commentReportsRes: await client.listCommentReports(commentReportsForm),
+ postReportsRes: await client.listPostReports(postReportsForm),
+ messageReportsRes: { state: "empty" },
};
if (amAdmin()) {
auth: auth as string,
};
- data.privateMessageReportsResponse =
- await client.listPrivateMessageReports(privateMessageReportsForm);
+ data.messageReportsRes = await client.listPrivateMessageReports(
+ privateMessageReportsForm
+ );
}
return data;
const { communityResponse: communityRes, initialCommunitiesRes } =
this.isoData.routeData;
+ this.state = {
+ ...this.state,
+ loading: false,
+ initialCommunitiesRes,
+ isIsomorphic: true,
+ };
+
if (communityRes?.state === "success") {
const communityChoice: Choice = {
label: communityRes.data.community_view.community.title,
selectedCommunityChoice: communityChoice,
};
}
-
- this.state = {
- ...this.state,
- loading: false,
- initialCommunitiesRes,
- isIsomorphic: true,
- };
}
}
}
type SearchData = RouteDataResponse<{
- communityResponse?: GetCommunityResponse;
- listCommunitiesResponse?: ListCommunitiesResponse;
- creatorDetailsResponse?: GetPersonDetailsResponse;
- searchResponse?: SearchResponse;
- resolveObjectResponse?: ResolveObjectResponse;
+ communityResponse: GetCommunityResponse;
+ listCommunitiesResponse: ListCommunitiesResponse;
+ creatorDetailsResponse: GetPersonDetailsResponse;
+ searchResponse: SearchResponse;
+ resolveObjectResponse: ResolveObjectResponse;
}>;
type FilterType = "creator" | "community";
query: { communityId, creatorId, q, type, sort, listingType, page },
}: InitialFetchRequest<QueryParams<SearchProps>>): Promise<SearchData> {
const community_id = getIdFromString(communityId);
- let communityResponse: RequestState<GetCommunityResponse> | undefined =
- undefined;
- let listCommunitiesResponse:
- | RequestState<ListCommunitiesResponse>
- | undefined = undefined;
+ let communityResponse: RequestState<GetCommunityResponse> = {
+ state: "empty",
+ };
+ let listCommunitiesResponse: RequestState<ListCommunitiesResponse> = {
+ state: "empty",
+ };
if (community_id) {
const getCommunityForm: GetCommunity = {
id: community_id,
}
const creator_id = getIdFromString(creatorId);
- let creatorDetailsResponse:
- | RequestState<GetPersonDetailsResponse>
- | undefined = undefined;
+ let creatorDetailsResponse: RequestState<GetPersonDetailsResponse> = {
+ state: "empty",
+ };
if (creator_id) {
const getCreatorForm: GetPersonDetails = {
person_id: creator_id,
const query = getSearchQueryFromQuery(q);
- let searchResponse: RequestState<SearchResponse> | undefined = undefined;
- let resolveObjectResponse: RequestState<ResolveObjectResponse> | undefined =
- undefined;
+ let searchResponse: RequestState<SearchResponse> = { state: "empty" };
+ let resolveObjectResponse: RequestState<ResolveObjectResponse> = {
+ state: "empty",
+ };
if (query) {
const form: SearchForm = {
q: query,
auth,
};
- resolveObjectResponse = await client
- .resolveObject(resolveObjectForm)
- .catch(() => undefined);
+ resolveObjectResponse = await client.resolveObject(resolveObjectForm);
}
}
}
}
export type RouteDataResponse<T extends Record<string, any>> = {
- [K in keyof T]: RequestState<Exclude<T[K], undefined>>;
+ [K in keyof T]: RequestState<T[K]>;
};
function sleep(millis: number): Promise<void> {