chore: Use constant objects where appropriate

This commit is contained in:
SleeplessOne1917 2023-10-04 18:46:50 -04:00
parent 1a2205c867
commit 61df23955c
24 changed files with 236 additions and 155 deletions

View file

@ -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)}
/>
<div>
{I18NextService.i18n.t("reporter")}:{" "}

View file

@ -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<any, CommunitiesState> {
private isoData = setIsoData<CommunitiesData>(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<any, CommunitiesState> {
}
async refetch() {
this.setState({ listCommunitiesResponse: { state: "loading" } });
this.setState({ listCommunitiesResponse: LOADING_REQUEST });
const { listingType, sort, page } = getCommunitiesQueryParams();

View file

@ -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<CommunityData>(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<GetPostsResponse> = { state: "empty" };
let commentsResponse: RequestState<GetCommentsResponse> = {
state: "empty",
};
let postsResponse: RequestState<GetPostsResponse> = EMPTY_REQUEST;
let commentsResponse: RequestState<GetCommentsResponse> = 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,

View file

@ -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<any, AdminSettingsState> {
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<any, AdminSettingsState> {
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<any, AdminSettingsState> {
}
async handleLeaveAdminTeam(i: AdminSettings) {
i.setState({ leaveAdminTeamRes: { state: "loading" } });
i.setState({ leaveAdminTeamRes: LOADING_REQUEST });
this.setState({
leaveAdminTeamRes: await HttpService.client.leaveAdmin(),
});

View file

@ -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<any, HomeState> {
private isoData = setIsoData<HomeData>(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<any, HomeState> {
const page = urlPage ? Number(urlPage) : 1;
let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
let commentsRes: RequestState<GetCommentsResponse> = {
state: "empty",
};
let postsRes: RequestState<GetPostsResponse> = EMPTY_REQUEST;
let commentsRes: RequestState<GetCommentsResponse> = EMPTY_REQUEST;
if (dataType === DataType.Post) {
const getPostsForm: GetPosts = {
@ -790,7 +793,7 @@ export class Home extends Component<any, HomeState> {
}
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<any, HomeState> {
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<any, HomeState> {
HomeCacheService.postsRes = this.state.postsRes;
}
} else {
this.setState({ commentsRes: { state: "loading" } });
this.setState({ commentsRes: LOADING_REQUEST });
this.setState({
commentsRes: await HttpService.client.getComments({
page,

View file

@ -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<any, InstancesState> {
private isoData = setIsoData<InstancesData>(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<any, InstancesState> {
async fetchInstances() {
this.setState({
instancesRes: { state: "loading" },
instancesRes: LOADING_REQUEST,
});
this.setState({

View file

@ -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: "",

View file

@ -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<any, State> {
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<any, State> {
async handleRegisterSubmit(i: Setup, event: any) {
event.preventDefault();
i.setState({ registerRes: { state: "loading" } });
i.setState({ registerRes: LOADING_REQUEST });
const {
username,
password_verify,

View file

@ -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<any, State> {
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<any, State> {
}
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<any, State> {
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<any, State> {
switch (registerRes.state) {
case "failed": {
toast(registerRes.msg, "danger");
i.setState({ registerRes: { state: "empty" } });
i.setState({ registerRes: EMPTY_REQUEST });
break;
}

View file

@ -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<ModlogData>(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<GetCommunityResponse> = {
state: "empty",
};
let communityResponse: RequestState<GetCommunityResponse> = EMPTY_REQUEST;
if (communityId) {
const communityForm: GetCommunity = {
@ -1013,9 +1016,7 @@ export class Modlog extends Component<
communityResponse = await client.getCommunity(communityForm);
}
let modUserResponse: RequestState<GetPersonDetailsResponse> = {
state: "empty",
};
let modUserResponse: RequestState<GetPersonDetailsResponse> = EMPTY_REQUEST;
if (modId) {
const getPersonForm: GetPersonDetails = {
@ -1025,9 +1026,7 @@ export class Modlog extends Component<
modUserResponse = await client.getPersonDetails(getPersonForm);
}
let userResponse: RequestState<GetPersonDetailsResponse> = {
state: "empty",
};
let userResponse: RequestState<GetPersonDetailsResponse> = EMPTY_REQUEST;
if (userId) {
const getPersonForm: GetPersonDetails = {

View file

@ -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<any, InboxState> {
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<any, InboxState> {
client,
}: InitialFetchRequest): Promise<InboxData> {
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<any, InboxState> {
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<any, InboxState> {
}),
});
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<any, InboxState> {
}),
});
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<any, InboxState> {
}
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<any, InboxState> {
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,
});
}
}

View file

@ -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<any, State> {
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<any, State> {
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;

View file

@ -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<ProfileData>(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,

View file

@ -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<RegistrationApplicationsData>(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({

View file

@ -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<any, ReportsState> {
private isoData = setIsoData<ReportsData>(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<any, ReportsState> {
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<any, ReportsState> {
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:

View file

@ -184,10 +184,10 @@ function handleClose2faModal(i: Settings) {
export class Settings extends Component<any, SettingsState> {
private isoData = setIsoData<SettingsData>(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<any, SettingsState> {
if (!this.state.isIsomorphic) {
this.setState({
instancesRes: { state: "loading" },
instancesRes: LOADING_REQUEST,
});
this.setState({
@ -1432,7 +1432,7 @@ export class Settings extends Component<any, SettingsState> {
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<any, SettingsState> {
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<any, SettingsState> {
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

View file

@ -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<any, State> {
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<any, State> {
async verify() {
this.setState({
verifyRes: { state: "loading" },
verifyRes: LOADING_REQUEST,
});
this.setState({

View file

@ -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<CreatePostData> {
const data: CreatePostData = {
initialCommunitiesRes: await fetchCommunitiesForOptions(client),
communityResponse: { state: "empty" },
communityResponse: EMPTY_REQUEST,
};
if (communityId) {

View file

@ -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<PostFormProps, PostFormState> {
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<PostFormProps, PostFormState> {
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<PostFormProps, PostFormState> {
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,

View file

@ -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<any, PostState> {
private isoData = setIsoData<PostData>(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<any, PostState> {
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<any, PostState> {
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();
}

View file

@ -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<CreatePrivateMessageData>(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({

View file

@ -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<any, RemoteFetchState> {
private isoData = setIsoData<RemoteFetchData>(this.context);
state: RemoteFetchState = {
resolveObjectRes: { state: "empty" },
resolveObjectRes: EMPTY_REQUEST,
isIsomorphic: false,
followCommunityLoading: false,
};
@ -100,7 +104,7 @@ export class RemoteFetch extends Component<any, RemoteFetchState> {
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<any, RemoteFetchState> {
}: InitialFetchRequest<
QueryParams<RemoteFetchProps>
>): Promise<RemoteFetchData> {
const data: RemoteFetchData = { resolveObjectRes: { state: "empty" } };
const data: RemoteFetchData = { resolveObjectRes: EMPTY_REQUEST };
if (uri && auth) {
data.resolveObjectRes = await client.resolveObject({

View file

@ -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<any, SearchState> {
private isoData = setIsoData<SearchData>(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<any, SearchState> {
}
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<any, SearchState> {
query: { communityId, creatorId, q, type, sort, listingType, page },
}: InitialFetchRequest<QueryParams<SearchProps>>): Promise<SearchData> {
const community_id = getIdFromString(communityId);
let communityResponse: RequestState<GetCommunityResponse> = {
state: "empty",
};
let listCommunitiesResponse: RequestState<ListCommunitiesResponse> = {
state: "empty",
};
let communityResponse: RequestState<GetCommunityResponse> = EMPTY_REQUEST;
let listCommunitiesResponse: RequestState<ListCommunitiesResponse> =
EMPTY_REQUEST;
if (community_id) {
const getCommunityForm: GetCommunity = {
id: community_id,
@ -387,9 +389,8 @@ export class Search extends Component<any, SearchState> {
}
const creator_id = getIdFromString(creatorId);
let creatorDetailsResponse: RequestState<GetPersonDetailsResponse> = {
state: "empty",
};
let creatorDetailsResponse: RequestState<GetPersonDetailsResponse> =
EMPTY_REQUEST;
if (creator_id) {
const getCreatorForm: GetPersonDetails = {
person_id: creator_id,
@ -400,10 +401,9 @@ export class Search extends Component<any, SearchState> {
const query = getSearchQueryFromQuery(q);
let searchResponse: RequestState<SearchResponse> = { state: "empty" };
let resolveObjectResponse: RequestState<ResolveObjectResponse> = {
state: "empty",
};
let searchResponse: RequestState<SearchResponse> = EMPTY_REQUEST;
let resolveObjectResponse: RequestState<ResolveObjectResponse> =
EMPTY_REQUEST;
if (query) {
const form: SearchForm = {
@ -430,7 +430,7 @@ export class Search extends Component<any, SearchState> {
// 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<any, SearchState> {
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<any, SearchState> {
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<any, SearchState> {
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<any, SearchState> {
restoreScrollPosition(this.context);
if (myAuth()) {
this.setState({ resolveObjectRes: { state: "loading" } });
this.setState({ resolveObjectRes: LOADING_REQUEST });
this.setState({
resolveObjectRes: await HttpService.silent_client.resolveObject({
q,

View file

@ -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<GetPostsResponse> = { state: "empty" };
posts: RequestState<GetPostsResponse> = EMPTY_REQUEST;
get active() {
return (