Fixing a few things, commenting out props for now.

This commit is contained in:
Dessalines 2023-06-07 13:33:15 -04:00
parent f8dc8caa99
commit 5bd558000c
10 changed files with 61 additions and 137 deletions

View file

@ -17,9 +17,16 @@
"start": "yarn build:dev --watch" "start": "yarn build:dev --watch"
}, },
"lint-staged": { "lint-staged": {
"*.{ts,tsx,js}": ["prettier --write", "eslint --fix"], "*.{ts,tsx,js}": [
"*.{css, scss}": ["prettier --write"], "prettier --write",
"package.json": ["sortpack"] "eslint --fix"
],
"*.{css, scss}": [
"prettier --write"
],
"package.json": [
"sortpack"
]
}, },
"dependencies": { "dependencies": {
"@babel/plugin-proposal-decorators": "^7.21.0", "@babel/plugin-proposal-decorators": "^7.21.0",

View file

@ -53,7 +53,6 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
expanded: false, expanded: false,
showDropdown: false, showDropdown: false,
}; };
subscription: any;
collapseButtonRef = createRef<HTMLButtonElement>(); collapseButtonRef = createRef<HTMLButtonElement>();
constructor(props: any, context: any) { constructor(props: any, context: any) {

View file

@ -1,7 +1,6 @@
import autosize from "autosize"; import autosize from "autosize";
import { NoOptionI18nKeys } from "i18next"; import { NoOptionI18nKeys } from "i18next";
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { Prompt } from "inferno-router";
import { Language } from "lemmy-js-client"; import { Language } from "lemmy-js-client";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { HttpService, UserService } from "../../services"; import { HttpService, UserService } from "../../services";
@ -104,14 +103,6 @@ export class MarkdownTextArea extends Component<
} }
} }
componentDidUpdate() {
if (!this.props.hideNavigationWarnings && this.state.content) {
window.onbeforeunload = () => true;
} else {
window.onbeforeunload = null;
}
}
componentWillReceiveProps(nextProps: MarkdownTextAreaProps) { componentWillReceiveProps(nextProps: MarkdownTextAreaProps) {
if (nextProps.finished) { if (nextProps.finished) {
this.setState({ this.setState({
@ -131,19 +122,16 @@ export class MarkdownTextArea extends Component<
} }
} }
componentWillUnmount() {
window.onbeforeunload = null;
}
render() { render() {
const languageId = this.state.languageId; const languageId = this.state.languageId;
// TODO add these prompts back in at some point
// <Prompt
// when={!this.props.hideNavigationWarnings && this.state.content}
// message={i18n.t("block_leaving")}
// />
return ( return (
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}> <form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
<Prompt
when={!this.props.hideNavigationWarnings && this.state.content}
message={i18n.t("block_leaving")}
/>
<div className="form-group row"> <div className="form-group row">
<div className={`col-sm-12`}> <div className={`col-sm-12`}>
<textarea <textarea

View file

@ -6,7 +6,6 @@ import {
ListCommunitiesResponse, ListCommunitiesResponse,
ListingType, ListingType,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { Subscription } from "rxjs";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { InitialFetchRequest } from "../../interfaces"; import { InitialFetchRequest } from "../../interfaces";
import { HttpService, RequestState } from "../../services/HttpService"; import { HttpService, RequestState } from "../../services/HttpService";
@ -16,7 +15,6 @@ import {
getPageFromString, getPageFromString,
getQueryParams, getQueryParams,
getQueryString, getQueryString,
isBrowser,
isInitialRoute, isInitialRoute,
myAuth, myAuth,
myAuthRequired, myAuthRequired,
@ -48,7 +46,6 @@ function getListingTypeFromQuery(listingType?: string): ListingType {
} }
export class Communities extends Component<any, CommunitiesState> { export class Communities extends Component<any, CommunitiesState> {
private subscription?: Subscription;
private isoData = setIsoData(this.context); private isoData = setIsoData(this.context);
state: CommunitiesState = { state: CommunitiesState = {
listCommunitiesResponse: { state: "empty" }, listCommunitiesResponse: { state: "empty" },
@ -76,12 +73,6 @@ export class Communities extends Component<any, CommunitiesState> {
} }
} }
componentWillUnmount() {
if (isBrowser()) {
this.subscription?.unsubscribe();
}
}
get documentTitle(): string { get documentTitle(): string {
return `${i18n.t("communities")} - ${ return `${i18n.t("communities")} - ${
this.state.siteRes.site_view.site.name this.state.siteRes.site_view.site.name

View file

@ -1,12 +1,10 @@
import { Component, linkEvent } from "inferno"; import { Component, linkEvent } from "inferno";
import { Prompt } from "inferno-router";
import { import {
CommunityView, CommunityView,
CreateCommunity, CreateCommunity,
EditCommunity, EditCommunity,
Language, Language,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { Subscription } from "rxjs";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { capitalizeFirstLetter, myAuthRequired, randomStr } from "../../utils"; import { capitalizeFirstLetter, myAuthRequired, randomStr } from "../../utils";
import { Icon, Spinner } from "../common/icon"; import { Icon, Spinner } from "../common/icon";
@ -43,7 +41,6 @@ export class CommunityForm extends Component<
CommunityFormState CommunityFormState
> { > {
private id = `community-form-${randomStr()}`; private id = `community-form-${randomStr()}`;
private subscription?: Subscription;
state: CommunityFormState = { state: CommunityFormState = {
form: {}, form: {},
@ -84,36 +81,20 @@ export class CommunityForm extends Component<
} }
} }
componentDidUpdate() { // TODO
if ( // <Prompt
!this.state.loading && // when={
(this.state.form.name || // !this.state.loading &&
this.state.form.title || // (this.state.form.name ||
this.state.form.description) // this.state.form.title ||
) { // this.state.form.description)
window.onbeforeunload = () => true; // }
} else { // message={i18n.t("block_leaving")}
window.onbeforeunload = null; // />
}
}
componentWillUnmount() {
this.subscription?.unsubscribe();
window.onbeforeunload = null;
}
render() { render() {
return ( return (
<> <>
<Prompt
when={
!this.state.loading &&
(this.state.form.name ||
this.state.form.title ||
this.state.form.description)
}
message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}> <form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
{!this.props.community_view && ( {!this.props.community_view && (
<div className="form-group row"> <div className="form-group row">

View file

@ -58,7 +58,5 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
const name = res.data.community_view.community.name; const name = res.data.community_view.community.name;
this.props.history.replace(`/c/${name}`); this.props.history.replace(`/c/${name}`);
} }
return res;
} }
} }

View file

@ -4,7 +4,6 @@ import {
InfernoMouseEvent, InfernoMouseEvent,
linkEvent, linkEvent,
} from "inferno"; } from "inferno";
import { Prompt } from "inferno-router";
import { import {
CreateSite, CreateSite,
EditSite, EditSite,
@ -115,40 +114,23 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
this.setState({ loading: false }); this.setState({ loading: false });
} }
componentDidUpdate() { // TODO
if ( // <Prompt
!this.state.loading && // when={
!this.props.siteRes.site_view.local_site.site_setup && // !this.state.loading &&
(this.state.siteForm.name || // !siteSetup &&
this.state.siteForm.sidebar || // (this.state.siteForm.name ||
this.state.siteForm.application_question || // this.state.siteForm.sidebar ||
this.state.siteForm.description) // this.state.siteForm.application_question ||
) { // this.state.siteForm.description)
window.onbeforeunload = () => true; // }
} else { // message={i18n.t("block_leaving")}
window.onbeforeunload = null; // />
}
}
componentWillUnmount() {
window.onbeforeunload = null;
}
render() { render() {
const siteSetup = this.props.siteRes.site_view.local_site.site_setup; const siteSetup = this.props.siteRes.site_view.local_site.site_setup;
return ( return (
<> <>
<Prompt
when={
!this.state.loading &&
!siteSetup &&
(this.state.siteForm.name ||
this.state.siteForm.sidebar ||
this.state.siteForm.application_question ||
this.state.siteForm.description)
}
message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handleSaveSiteSubmit)}> <form onSubmit={linkEvent(this, this.handleSaveSiteSubmit)}>
<h5>{`${ <h5>{`${
siteSetup siteSetup

View file

@ -1,6 +1,5 @@
import autosize from "autosize"; import autosize from "autosize";
import { Component, linkEvent } from "inferno"; import { Component, InfernoNode, linkEvent } from "inferno";
import { Prompt } from "inferno-router";
import { import {
CreatePost, CreatePost,
EditPost, EditPost,
@ -142,22 +141,19 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
} }
} }
static getDerivedStateFromProps( componentWillReceiveProps(
{ selectedCommunityChoice, post_view }: PostFormProps, nextProps: Readonly<{ children?: InfernoNode } & PostFormProps>
{ form, ...restState }: PostFormState ): void {
) { if (this.props != nextProps) {
return post_view this.setState(
? { s => (
...restState, (s.form.community_id = getIdFromString(
form, nextProps.selectedCommunityChoice?.value
} )),
: { s
...restState, )
form: { );
...form, }
community_id: getIdFromString(selectedCommunityChoice?.value),
},
};
} }
render() { render() {
@ -166,18 +162,12 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
const url = this.state.form.url; const url = this.state.form.url;
// TODO
// const promptCheck =
// !!this.state.form.name || !!this.state.form.url || !!this.state.form.body;
// <Prompt when={promptCheck} message={i18n.t("block_leaving")} />
return ( return (
<div> <div>
<Prompt
when={
!(
this.state.form.name ||
this.state.form.url ||
this.state.form.body
)
}
message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handlePostSubmit)}> <form onSubmit={linkEvent(this, this.handlePostSubmit)}>
<div className="form-group row"> <div className="form-group row">
<label className="col-sm-2 col-form-label" htmlFor="post-url"> <label className="col-sm-2 col-form-label" htmlFor="post-url">
@ -513,8 +503,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
auth, auth,
}); });
} }
i.setState({ loading: false });
} }
copySuggestedTitle(d: { i: PostForm; suggestedTitle?: string }) { copySuggestedTitle(d: { i: PostForm; suggestedTitle?: string }) {
@ -624,6 +612,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
if (res.data.msg === "ok") { if (res.data.msg === "ok") {
i.state.form.url = res.data.url; i.state.form.url = res.data.url;
pictrsDeleteToast(file.name, res.data.delete_url as string); pictrsDeleteToast(file.name, res.data.delete_url as string);
i.setState({ imageLoading: false });
} else { } else {
toast(JSON.stringify(res), "danger"); toast(JSON.stringify(res), "danger");
} }
@ -631,8 +620,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
console.error(res.msg); console.error(res.msg);
toast(res.msg, "danger"); toast(res.msg, "danger");
} }
i.setState({ imageLoading: false });
}); });
} }

View file

@ -5,13 +5,11 @@ import {
GetPersonDetailsResponse, GetPersonDetailsResponse,
GetSiteResponse, GetSiteResponse,
} from "lemmy-js-client"; } from "lemmy-js-client";
import { Subscription } from "rxjs";
import { i18n } from "../../i18next"; import { i18n } from "../../i18next";
import { InitialFetchRequest } from "../../interfaces"; import { InitialFetchRequest } from "../../interfaces";
import { HttpService, RequestState } from "../../services/HttpService"; import { HttpService, RequestState } from "../../services/HttpService";
import { import {
getRecipientIdFromProps, getRecipientIdFromProps,
isBrowser,
isInitialRoute, isInitialRoute,
myAuth, myAuth,
setIsoData, setIsoData,
@ -32,7 +30,6 @@ export class CreatePrivateMessage extends Component<
CreatePrivateMessageState CreatePrivateMessageState
> { > {
private isoData = setIsoData(this.context); private isoData = setIsoData(this.context);
private subscription?: Subscription;
state: CreatePrivateMessageState = { state: CreatePrivateMessageState = {
siteRes: this.isoData.site_res, siteRes: this.isoData.site_res,
recipientRes: { state: "empty" }, recipientRes: { state: "empty" },
@ -96,12 +93,6 @@ export class CreatePrivateMessage extends Component<
} }
} }
componentWillUnmount() {
if (isBrowser()) {
this.subscription?.unsubscribe();
}
}
renderRecipientRes() { renderRecipientRes() {
switch (this.state.recipientRes.state) { switch (this.state.recipientRes.state) {
case "loading": case "loading":

View file

@ -1,6 +1,5 @@
import { Component, InfernoNode, linkEvent } from "inferno"; import { Component, InfernoNode, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess"; import { T } from "inferno-i18next-dess";
import { Prompt } from "inferno-router";
import { import {
CreatePrivateMessage, CreatePrivateMessage,
EditPrivateMessage, EditPrivateMessage,
@ -63,14 +62,15 @@ export class PrivateMessageForm extends Component<
this.setState({ loading: false, content: undefined, previewMode: false }); this.setState({ loading: false, content: undefined, previewMode: false });
} }
} }
// TODO
// <Prompt
// when={!this.state.loading && this.state.content}
// message={i18n.t("block_leaving")}
// />
render() { render() {
return ( return (
<div> <div>
<Prompt
when={!this.state.loading && this.state.content}
message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handlePrivateMessageSubmit)}> <form onSubmit={linkEvent(this, this.handlePrivateMessageSubmit)}>
{!this.props.privateMessageView && ( {!this.props.privateMessageView && (
<div className="form-group row"> <div className="form-group row">