mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-27 08:16:20 +00:00
add optional chaining, remove conditional to fetch on component mount
This commit is contained in:
parent
d0a40f6690
commit
60e8486d5b
|
@ -79,9 +79,7 @@ export class Communities extends Component<any, CommunitiesState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.refetch();
|
||||||
await this.refetch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
|
@ -91,7 +89,7 @@ export class Communities extends Component<any, CommunitiesState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderListings() {
|
renderListings() {
|
||||||
switch (this.state.listCommunitiesResponse.state) {
|
switch (this.state.listCommunitiesResponse?.state) {
|
||||||
case "loading":
|
case "loading":
|
||||||
return (
|
return (
|
||||||
<h5>
|
<h5>
|
||||||
|
|
|
@ -221,9 +221,7 @@ export class Community extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await Promise.all([this.fetchCommunity(), this.fetchData()]);
|
||||||
await Promise.all([this.fetchCommunity(), this.fetchData()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,9 +101,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.fetchData();
|
||||||
await this.fetchData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
|
@ -114,7 +112,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const federationData =
|
const federationData =
|
||||||
this.state.instancesRes.state === "success"
|
this.state.instancesRes?.state === "success"
|
||||||
? this.state.instancesRes.data.federated_instances
|
? this.state.instancesRes.data.federated_instances
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
@ -281,7 +279,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
bannedUsers() {
|
bannedUsers() {
|
||||||
switch (this.state.bannedRes.state) {
|
switch (this.state.bannedRes?.state) {
|
||||||
case "loading":
|
case "loading":
|
||||||
return (
|
return (
|
||||||
<h5>
|
<h5>
|
||||||
|
@ -289,7 +287,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
|
||||||
</h5>
|
</h5>
|
||||||
);
|
);
|
||||||
case "success": {
|
case "success": {
|
||||||
const bans = this.state.bannedRes.data.banned;
|
const bans = this.state.bannedRes?.data.banned;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h5>{I18NextService.i18n.t("banned_users")}</h5>
|
<h5>{I18NextService.i18n.t("banned_users")}</h5>
|
||||||
|
|
|
@ -45,9 +45,7 @@ export class Instances extends Component<any, InstancesState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.fetchInstances();
|
||||||
await this.fetchInstances();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchInstances() {
|
async fetchInstances() {
|
||||||
|
|
|
@ -837,7 +837,7 @@ export class Modlog extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
renderModlogTable() {
|
renderModlogTable() {
|
||||||
switch (this.state.res.state) {
|
switch (this.state.res?.state) {
|
||||||
case "loading":
|
case "loading":
|
||||||
return (
|
return (
|
||||||
<h5>
|
<h5>
|
||||||
|
|
|
@ -177,9 +177,7 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.refetch();
|
||||||
await this.refetch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
|
@ -195,11 +193,11 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
if (this.state.unreadOrAll == UnreadOrAll.Unread) {
|
if (this.state.unreadOrAll == UnreadOrAll.Unread) {
|
||||||
const { repliesRes, mentionsRes, messagesRes } = this.state;
|
const { repliesRes, mentionsRes, messagesRes } = this.state;
|
||||||
const replyCount =
|
const replyCount =
|
||||||
repliesRes.state == "success" ? repliesRes.data.replies.length : 0;
|
repliesRes?.state == "success" ? repliesRes.data.replies.length : 0;
|
||||||
const mentionCount =
|
const mentionCount =
|
||||||
mentionsRes.state == "success" ? mentionsRes.data.mentions.length : 0;
|
mentionsRes?.state == "success" ? mentionsRes.data.mentions.length : 0;
|
||||||
const messageCount =
|
const messageCount =
|
||||||
messagesRes.state == "success"
|
messagesRes?.state == "success"
|
||||||
? messagesRes.data.private_messages.length
|
? messagesRes.data.private_messages.length
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
setIsoData,
|
setIsoData,
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
} from "@utils/app";
|
} from "@utils/app";
|
||||||
import { restoreScrollPosition, saveScrollPosition } from "@utils/browser";
|
|
||||||
import {
|
import {
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
futureDaysToUnixTime,
|
futureDaysToUnixTime,
|
||||||
|
@ -216,16 +215,10 @@ export class Profile extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.fetchUserData();
|
||||||
await this.fetchUserData();
|
|
||||||
}
|
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
saveScrollPosition(this.context);
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchUserData() {
|
async fetchUserData() {
|
||||||
const { page, sort, view } = getProfileQueryParams();
|
const { page, sort, view } = getProfileQueryParams();
|
||||||
|
|
||||||
|
@ -240,12 +233,12 @@ export class Profile extends Component<
|
||||||
auth: myAuth(),
|
auth: myAuth(),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
restoreScrollPosition(this.context);
|
|
||||||
this.setPersonBlock();
|
this.setPersonBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
get amCurrentUser() {
|
get amCurrentUser() {
|
||||||
if (this.state.personRes.state === "success") {
|
if (this.state.personRes?.state === "success") {
|
||||||
return (
|
return (
|
||||||
UserService.Instance.myUserInfo?.local_user_view.person.id ===
|
UserService.Instance.myUserInfo?.local_user_view.person.id ===
|
||||||
this.state.personRes.data.person_view.person.id
|
this.state.personRes.data.person_view.person.id
|
||||||
|
@ -302,7 +295,7 @@ export class Profile extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPersonRes() {
|
renderPersonRes() {
|
||||||
switch (this.state.personRes.state) {
|
switch (this.state.personRes?.state) {
|
||||||
case "loading":
|
case "loading":
|
||||||
return (
|
return (
|
||||||
<h5>
|
<h5>
|
||||||
|
|
|
@ -68,9 +68,7 @@ export class RegistrationApplications extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.refetch();
|
||||||
await this.refetch();
|
|
||||||
}
|
|
||||||
setupTippy();
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +82,7 @@ export class RegistrationApplications extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
renderApps() {
|
renderApps() {
|
||||||
switch (this.state.appsRes.state) {
|
switch (this.state.appsRes?.state) {
|
||||||
case "loading":
|
case "loading":
|
||||||
return (
|
return (
|
||||||
<h5>
|
<h5>
|
||||||
|
@ -92,7 +90,7 @@ export class RegistrationApplications extends Component<
|
||||||
</h5>
|
</h5>
|
||||||
);
|
);
|
||||||
case "success": {
|
case "success": {
|
||||||
const apps = this.state.appsRes.data.registration_applications;
|
const apps = this.state.appsRes?.data.registration_applications;
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
|
|
|
@ -129,9 +129,7 @@ export class Reports extends Component<any, ReportsState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.refetch();
|
||||||
await this.refetch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
|
@ -329,6 +327,11 @@ export class Reports extends Component<any, ReportsState> {
|
||||||
|
|
||||||
get buildCombined(): ItemType[] {
|
get buildCombined(): ItemType[] {
|
||||||
const commentRes = this.state.commentReportsRes;
|
const commentRes = this.state.commentReportsRes;
|
||||||
|
|
||||||
|
if (!commentRes) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const comments =
|
const comments =
|
||||||
commentRes.state == "success"
|
commentRes.state == "success"
|
||||||
? commentRes.data.comment_reports.map(this.commentReportToItemType)
|
? commentRes.data.comment_reports.map(this.commentReportToItemType)
|
||||||
|
|
|
@ -228,8 +228,8 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
setupTippy();
|
|
||||||
this.setState({ themeList: await fetchThemeList() });
|
this.setState({ themeList: await fetchThemeList() });
|
||||||
|
setupTippy();
|
||||||
}
|
}
|
||||||
|
|
||||||
get documentTitle(): string {
|
get documentTitle(): string {
|
||||||
|
|
|
@ -103,7 +103,7 @@ export class CreatePost extends Component<
|
||||||
id: communityId,
|
id: communityId,
|
||||||
auth,
|
auth,
|
||||||
});
|
});
|
||||||
if (res.state === "success") {
|
if (res?.state === "success") {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedCommunityChoice: {
|
selectedCommunityChoice: {
|
||||||
label: res.data.community_view.community.title,
|
label: res.data.community_view.community.title,
|
||||||
|
@ -116,28 +116,23 @@ export class CreatePost extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
// TODO test this
|
const { communityId } = getCreatePostQueryParams();
|
||||||
if (!this.state.isIsomorphic) {
|
|
||||||
const { communityId } = getCreatePostQueryParams();
|
|
||||||
|
|
||||||
const initialCommunitiesRes = await fetchCommunitiesForOptions(
|
const initialCommunitiesRes = await fetchCommunitiesForOptions(
|
||||||
HttpService.client
|
HttpService.client
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
initialCommunitiesRes,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (communityId?.toString() !== this.state.selectedCommunityChoice?.value) {
|
||||||
|
await this.fetchCommunity();
|
||||||
|
} else if (!communityId) {
|
||||||
this.setState({
|
this.setState({
|
||||||
initialCommunitiesRes,
|
selectedCommunityChoice: undefined,
|
||||||
|
loading: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
|
||||||
communityId?.toString() !== this.state.selectedCommunityChoice?.value
|
|
||||||
) {
|
|
||||||
await this.fetchCommunity();
|
|
||||||
} else if (!communityId) {
|
|
||||||
this.setState({
|
|
||||||
selectedCommunityChoice: undefined,
|
|
||||||
loading: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,8 +176,8 @@ export class CreatePost extends Component<
|
||||||
selectedCommunityChoice={selectedCommunityChoice}
|
selectedCommunityChoice={selectedCommunityChoice}
|
||||||
onSelectCommunity={this.handleSelectedCommunityChange}
|
onSelectCommunity={this.handleSelectedCommunityChange}
|
||||||
initialCommunities={
|
initialCommunities={
|
||||||
this.state.initialCommunitiesRes.state === "success"
|
this.state.initialCommunitiesRes?.state === "success"
|
||||||
? this.state.initialCommunitiesRes.data.communities
|
? this.state.initialCommunitiesRes?.data.communities
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
@ -224,7 +219,7 @@ export class CreatePost extends Component<
|
||||||
async handlePostCreate(form: CreatePostI) {
|
async handlePostCreate(form: CreatePostI) {
|
||||||
const res = await HttpService.client.createPost(form);
|
const res = await HttpService.client.createPost(form);
|
||||||
|
|
||||||
if (res.state === "success") {
|
if (res?.state === "success") {
|
||||||
const postId = res.data.post_view.post.id;
|
const postId = res.data.post_view.post.id;
|
||||||
this.props.history.replace(`/post/${postId}`);
|
this.props.history.replace(`/post/${postId}`);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -270,9 +270,7 @@ export class Post extends Component<any, PostState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.fetchPost();
|
||||||
await this.fetchPost();
|
|
||||||
}
|
|
||||||
|
|
||||||
autosize(document.querySelectorAll("textarea"));
|
autosize(document.querySelectorAll("textarea"));
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,7 @@ export class CreatePrivateMessage extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
await this.fetchPersonDetails();
|
||||||
await this.fetchPersonDetails();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async fetchInitialData({
|
static async fetchInitialData({
|
||||||
|
|
|
@ -332,14 +332,12 @@ export class Search extends Component<any, SearchState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
if (!this.state.isIsomorphic) {
|
const promises = [this.fetchCommunities()];
|
||||||
const promises = [this.fetchCommunities()];
|
if (this.state.searchText) {
|
||||||
if (this.state.searchText) {
|
promises.push(this.search());
|
||||||
promises.push(this.search());
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchCommunities() {
|
async fetchCommunities() {
|
||||||
|
|
Loading…
Reference in a new issue