diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx
index ff740b59..1b4e0471 100644
--- a/src/shared/components/comment/comment-report.tsx
+++ b/src/shared/components/comment/comment-report.tsx
@@ -10,6 +10,7 @@ import { I18NextService } from "../../services";
import { Icon, Spinner } from "../common/icon";
import { PersonListing } from "../person/person-listing";
import { CommentNode } from "./comment-node";
+import { EMPTY_REQUEST } from "shared/services/HttpService";
interface CommentReportProps {
report: CommentReportView;
@@ -97,8 +98,8 @@ export class CommentReport extends Component<
onPersonMentionRead={() => {}}
onBanPersonFromCommunity={() => {}}
onBanPerson={() => {}}
- onCreateComment={() => Promise.resolve({ state: "empty" })}
- onEditComment={() => Promise.resolve({ state: "empty" })}
+ onCreateComment={() => Promise.resolve(EMPTY_REQUEST)}
+ onEditComment={() => Promise.resolve(EMPTY_REQUEST)}
/>
{I18NextService.i18n.t("reporter")}:{" "}
diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx
index b36e1c8a..ca015e2d 100644
--- a/src/shared/components/community/communities.tsx
+++ b/src/shared/components/community/communities.tsx
@@ -18,7 +18,12 @@ import {
} from "lemmy-js-client";
import { InitialFetchRequest } from "../../interfaces";
import { FirstLoadService, I18NextService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
import { ListingTypeSelect } from "../common/listing-type-select";
@@ -64,7 +69,7 @@ function getCommunitiesQueryParams() {
export class Communities extends Component
{
private isoData = setIsoData(this.context);
state: CommunitiesState = {
- listCommunitiesResponse: { state: "empty" },
+ listCommunitiesResponse: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
searchText: "",
isIsomorphic: false,
@@ -333,7 +338,7 @@ export class Communities extends Component {
}
async refetch() {
- this.setState({ listCommunitiesResponse: { state: "loading" } });
+ this.setState({ listCommunitiesResponse: LOADING_REQUEST });
const { listingType, sort, page } = getCommunitiesQueryParams();
diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx
index 6b70b550..59d32e8d 100644
--- a/src/shared/components/community/community.tsx
+++ b/src/shared/components/community/community.tsx
@@ -83,7 +83,12 @@ import {
InitialFetchRequest,
} from "../../interfaces";
import { FirstLoadService, I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { setupTippy } from "../../tippy";
import { toast } from "../../toast";
import { CommentNodes } from "../comment/comment-nodes";
@@ -146,9 +151,9 @@ export class Community extends Component<
> {
private isoData = setIsoData(this.context);
state: State = {
- communityRes: { state: "empty" },
- postsRes: { state: "empty" },
- commentsRes: { state: "empty" },
+ communityRes: EMPTY_REQUEST,
+ postsRes: EMPTY_REQUEST,
+ commentsRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
showSidebarMobile: false,
finished: new Map(),
@@ -212,7 +217,7 @@ export class Community extends Component<
}
async fetchCommunity() {
- this.setState({ communityRes: { state: "loading" } });
+ this.setState({ communityRes: LOADING_REQUEST });
this.setState({
communityRes: await HttpService.client.getCommunity({
name: this.props.match.params.name,
@@ -248,10 +253,8 @@ export class Community extends Component<
const page = getPageFromString(urlPage);
- let postsResponse: RequestState = { state: "empty" };
- let commentsResponse: RequestState = {
- state: "empty",
- };
+ let postsResponse: RequestState = EMPTY_REQUEST;
+ let commentsResponse: RequestState = EMPTY_REQUEST;
if (dataType === DataType.Post) {
const getPostsForm: GetPosts = {
@@ -585,7 +588,7 @@ export class Community extends Component<
const { name } = this.props.match.params;
if (dataType === DataType.Post) {
- this.setState({ postsRes: { state: "loading" } });
+ this.setState({ postsRes: LOADING_REQUEST });
this.setState({
postsRes: await HttpService.client.getPosts({
page,
@@ -597,7 +600,7 @@ export class Community extends Component<
}),
});
} else {
- this.setState({ commentsRes: { state: "loading" } });
+ this.setState({ commentsRes: LOADING_REQUEST });
this.setState({
commentsRes: await HttpService.client.getComments({
page,
diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx
index c86fd01f..a799b455 100644
--- a/src/shared/components/home/admin-settings.tsx
+++ b/src/shared/components/home/admin-settings.tsx
@@ -16,7 +16,12 @@ import {
import { InitialFetchRequest } from "../../interfaces";
import { removeFromEmojiDataModel, updateEmojiDataModel } from "../../markdown";
import { FirstLoadService, I18NextService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { toast } from "../../toast";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
@@ -50,9 +55,9 @@ export class AdminSettings extends Component {
siteRes: this.isoData.site_res,
banned: [],
currentTab: "site",
- bannedRes: { state: "empty" },
- instancesRes: { state: "empty" },
- leaveAdminTeamRes: { state: "empty" },
+ bannedRes: EMPTY_REQUEST,
+ instancesRes: EMPTY_REQUEST,
+ leaveAdminTeamRes: EMPTY_REQUEST,
loading: false,
themeList: [],
isIsomorphic: false,
@@ -231,8 +236,8 @@ export class AdminSettings extends Component {
async fetchData() {
this.setState({
- bannedRes: { state: "loading" },
- instancesRes: { state: "loading" },
+ bannedRes: LOADING_REQUEST,
+ instancesRes: LOADING_REQUEST,
themeList: [],
});
@@ -333,7 +338,7 @@ export class AdminSettings extends Component {
}
async handleLeaveAdminTeam(i: AdminSettings) {
- i.setState({ leaveAdminTeamRes: { state: "loading" } });
+ i.setState({ leaveAdminTeamRes: LOADING_REQUEST });
this.setState({
leaveAdminTeamRes: await HttpService.client.leaveAdmin(),
});
diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx
index 97dd89ca..fc141d99 100644
--- a/src/shared/components/home/home.tsx
+++ b/src/shared/components/home/home.tsx
@@ -85,7 +85,12 @@ import {
I18NextService,
UserService,
} from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { setupTippy } from "../../tippy";
import { toast } from "../../toast";
import { CommentNodes } from "../comment/comment-nodes";
@@ -221,9 +226,9 @@ const LinkButton = ({
export class Home extends Component {
private isoData = setIsoData(this.context);
state: HomeState = {
- postsRes: { state: "empty" },
- commentsRes: { state: "empty" },
- trendingCommunitiesRes: { state: "empty" },
+ postsRes: EMPTY_REQUEST,
+ commentsRes: EMPTY_REQUEST,
+ trendingCommunitiesRes: EMPTY_REQUEST,
scrolled: true,
siteRes: this.isoData.site_res,
showSubscribedMobile: false,
@@ -321,10 +326,8 @@ export class Home extends Component {
const page = urlPage ? Number(urlPage) : 1;
- let postsRes: RequestState = { state: "empty" };
- let commentsRes: RequestState = {
- state: "empty",
- };
+ let postsRes: RequestState = EMPTY_REQUEST;
+ let commentsRes: RequestState = EMPTY_REQUEST;
if (dataType === DataType.Post) {
const getPostsForm: GetPosts = {
@@ -790,7 +793,7 @@ export class Home extends Component {
}
async fetchTrendingCommunities() {
- this.setState({ trendingCommunitiesRes: { state: "loading" } });
+ this.setState({ trendingCommunitiesRes: LOADING_REQUEST });
this.setState({
trendingCommunitiesRes: await HttpService.client.listCommunities({
type_: "Local",
@@ -814,7 +817,7 @@ export class Home extends Component {
behavior: "instant",
});
} else {
- this.setState({ postsRes: { state: "loading" } });
+ this.setState({ postsRes: LOADING_REQUEST });
this.setState({
postsRes: await HttpService.client.getPosts({
page,
@@ -828,7 +831,7 @@ export class Home extends Component {
HomeCacheService.postsRes = this.state.postsRes;
}
} else {
- this.setState({ commentsRes: { state: "loading" } });
+ this.setState({ commentsRes: LOADING_REQUEST });
this.setState({
commentsRes: await HttpService.client.getComments({
page,
diff --git a/src/shared/components/home/instances.tsx b/src/shared/components/home/instances.tsx
index 4edc6056..40ab420a 100644
--- a/src/shared/components/home/instances.tsx
+++ b/src/shared/components/home/instances.tsx
@@ -10,7 +10,12 @@ import classNames from "classnames";
import { relTags } from "../../config";
import { InitialFetchRequest } from "../../interfaces";
import { FirstLoadService, I18NextService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
import Tabs from "../common/tabs";
@@ -28,7 +33,7 @@ interface InstancesState {
export class Instances extends Component {
private isoData = setIsoData(this.context);
state: InstancesState = {
- instancesRes: { state: "empty" },
+ instancesRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
isIsomorphic: false,
};
@@ -54,7 +59,7 @@ export class Instances extends Component {
async fetchInstances() {
this.setState({
- instancesRes: { state: "loading" },
+ instancesRes: LOADING_REQUEST,
});
this.setState({
diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx
index 95730b6b..57b1a9d8 100644
--- a/src/shared/components/home/login.tsx
+++ b/src/shared/components/home/login.tsx
@@ -5,7 +5,12 @@ import { Component, linkEvent } from "inferno";
import { RouteComponentProps } from "inferno-router/dist/Route";
import { GetSiteResponse, LoginResponse } from "lemmy-js-client";
import { I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { toast } from "../../toast";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
@@ -57,7 +62,7 @@ async function handleLoginSubmit(i: Login, event: any) {
const { password, username_or_email } = i.state.form;
if (username_or_email && password) {
- i.setState({ loginRes: { state: "loading" } });
+ i.setState({ loginRes: LOADING_REQUEST });
const loginRes = await HttpService.client.login({
username_or_email,
@@ -104,7 +109,7 @@ export class Login extends Component<
private isoData = setIsoData(this.context);
state: State = {
- loginRes: { state: "empty" },
+ loginRes: EMPTY_REQUEST,
form: {
username_or_email: "",
password: "",
diff --git a/src/shared/components/home/setup.tsx b/src/shared/components/home/setup.tsx
index 0a3d09fe..5dbad944 100644
--- a/src/shared/components/home/setup.tsx
+++ b/src/shared/components/home/setup.tsx
@@ -8,7 +8,12 @@ import {
Register,
} from "lemmy-js-client";
import { I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { Spinner } from "../common/icon";
import PasswordInput from "../common/password-input";
import { SiteForm } from "./site-form";
@@ -35,7 +40,7 @@ export class Setup extends Component {
private isoData = setIsoData(this.context);
state: State = {
- registerRes: { state: "empty" },
+ registerRes: EMPTY_REQUEST,
themeList: [],
form: {
show_nsfw: true,
@@ -157,7 +162,7 @@ export class Setup extends Component {
async handleRegisterSubmit(i: Setup, event: any) {
event.preventDefault();
- i.setState({ registerRes: { state: "loading" } });
+ i.setState({ registerRes: LOADING_REQUEST });
const {
username,
password_verify,
diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx
index c7256aa9..10c64d0d 100644
--- a/src/shared/components/home/signup.tsx
+++ b/src/shared/components/home/signup.tsx
@@ -13,7 +13,12 @@ import {
import { joinLemmyUrl } from "../../config";
import { mdToHtml } from "../../markdown";
import { I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { toast } from "../../toast";
import { HtmlTags } from "../common/html-tags";
import { Icon, Spinner } from "../common/icon";
@@ -43,8 +48,8 @@ export class Signup extends Component {
private audio?: HTMLAudioElement;
state: State = {
- registerRes: { state: "empty" },
- captchaRes: { state: "empty" },
+ registerRes: EMPTY_REQUEST,
+ captchaRes: EMPTY_REQUEST,
form: {
show_nsfw: false,
},
@@ -65,7 +70,7 @@ export class Signup extends Component {
}
async fetchCaptcha() {
- this.setState({ captchaRes: { state: "loading" } });
+ this.setState({ captchaRes: LOADING_REQUEST });
this.setState({
captchaRes: await HttpService.client.getCaptcha(),
});
@@ -368,7 +373,7 @@ export class Signup extends Component {
username,
} = i.state.form;
if (username && password && password_verify) {
- i.setState({ registerRes: { state: "loading" } });
+ i.setState({ registerRes: LOADING_REQUEST });
const registerRes = await HttpService.client.register({
username,
@@ -384,7 +389,7 @@ export class Signup extends Component {
switch (registerRes.state) {
case "failed": {
toast(registerRes.msg, "danger");
- i.setState({ registerRes: { state: "empty" } });
+ i.setState({ registerRes: EMPTY_REQUEST });
break;
}
diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx
index 87e378ef..0b246a6e 100644
--- a/src/shared/components/modlog.tsx
+++ b/src/shared/components/modlog.tsx
@@ -47,7 +47,12 @@ import {
import { fetchLimit } from "../config";
import { InitialFetchRequest } from "../interfaces";
import { FirstLoadService, I18NextService } from "../services";
-import { HttpService, RequestState } from "../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../services/HttpService";
import { HtmlTags } from "./common/html-tags";
import { Icon, Spinner } from "./common/icon";
import { MomentTime } from "./common/moment-time";
@@ -647,8 +652,8 @@ export class Modlog extends Component<
private isoData = setIsoData(this.context);
state: ModlogState = {
- res: { state: "empty" },
- communityRes: { state: "empty" },
+ res: EMPTY_REQUEST,
+ communityRes: EMPTY_REQUEST,
loadingModSearch: false,
loadingUserSearch: false,
userSearchOptions: [],
@@ -954,7 +959,7 @@ export class Modlog extends Component<
const { communityId: urlCommunityId } = this.props.match.params;
const communityId = getIdFromString(urlCommunityId);
- this.setState({ res: { state: "loading" } });
+ this.setState({ res: LOADING_REQUEST });
this.setState({
res: await HttpService.client.getModlog({
community_id: communityId,
@@ -970,7 +975,7 @@ export class Modlog extends Component<
});
if (communityId) {
- this.setState({ communityRes: { state: "loading" } });
+ this.setState({ communityRes: LOADING_REQUEST });
this.setState({
communityRes: await HttpService.client.getCommunity({
id: communityId,
@@ -1001,9 +1006,7 @@ export class Modlog extends Component<
other_person_id: userId,
};
- let communityResponse: RequestState = {
- state: "empty",
- };
+ let communityResponse: RequestState = EMPTY_REQUEST;
if (communityId) {
const communityForm: GetCommunity = {
@@ -1013,9 +1016,7 @@ export class Modlog extends Component<
communityResponse = await client.getCommunity(communityForm);
}
- let modUserResponse: RequestState = {
- state: "empty",
- };
+ let modUserResponse: RequestState = EMPTY_REQUEST;
if (modId) {
const getPersonForm: GetPersonDetails = {
@@ -1025,9 +1026,7 @@ export class Modlog extends Component<
modUserResponse = await client.getPersonDetails(getPersonForm);
}
- let userResponse: RequestState = {
- state: "empty",
- };
+ let userResponse: RequestState = EMPTY_REQUEST;
if (userId) {
const getPersonForm: GetPersonDetails = {
diff --git a/src/shared/components/person/inbox.tsx b/src/shared/components/person/inbox.tsx
index 307de310..247850c7 100644
--- a/src/shared/components/person/inbox.tsx
+++ b/src/shared/components/person/inbox.tsx
@@ -64,8 +64,10 @@ import { CommentViewType, InitialFetchRequest } from "../../interfaces";
import { FirstLoadService, I18NextService, UserService } from "../../services";
import { UnreadCounterService } from "../../services";
import {
+ EMPTY_REQUEST,
EmptyRequestState,
HttpService,
+ LOADING_REQUEST,
RequestState,
} from "../../services/HttpService";
import { toast } from "../../toast";
@@ -129,10 +131,10 @@ export class Inbox extends Component {
sort: "New",
page: 1,
siteRes: this.isoData.site_res,
- repliesRes: { state: "empty" },
- mentionsRes: { state: "empty" },
- messagesRes: { state: "empty" },
- markAllAsReadRes: { state: "empty" },
+ repliesRes: EMPTY_REQUEST,
+ mentionsRes: EMPTY_REQUEST,
+ messagesRes: EMPTY_REQUEST,
+ markAllAsReadRes: EMPTY_REQUEST,
finished: new Map(),
isIsomorphic: false,
};
@@ -725,7 +727,7 @@ export class Inbox extends Component {
client,
}: InitialFetchRequest): Promise {
const sort: CommentSortType = "New";
- const empty: EmptyRequestState = { state: "empty" };
+ const empty: EmptyRequestState = EMPTY_REQUEST;
let inboxData: InboxData = {
mentionsRes: empty,
messagesRes: empty,
@@ -765,7 +767,7 @@ export class Inbox extends Component {
const page = this.state.page;
const limit = fetchLimit;
- this.setState({ repliesRes: { state: "loading" } });
+ this.setState({ repliesRes: LOADING_REQUEST });
this.setState({
repliesRes: await HttpService.client.getReplies({
sort,
@@ -775,7 +777,7 @@ export class Inbox extends Component {
}),
});
- this.setState({ mentionsRes: { state: "loading" } });
+ this.setState({ mentionsRes: LOADING_REQUEST });
this.setState({
mentionsRes: await HttpService.client.getPersonMentions({
sort,
@@ -785,7 +787,7 @@ export class Inbox extends Component {
}),
});
- this.setState({ messagesRes: { state: "loading" } });
+ this.setState({ messagesRes: LOADING_REQUEST });
this.setState({
messagesRes: await HttpService.client.getPrivateMessages({
unread_only,
@@ -802,7 +804,7 @@ export class Inbox extends Component {
}
async handleMarkAllAsRead(i: Inbox) {
- i.setState({ markAllAsReadRes: { state: "loading" } });
+ i.setState({ markAllAsReadRes: LOADING_REQUEST });
i.setState({
markAllAsReadRes: await HttpService.client.markAllAsRead(),
@@ -810,9 +812,9 @@ export class Inbox extends Component {
if (i.state.markAllAsReadRes.state === "success") {
i.setState({
- repliesRes: { state: "empty" },
- mentionsRes: { state: "empty" },
- messagesRes: { state: "empty" },
+ repliesRes: EMPTY_REQUEST,
+ mentionsRes: EMPTY_REQUEST,
+ messagesRes: EMPTY_REQUEST,
});
}
}
diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx
index 1acfee49..8fc8078d 100644
--- a/src/shared/components/person/password-change.tsx
+++ b/src/shared/components/person/password-change.tsx
@@ -3,7 +3,11 @@ import { capitalizeFirstLetter } from "@utils/helpers";
import { Component, linkEvent } from "inferno";
import { GetSiteResponse, LoginResponse } from "lemmy-js-client";
import { HttpService, I18NextService, UserService } from "../../services";
-import { RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
import PasswordInput from "../common/password-input";
@@ -22,7 +26,7 @@ export class PasswordChange extends Component {
private isoData = setIsoData(this.context);
state: State = {
- passwordChangeRes: { state: "empty" },
+ passwordChangeRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
form: {
token: this.props.match.params.token,
@@ -106,7 +110,7 @@ export class PasswordChange extends Component {
async handlePasswordChangeSubmit(i: PasswordChange, event: any) {
event.preventDefault();
- i.setState({ passwordChangeRes: { state: "loading" } });
+ i.setState({ passwordChangeRes: LOADING_REQUEST });
const password = i.state.form.password;
const password_verify = i.state.form.password_verify;
diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx
index cfff6394..6a92c6c9 100644
--- a/src/shared/components/person/profile.tsx
+++ b/src/shared/components/person/profile.tsx
@@ -76,7 +76,12 @@ import { fetchLimit, relTags } from "../../config";
import { InitialFetchRequest, PersonDetailsView } from "../../interfaces";
import { mdToHtml } from "../../markdown";
import { FirstLoadService, I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { setupTippy } from "../../tippy";
import { toast } from "../../toast";
import { BannerIconHeader } from "../common/banner-icon-header";
@@ -171,7 +176,7 @@ export class Profile extends Component<
> {
private isoData = setIsoData(this.context);
state: ProfileState = {
- personRes: { state: "empty" },
+ personRes: EMPTY_REQUEST,
personBlocked: false,
siteRes: this.isoData.site_res,
showBanDialog: false,
@@ -245,7 +250,7 @@ export class Profile extends Component<
async fetchUserData() {
const { page, sort, view } = getProfileQueryParams();
- this.setState({ personRes: { state: "loading" } });
+ this.setState({ personRes: LOADING_REQUEST });
const personRes = await HttpService.client.getPersonDetails({
username: this.props.match.params.username,
sort,
diff --git a/src/shared/components/person/registration-applications.tsx b/src/shared/components/person/registration-applications.tsx
index ac752f32..4525fa5a 100644
--- a/src/shared/components/person/registration-applications.tsx
+++ b/src/shared/components/person/registration-applications.tsx
@@ -12,7 +12,12 @@ import {
import { fetchLimit } from "../../config";
import { InitialFetchRequest } from "../../interfaces";
import { FirstLoadService, I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { setupTippy } from "../../tippy";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
@@ -42,7 +47,7 @@ export class RegistrationApplications extends Component<
> {
private isoData = setIsoData(this.context);
state: RegistrationApplicationsState = {
- appsRes: { state: "empty" },
+ appsRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
unreadOrAll: UnreadOrAll.Unread,
page: 1,
@@ -210,14 +215,14 @@ export class RegistrationApplications extends Component<
page: 1,
limit: fetchLimit,
})
- : { state: "empty" },
+ : EMPTY_REQUEST,
};
}
async refetch() {
const unread_only = this.state.unreadOrAll === UnreadOrAll.Unread;
this.setState({
- appsRes: { state: "loading" },
+ appsRes: LOADING_REQUEST,
});
this.setState({
appsRes: await HttpService.client.listRegistrationApplications({
diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx
index 9de8463e..122fa234 100644
--- a/src/shared/components/person/reports.tsx
+++ b/src/shared/components/person/reports.tsx
@@ -35,7 +35,11 @@ import {
I18NextService,
UserService,
} from "../../services";
-import { RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { CommentReport } from "../comment/comment-report";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
@@ -88,9 +92,9 @@ interface ReportsState {
export class Reports extends Component {
private isoData = setIsoData(this.context);
state: ReportsState = {
- commentReportsRes: { state: "empty" },
- postReportsRes: { state: "empty" },
- messageReportsRes: { state: "empty" },
+ commentReportsRes: EMPTY_REQUEST,
+ postReportsRes: EMPTY_REQUEST,
+ messageReportsRes: EMPTY_REQUEST,
unreadOrAll: UnreadOrAll.Unread,
messageType: MessageType.All,
page: 1,
@@ -551,7 +555,7 @@ export class Reports extends Component {
const data: ReportsData = {
commentReportsRes: await client.listCommentReports(commentReportsForm),
postReportsRes: await client.listPostReports(postReportsForm),
- messageReportsRes: { state: "empty" },
+ messageReportsRes: EMPTY_REQUEST,
};
if (amAdmin()) {
@@ -575,9 +579,9 @@ export class Reports extends Component {
const limit = fetchLimit;
this.setState({
- commentReportsRes: { state: "loading" },
- postReportsRes: { state: "loading" },
- messageReportsRes: { state: "loading" },
+ commentReportsRes: LOADING_REQUEST,
+ postReportsRes: LOADING_REQUEST,
+ messageReportsRes: LOADING_REQUEST,
});
const form:
diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx
index 001b7e33..2dad9f95 100644
--- a/src/shared/components/person/settings.tsx
+++ b/src/shared/components/person/settings.tsx
@@ -184,10 +184,10 @@ function handleClose2faModal(i: Settings) {
export class Settings extends Component {
private isoData = setIsoData(this.context);
state: SettingsState = {
- saveRes: { state: "empty" },
- deleteAccountRes: { state: "empty" },
- changePasswordRes: { state: "empty" },
- instancesRes: { state: "empty" },
+ saveRes: EMPTY_REQUEST,
+ deleteAccountRes: EMPTY_REQUEST,
+ changePasswordRes: EMPTY_REQUEST,
+ instancesRes: EMPTY_REQUEST,
saveUserSettingsForm: {},
changePasswordForm: {},
deleteAccountShowConfirm: false,
@@ -312,7 +312,7 @@ export class Settings extends Component {
if (!this.state.isIsomorphic) {
this.setState({
- instancesRes: { state: "loading" },
+ instancesRes: LOADING_REQUEST,
});
this.setState({
@@ -1432,7 +1432,7 @@ export class Settings extends Component {
async handleSaveSettingsSubmit(i: Settings, event: any) {
event.preventDefault();
- i.setState({ saveRes: { state: "loading" } });
+ i.setState({ saveRes: LOADING_REQUEST });
const saveRes = await HttpService.client.saveUserSettings({
...i.state.saveUserSettingsForm,
@@ -1467,7 +1467,7 @@ export class Settings extends Component {
i.state.changePasswordForm;
if (new_password && old_password && new_password_verify) {
- i.setState({ changePasswordRes: { state: "loading" } });
+ i.setState({ changePasswordRes: LOADING_REQUEST });
const changePasswordRes = await HttpService.client.changePassword({
new_password,
new_password_verify,
@@ -1498,7 +1498,7 @@ export class Settings extends Component {
event.preventDefault();
const password = i.state.deleteAccountForm.password;
if (password) {
- i.setState({ deleteAccountRes: { state: "loading" } });
+ i.setState({ deleteAccountRes: LOADING_REQUEST });
const deleteAccountRes = await HttpService.client.deleteAccount({
password,
// TODO: promt user weather he wants the content to be deleted
diff --git a/src/shared/components/person/verify-email.tsx b/src/shared/components/person/verify-email.tsx
index b736146e..35bece5f 100644
--- a/src/shared/components/person/verify-email.tsx
+++ b/src/shared/components/person/verify-email.tsx
@@ -2,7 +2,12 @@ import { setIsoData } from "@utils/app";
import { Component } from "inferno";
import { GetSiteResponse, VerifyEmailResponse } from "lemmy-js-client";
import { I18NextService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { toast } from "../../toast";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
@@ -16,7 +21,7 @@ export class VerifyEmail extends Component {
private isoData = setIsoData(this.context);
state: State = {
- verifyRes: { state: "empty" },
+ verifyRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
};
@@ -26,7 +31,7 @@ export class VerifyEmail extends Component {
async verify() {
this.setState({
- verifyRes: { state: "loading" },
+ verifyRes: LOADING_REQUEST,
});
this.setState({
diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx
index b447cf14..bd5b3edf 100644
--- a/src/shared/components/post/create-post.tsx
+++ b/src/shared/components/post/create-post.tsx
@@ -14,6 +14,7 @@ import {
import { InitialFetchRequest, PostFormParams } from "../../interfaces";
import { FirstLoadService, I18NextService } from "../../services";
import {
+ EMPTY_REQUEST,
HttpService,
RequestState,
WrappedLemmyHttp,
@@ -57,7 +58,7 @@ export class CreatePost extends Component<
state: CreatePostState = {
siteRes: this.isoData.site_res,
loading: true,
- initialCommunitiesRes: { state: "empty" },
+ initialCommunitiesRes: EMPTY_REQUEST,
isIsomorphic: false,
};
@@ -242,7 +243,7 @@ export class CreatePost extends Component<
>): Promise {
const data: CreatePostData = {
initialCommunitiesRes: await fetchCommunitiesForOptions(client),
- communityResponse: { state: "empty" },
+ communityResponse: EMPTY_REQUEST,
};
if (communityId) {
diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx
index 406d86ea..970bf93c 100644
--- a/src/shared/components/post/post-form.tsx
+++ b/src/shared/components/post/post-form.tsx
@@ -29,7 +29,12 @@ import {
} from "../../config";
import { PostFormParams } from "../../interfaces";
import { I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { setupTippy } from "../../tippy";
import { toast } from "../../toast";
import { Icon, Spinner } from "../common/icon";
@@ -116,7 +121,7 @@ function copySuggestedTitle(d: { i: PostForm; suggestedTitle?: string }) {
d.i.setState(
s => ((s.form.name = sTitle?.substring(0, MAX_POST_TITLE_LENGTH)), s),
);
- d.i.setState({ suggestedPostsRes: { state: "empty" } });
+ d.i.setState({ suggestedPostsRes: EMPTY_REQUEST });
setTimeout(() => {
const textarea: any = document.getElementById("post-title");
autosize.update(textarea);
@@ -215,8 +220,8 @@ function handleImageDelete(i: PostForm) {
export class PostForm extends Component {
state: PostFormState = {
- suggestedPostsRes: { state: "empty" },
- metadataRes: { state: "empty" },
+ suggestedPostsRes: EMPTY_REQUEST,
+ metadataRes: EMPTY_REQUEST,
form: {},
loading: false,
imageLoading: false,
@@ -648,7 +653,7 @@ export class PostForm extends Component {
async fetchPageTitle() {
const url = this.state.form.url;
if (url && validURL(url)) {
- this.setState({ metadataRes: { state: "loading" } });
+ this.setState({ metadataRes: LOADING_REQUEST });
this.setState({
metadataRes: await HttpService.client.getSiteMetadata({ url }),
});
@@ -658,7 +663,7 @@ export class PostForm extends Component {
async fetchSimilarPosts() {
const q = this.state.form.name;
if (q && q !== "") {
- this.setState({ suggestedPostsRes: { state: "loading" } });
+ this.setState({ suggestedPostsRes: LOADING_REQUEST });
this.setState({
suggestedPostsRes: await HttpService.client.search({
q,
diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx
index 25514208..8f9bd59e 100644
--- a/src/shared/components/post/post.tsx
+++ b/src/shared/components/post/post.tsx
@@ -83,7 +83,12 @@ import {
InitialFetchRequest,
} from "../../interfaces";
import { FirstLoadService, I18NextService, UserService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { setupTippy } from "../../tippy";
import { toast } from "../../toast";
import { CommentForm } from "../comment/comment-form";
@@ -120,8 +125,8 @@ export class Post extends Component {
private isoData = setIsoData(this.context);
private commentScrollDebounced: () => void;
state: PostState = {
- postRes: { state: "empty" },
- commentsRes: { state: "empty" },
+ postRes: EMPTY_REQUEST,
+ commentsRes: EMPTY_REQUEST,
postId: getIdFromProps(this.props),
commentId: getCommentIdFromProps(this.props),
commentSort: "Hot",
@@ -196,8 +201,8 @@ export class Post extends Component {
async fetchPost() {
this.setState({
- postRes: { state: "loading" },
- commentsRes: { state: "loading" },
+ postRes: LOADING_REQUEST,
+ commentsRes: LOADING_REQUEST,
});
const [postRes, commentsRes] = await Promise.all([
@@ -697,8 +702,8 @@ export class Post extends Component {
i.setState({
commentSort: event.target.value as CommentSortType,
commentViewType: CommentViewType.Tree,
- commentsRes: { state: "loading" },
- postRes: { state: "loading" },
+ commentsRes: LOADING_REQUEST,
+ postRes: LOADING_REQUEST,
});
await i.fetchPost();
}
diff --git a/src/shared/components/private_message/create-private-message.tsx b/src/shared/components/private_message/create-private-message.tsx
index cbe25d79..7c04771f 100644
--- a/src/shared/components/private_message/create-private-message.tsx
+++ b/src/shared/components/private_message/create-private-message.tsx
@@ -9,7 +9,12 @@ import {
} from "lemmy-js-client";
import { InitialFetchRequest } from "../../interfaces";
import { FirstLoadService, I18NextService } from "../../services";
-import { HttpService, RequestState } from "../../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../../services/HttpService";
import { toast } from "../../toast";
import { HtmlTags } from "../common/html-tags";
import { Spinner } from "../common/icon";
@@ -33,7 +38,7 @@ export class CreatePrivateMessage extends Component<
private isoData = setIsoData(this.context);
state: CreatePrivateMessageState = {
siteRes: this.isoData.site_res,
- recipientRes: { state: "empty" },
+ recipientRes: EMPTY_REQUEST,
recipientId: getRecipientIdFromProps(this.props),
isIsomorphic: false,
};
@@ -78,7 +83,7 @@ export class CreatePrivateMessage extends Component<
async fetchPersonDetails() {
this.setState({
- recipientRes: { state: "loading" },
+ recipientRes: LOADING_REQUEST,
});
this.setState({
diff --git a/src/shared/components/remote-fetch.tsx b/src/shared/components/remote-fetch.tsx
index 8f7a3f4b..38b58720 100644
--- a/src/shared/components/remote-fetch.tsx
+++ b/src/shared/components/remote-fetch.tsx
@@ -5,7 +5,11 @@ import { Component, linkEvent } from "inferno";
import { CommunityView, ResolveObjectResponse } from "lemmy-js-client";
import { InitialFetchRequest } from "../interfaces";
import { FirstLoadService, HttpService, I18NextService } from "../services";
-import { RequestState } from "../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ LOADING_REQUEST,
+ RequestState,
+} from "../services/HttpService";
import { HtmlTags } from "./common/html-tags";
import { Spinner } from "./common/icon";
import { LoadingEllipses } from "./common/loading-ellipses";
@@ -76,7 +80,7 @@ const handleUnfollow = (i: RemoteFetch) => handleToggleFollow(i, false);
export class RemoteFetch extends Component {
private isoData = setIsoData(this.context);
state: RemoteFetchState = {
- resolveObjectRes: { state: "empty" },
+ resolveObjectRes: EMPTY_REQUEST,
isIsomorphic: false,
followCommunityLoading: false,
};
@@ -100,7 +104,7 @@ export class RemoteFetch extends Component {
const { uri } = getRemoteFetchQueryParams();
if (uri) {
- this.setState({ resolveObjectRes: { state: "loading" } });
+ this.setState({ resolveObjectRes: LOADING_REQUEST });
this.setState({
resolveObjectRes: await HttpService.client.resolveObject({
q: uriToQuery(uri),
@@ -208,7 +212,7 @@ export class RemoteFetch extends Component {
}: InitialFetchRequest<
QueryParams
>): Promise {
- const data: RemoteFetchData = { resolveObjectRes: { state: "empty" } };
+ const data: RemoteFetchData = { resolveObjectRes: EMPTY_REQUEST };
if (uri && auth) {
data.resolveObjectRes = await client.resolveObject({
diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx
index 9041d6fc..08d70727 100644
--- a/src/shared/components/search.tsx
+++ b/src/shared/components/search.tsx
@@ -48,7 +48,12 @@ import {
import { fetchLimit } from "../config";
import { CommentViewType, InitialFetchRequest } from "../interfaces";
import { FirstLoadService, I18NextService } from "../services";
-import { HttpService, RequestState } from "../services/HttpService";
+import {
+ EMPTY_REQUEST,
+ HttpService,
+ LOADING_REQUEST,
+ RequestState,
+} from "../services/HttpService";
import { CommentNodes } from "./comment/comment-nodes";
import { HtmlTags } from "./common/html-tags";
import { Spinner } from "./common/icon";
@@ -239,14 +244,14 @@ export class Search extends Component {
private isoData = setIsoData(this.context);
state: SearchState = {
- resolveObjectRes: { state: "empty" },
- creatorDetailsRes: { state: "empty" },
- communitiesRes: { state: "empty" },
- communityRes: { state: "empty" },
+ resolveObjectRes: EMPTY_REQUEST,
+ creatorDetailsRes: EMPTY_REQUEST,
+ communitiesRes: EMPTY_REQUEST,
+ communityRes: EMPTY_REQUEST,
siteRes: this.isoData.site_res,
creatorSearchOptions: [],
communitySearchOptions: [],
- searchRes: { state: "empty" },
+ searchRes: EMPTY_REQUEST,
searchCreatorLoading: false,
searchCommunitiesLoading: false,
isIsomorphic: false,
@@ -343,7 +348,7 @@ export class Search extends Component {
}
async fetchCommunities() {
- this.setState({ communitiesRes: { state: "loading" } });
+ this.setState({ communitiesRes: LOADING_REQUEST });
this.setState({
communitiesRes: await HttpService.client.listCommunities({
type_: defaultListingType,
@@ -362,12 +367,9 @@ export class Search extends Component {
query: { communityId, creatorId, q, type, sort, listingType, page },
}: InitialFetchRequest>): Promise {
const community_id = getIdFromString(communityId);
- let communityResponse: RequestState = {
- state: "empty",
- };
- let listCommunitiesResponse: RequestState = {
- state: "empty",
- };
+ let communityResponse: RequestState = EMPTY_REQUEST;
+ let listCommunitiesResponse: RequestState =
+ EMPTY_REQUEST;
if (community_id) {
const getCommunityForm: GetCommunity = {
id: community_id,
@@ -387,9 +389,8 @@ export class Search extends Component {
}
const creator_id = getIdFromString(creatorId);
- let creatorDetailsResponse: RequestState = {
- state: "empty",
- };
+ let creatorDetailsResponse: RequestState =
+ EMPTY_REQUEST;
if (creator_id) {
const getCreatorForm: GetPersonDetails = {
person_id: creator_id,
@@ -400,10 +401,9 @@ export class Search extends Component {
const query = getSearchQueryFromQuery(q);
- let searchResponse: RequestState = { state: "empty" };
- let resolveObjectResponse: RequestState = {
- state: "empty",
- };
+ let searchResponse: RequestState = EMPTY_REQUEST;
+ let resolveObjectResponse: RequestState =
+ EMPTY_REQUEST;
if (query) {
const form: SearchForm = {
@@ -430,7 +430,7 @@ export class Search extends Component {
// If we return this object with a state of failed, the catch-all-handler will redirect
// to an error page, so we ignore it by covering up the error with the empty state.
if (resolveObjectResponse.state === "failed") {
- resolveObjectResponse = { state: "empty" };
+ resolveObjectResponse = EMPTY_REQUEST;
}
}
}
@@ -744,8 +744,8 @@ export class Search extends Component {
onPersonMentionRead={() => {}}
onBanPersonFromCommunity={() => {}}
onBanPerson={() => {}}
- onCreateComment={() => Promise.resolve({ state: "empty" })}
- onEditComment={() => Promise.resolve({ state: "empty" })}
+ onCreateComment={() => Promise.resolve(EMPTY_REQUEST)}
+ onEditComment={() => Promise.resolve(EMPTY_REQUEST)}
/>
)}
{i.type_ === "communities" && (
@@ -805,8 +805,8 @@ export class Search extends Component {
onPersonMentionRead={() => {}}
onBanPersonFromCommunity={() => {}}
onBanPerson={() => {}}
- onCreateComment={() => Promise.resolve({ state: "empty" })}
- onEditComment={() => Promise.resolve({ state: "empty" })}
+ onCreateComment={() => Promise.resolve(EMPTY_REQUEST)}
+ onEditComment={() => Promise.resolve(EMPTY_REQUEST)}
/>
);
}
@@ -948,7 +948,7 @@ export class Search extends Component {
getSearchQueryParams();
if (q) {
- this.setState({ searchRes: { state: "loading" } });
+ this.setState({ searchRes: LOADING_REQUEST });
this.setState({
searchRes: await HttpService.client.search({
q,
@@ -965,7 +965,7 @@ export class Search extends Component {
restoreScrollPosition(this.context);
if (myAuth()) {
- this.setState({ resolveObjectRes: { state: "loading" } });
+ this.setState({ resolveObjectRes: LOADING_REQUEST });
this.setState({
resolveObjectRes: await HttpService.silent_client.resolveObject({
q,
diff --git a/src/shared/services/HomeCacheService.ts b/src/shared/services/HomeCacheService.ts
index 9f33dc4e..43a952f1 100644
--- a/src/shared/services/HomeCacheService.ts
+++ b/src/shared/services/HomeCacheService.ts
@@ -1,5 +1,5 @@
import { GetPostsResponse } from "lemmy-js-client";
-import { RequestState } from "./HttpService.js";
+import { EMPTY_REQUEST, RequestState } from "./HttpService.js";
/**
* Service to cache home post listings and restore home state when user uses the browser back buttons.
@@ -8,7 +8,7 @@ export class HomeCacheService {
static #_instance: HomeCacheService;
historyIdx = 0;
scrollY = 0;
- posts: RequestState = { state: "empty" };
+ posts: RequestState = EMPTY_REQUEST;
get active() {
return (