pull latest main

This commit is contained in:
Alec Armbruster 2023-06-16 18:51:51 -04:00
commit 05aa483d89
No known key found for this signature in database
GPG key ID: 0BE3206ADE0F3B3B
13 changed files with 100 additions and 107 deletions

View file

@ -359,7 +359,6 @@ export class Community extends Component<
community_view={res.community_view}
moderators={res.moderators}
admins={site_res.admins}
online={res.online}
enableNsfw={enableNsfw(site_res)}
editable
allLanguages={site_res.all_languages}
@ -646,6 +645,12 @@ export class Community extends Component<
const blockCommunityRes = await HttpService.client.blockCommunity(form);
if (blockCommunityRes.state == "success") {
updateCommunityBlock(blockCommunityRes.data);
this.setState(s => {
if (s.communityRes.state == "success") {
s.communityRes.data.community_view.blocked =
blockCommunityRes.data.blocked;
}
});
}
}

View file

@ -1,4 +1,5 @@
import { Component, InfernoNode, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess";
import { Link } from "inferno-router";
import {
AddModToCommunity,
@ -38,7 +39,6 @@ interface SidebarProps {
allLanguages: Language[];
siteLanguages: number[];
communityLanguages?: number[];
online: number;
enableNsfw?: boolean;
showIcon?: boolean;
editable?: boolean;
@ -63,7 +63,6 @@ interface SidebarState {
removeCommunityLoading: boolean;
leaveModTeamLoading: boolean;
followCommunityLoading: boolean;
blockCommunityLoading: boolean;
purgeCommunityLoading: boolean;
}
@ -77,7 +76,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
removeCommunityLoading: false,
leaveModTeamLoading: false,
followCommunityLoading: false,
blockCommunityLoading: false,
purgeCommunityLoading: false,
};
@ -104,7 +102,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
removeCommunityLoading: false,
leaveModTeamLoading: false,
followCommunityLoading: false,
blockCommunityLoading: false,
purgeCommunityLoading: false,
});
}
@ -144,10 +141,15 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
{myUSerInfo && this.blockCommunity()}
{!myUSerInfo && (
<div className="alert alert-info" role="alert">
{i18n.t("community_not_logged_in_alert", {
community: name,
instance: hostname(actor_id),
})}
<T
i18nKey="community_not_logged_in_alert"
interpolation={{
community: name,
instance: hostname(actor_id),
}}
>
#<code className="user-select-all">#</code>#
</T>
</div>
)}
</div>
@ -234,12 +236,6 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
const counts = community_view.counts;
return (
<ul className="my-1 list-inline">
<li className="list-inline-item badge badge-secondary">
{i18n.t("number_online", {
count: this.props.online,
formattedCount: numToSI(this.props.online),
})}
</li>
<li
className="list-inline-item badge badge-secondary pointer"
data-tippy-content={i18n.t("active_users_in_the_last_day", {
@ -370,35 +366,18 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
blockCommunity() {
const community_view = this.props.community_view;
const blocked = this.props.community_view.blocked;
const { subscribed, blocked } = this.props.community_view;
return (
<div className="mb-2">
{community_view.subscribed == "NotSubscribed" &&
(blocked ? (
<button
className="btn btn-danger btn-block"
onClick={linkEvent(this, this.handleBlockCommunity)}
>
{this.state.blockCommunityLoading ? (
<Spinner />
) : (
i18n.t("unblock_community")
)}
</button>
) : (
<button
className="btn btn-danger btn-block"
onClick={linkEvent(this, this.handleBlockCommunity)}
>
{this.state.blockCommunityLoading ? (
<Spinner />
) : (
i18n.t("block_community")
)}
</button>
))}
{subscribed == "NotSubscribed" && (
<button
className="btn btn-danger btn-block"
onClick={linkEvent(this, this.handleBlockCommunity)}
>
{i18n.t(blocked ? "unblock_community" : "block_community")}
</button>
)}
</div>
);
}
@ -662,10 +641,11 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
}
handleBlockCommunity(i: Sidebar) {
i.setState({ blockCommunityLoading: true });
const { community, blocked } = i.props.community_view;
i.props.onBlockCommunity({
community_id: 0,
block: !i.props.community_view.blocked,
community_id: community.id,
block: !blocked,
auth: myAuthRequired(),
});
}

View file

@ -39,6 +39,8 @@ interface AdminSettingsState {
instancesRes: RequestState<GetFederatedInstancesResponse>;
bannedRes: RequestState<BannedPersonsResponse>;
leaveAdminTeamRes: RequestState<GetSiteResponse>;
emojiLoading: boolean;
loading: boolean;
themeList: string[];
isIsomorphic: boolean;
}
@ -52,6 +54,8 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
bannedRes: { state: "empty" },
instancesRes: { state: "empty" },
leaveAdminTeamRes: { state: "empty" },
emojiLoading: false,
loading: false,
themeList: [],
isIsomorphic: false,
};
@ -81,6 +85,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
bannedRes: { state: "loading" },
instancesRes: { state: "loading" },
themeList: [],
loading: true,
});
const auth = myAuthRequired();
@ -95,6 +100,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
bannedRes,
instancesRes,
themeList,
loading: false,
});
}
@ -156,6 +162,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
onSaveSite={this.handleEditSite}
siteRes={this.state.siteRes}
themeList={this.state.themeList}
loading={this.state.loading}
/>
</div>
<div className="col-12 col-md-6">
@ -174,6 +181,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
this.state.siteRes.site_view.local_site_rate_limit
}
onSaveSite={this.handleEditSite}
loading={this.state.loading}
/>
),
},
@ -185,6 +193,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
<TaglineForm
taglines={this.state.siteRes.taglines}
onSaveSite={this.handleEditSite}
loading={this.state.loading}
/>
</div>
),
@ -198,6 +207,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
onCreate={this.handleCreateEmoji}
onDelete={this.handleDeleteEmoji}
onEdit={this.handleEditEmoji}
loading={this.state.emojiLoading}
/>
</div>
),
@ -266,6 +276,8 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
}
async handleEditSite(form: EditSite) {
this.setState({ loading: true });
const editRes = await HttpService.client.editSite(form);
if (editRes.state === "success") {
@ -278,6 +290,8 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
toast(i18n.t("site_saved"));
}
this.setState({ loading: false });
return editRes;
}
@ -300,23 +314,35 @@ export class AdminSettings extends Component<any, AdminSettingsState> {
}
async handleEditEmoji(form: EditCustomEmoji) {
this.setState({ emojiLoading: true });
const res = await HttpService.client.editCustomEmoji(form);
if (res.state === "success") {
updateEmojiDataModel(res.data.custom_emoji);
}
this.setState({ emojiLoading: false });
}
async handleDeleteEmoji(form: DeleteCustomEmoji) {
this.setState({ emojiLoading: true });
const res = await HttpService.client.deleteCustomEmoji(form);
if (res.state === "success") {
removeFromEmojiDataModel(res.data.id);
}
this.setState({ emojiLoading: false });
}
async handleCreateEmoji(form: CreateCustomEmoji) {
this.setState({ emojiLoading: true });
const res = await HttpService.client.createCustomEmoji(form);
if (res.state === "success") {
updateEmojiDataModel(res.data.custom_emoji);
}
this.setState({ emojiLoading: false });
}
}

View file

@ -23,12 +23,12 @@ interface EmojiFormProps {
onEdit(form: EditCustomEmoji): void;
onCreate(form: CreateCustomEmoji): void;
onDelete(form: DeleteCustomEmoji): void;
loading: boolean;
}
interface EmojiFormState {
siteRes: GetSiteResponse;
customEmojis: CustomEmojiViewForm[];
loading: boolean;
page: number;
}
@ -47,7 +47,6 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
private isoData = setIsoData(this.context);
private itemsPerPage = 15;
private emptyState: EmojiFormState = {
loading: false,
siteRes: this.isoData.site_res,
customEmojis: this.isoData.site_res.custom_emojis.map((x, index) => ({
id: x.custom_emoji.id,
@ -223,7 +222,7 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
data-tippy-content={i18n.t("save")}
aria-label={i18n.t("save")}
disabled={
this.state.loading ||
this.props.loading ||
!this.canEdit(cv) ||
!cv.changed
}
@ -243,7 +242,7 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
)}
data-tippy-content={i18n.t("delete")}
aria-label={i18n.t("delete")}
disabled={this.state.loading}
disabled={this.props.loading}
title={i18n.t("delete")}
>
<Icon

View file

@ -361,7 +361,6 @@ export class Home extends Component<any, HomeState> {
siteRes: {
site_view: { counts, site },
admins,
online,
},
showSubscribedMobile,
showTrendingMobile,
@ -393,7 +392,6 @@ export class Home extends Component<any, HomeState> {
site={site}
admins={admins}
counts={counts}
online={online}
showLocal={showLocal(this.isoData)}
/>
)}
@ -417,7 +415,6 @@ export class Home extends Component<any, HomeState> {
siteRes: {
site_view: { counts, site },
admins,
online,
},
} = this.state;
@ -443,7 +440,6 @@ export class Home extends Component<any, HomeState> {
site={site}
admins={admins}
counts={counts}
online={online}
showLocal={showLocal(this.isoData)}
/>
{this.hasFollows && (

View file

@ -24,6 +24,7 @@ interface RateLimitsProps {
interface RateLimitFormProps {
rateLimits: LocalSiteRateLimit;
onSaveSite(form: EditSite): void;
loading: boolean;
}
interface RateLimitFormState {
@ -41,7 +42,6 @@ interface RateLimitFormState {
register?: number;
register_per_second?: number;
};
loading: boolean;
}
function RateLimits({
@ -117,7 +117,6 @@ function submitRateLimitForm(i: RateLimitsForm, event: any) {
}
);
i.setState({ loading: true });
i.props.onSaveSite(form);
}
@ -126,7 +125,6 @@ export default class RateLimitsForm extends Component<
RateLimitFormState
> {
state: RateLimitFormState = {
loading: false,
form: this.props.rateLimits,
};
constructor(props: RateLimitFormProps, context: any) {
@ -164,9 +162,9 @@ export default class RateLimitsForm extends Component<
<button
type="submit"
className="btn btn-secondary mr-2"
disabled={this.state.loading}
disabled={this.props.loading}
>
{this.state.loading ? (
{this.props.loading ? (
<Spinner />
) : (
capitalizeFirstLetter(i18n.t("save"))

View file

@ -73,6 +73,7 @@ export class Setup extends Component<any, State> {
onSaveSite={this.handleCreateSite}
siteRes={this.state.siteRes}
themeList={this.state.themeList}
loading={false}
/>
)}
</div>

View file

@ -12,7 +12,11 @@ import {
ListingType,
} from "lemmy-js-client";
import { i18n } from "../../i18next";
import { capitalizeFirstLetter, myAuthRequired } from "../../utils";
import {
capitalizeFirstLetter,
myAuthRequired,
validInstanceTLD,
} from "../../utils";
import { Icon, Spinner } from "../common/icon";
import { ImageUploadForm } from "../common/image-upload-form";
import { LanguageSelect } from "../common/language-select";
@ -27,11 +31,11 @@ interface SiteFormProps {
themeList?: string[];
onSaveSite(form: EditSite): void;
siteRes: GetSiteResponse;
loading: boolean;
}
interface SiteFormState {
siteForm: EditSite;
loading: boolean;
instance_select: {
allowed_instances: string;
blocked_instances: string;
@ -44,7 +48,6 @@ type InstanceKey = "allowed_instances" | "blocked_instances";
export class SiteForm extends Component<SiteFormProps, SiteFormState> {
state: SiteFormState = {
siteForm: this.initSiteForm(),
loading: false,
instance_select: {
allowed_instances: "",
blocked_instances: "",
@ -78,7 +81,6 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
slur_filter_regex: ls.slur_filter_regex,
actor_name_max_length: ls.actor_name_max_length,
federation_enabled: ls.federation_enabled,
federation_debug: ls.federation_debug,
federation_worker_count: ls.federation_worker_count,
captcha_enabled: ls.captcha_enabled,
captcha_difficulty: ls.captcha_difficulty,
@ -107,23 +109,21 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
this.handleDiscussionLanguageChange =
this.handleDiscussionLanguageChange.bind(this);
this.handleAddInstance = this.handleAddInstance.bind(this);
this.handleRemoveInstance = this.handleRemoveInstance.bind(this);
this.handleInstanceEnterPress = this.handleInstanceEnterPress.bind(this);
this.handleInstanceTextChange = this.handleInstanceTextChange.bind(this);
}
// Necessary to stop the loading
componentWillReceiveProps() {
this.setState({ loading: false });
}
render() {
const siteSetup = this.props.siteRes.site_view.local_site.site_setup;
return (
<form onSubmit={linkEvent(this, this.handleSaveSiteSubmit)}>
<NavigationPrompt
when={
!this.state.loading &&
!this.props.loading &&
!siteSetup &&
!!(
this.state.siteForm.name ||
@ -136,8 +136,8 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
/>
<h5>{`${
siteSetup
? capitalizeFirstLetter(i18n.t("save"))
: capitalizeFirstLetter(i18n.t("name"))
? capitalizeFirstLetter(i18n.t("edit"))
: capitalizeFirstLetter(i18n.t("setup"))
} ${i18n.t("your_site")}`}</h5>
<div className="form-group row">
<label className="col-12 col-form-label" htmlFor="create-site-name">
@ -157,7 +157,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
</div>
</div>
<div className="form-group">
<label>{i18n.t("icon")}</label>
<label className="mr-2">{i18n.t("icon")}</label>
<ImageUploadForm
uploadTitle={i18n.t("upload_icon")}
imageSrc={this.state.siteForm.icon}
@ -167,7 +167,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
/>
</div>
<div className="form-group">
<label>{i18n.t("banner")}</label>
<label className="mr-2">{i18n.t("banner")}</label>
<ImageUploadForm
uploadTitle={i18n.t("upload_banner")}
imageSrc={this.state.siteForm.banner}
@ -609,9 +609,9 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
<button
type="submit"
className="btn btn-secondary mr-2"
disabled={this.state.loading}
disabled={this.props.loading}
>
{this.state.loading ? (
{this.props.loading ? (
<Spinner />
) : siteSetup ? (
capitalizeFirstLetter(i18n.t("save"))
@ -717,7 +717,7 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
event.preventDefault();
const auth = myAuthRequired();
i.setState(s => ((s.siteForm.auth = auth), s));
i.setState({ loading: true, submitted: true });
i.setState({ submitted: true });
const stateSiteForm = i.state.siteForm;
@ -780,6 +780,11 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> {
handleAddInstance(key: InstanceKey) {
const instance = this.state.instance_select[key].trim();
if (!validInstanceTLD(instance)) {
return;
}
if (!this.state.siteForm[key]?.includes(instance)) {
this.setState(s => ({
...s,

View file

@ -12,7 +12,6 @@ interface SiteSidebarProps {
showLocal: boolean;
counts?: SiteAggregates;
admins?: PersonView[];
online?: number;
}
interface SiteSidebarState {
@ -99,15 +98,8 @@ export class SiteSidebar extends Component<SiteSidebarProps, SiteSidebarState> {
badges(siteAggregates: SiteAggregates) {
const counts = siteAggregates;
const online = this.props.online ?? 1;
return (
<ul className="my-2 list-inline">
<li className="list-inline-item badge badge-secondary">
{i18n.t("number_online", {
count: online,
formattedCount: numToSI(online),
})}
</li>
<li
className="list-inline-item badge badge-secondary pointer"
data-tippy-content={i18n.t("active_users_in_the_last_day", {

View file

@ -9,17 +9,16 @@ import { MarkdownTextArea } from "../common/markdown-textarea";
interface TaglineFormProps {
taglines: Array<Tagline>;
onSaveSite(form: EditSite): void;
loading: boolean;
}
interface TaglineFormState {
taglines: Array<string>;
loading: boolean;
editingRow?: number;
}
export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
state: TaglineFormState = {
loading: false,
editingRow: undefined,
taglines: this.props.taglines.map(x => x.content),
};
@ -30,10 +29,6 @@ export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
return i18n.t("taglines");
}
componentWillReceiveProps() {
this.setState({ loading: false });
}
render() {
return (
<div className="col-12">
@ -110,9 +105,9 @@ export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
<button
onClick={linkEvent(this, this.handleSaveClick)}
className="btn btn-secondary mr-2"
disabled={this.state.loading}
disabled={this.props.loading}
>
{this.state.loading ? (
{this.props.loading ? (
<Spinner />
) : (
capitalizeFirstLetter(i18n.t("save"))
@ -153,7 +148,6 @@ export class TaglineForm extends Component<TaglineFormProps, TaglineFormState> {
}
async handleSaveClick(i: TaglineForm) {
i.setState({ loading: true });
i.props.onSaveSite({
taglines: i.state.taglines,
auth: myAuthRequired(),

View file

@ -24,7 +24,6 @@ import {
fetchCommunities,
fetchThemeList,
fetchUsers,
getLanguages,
myAuth,
myAuthRequired,
personToChoice,
@ -1058,12 +1057,12 @@ export class Settings extends Component<any, SettingsState> {
}
handleInterfaceLangChange(i: Settings, event: any) {
const newLang = event.target.value ?? "browser";
i18n.changeLanguage(newLang === "browser" ? navigator.languages : newLang);
i.setState(
s => ((s.saveUserSettingsForm.interface_language = event.target.value), s)
);
i18n.changeLanguage(
getLanguages(i.state.saveUserSettingsForm.interface_language).at(0)
);
}
handleDiscussionLanguageChange(val: number[]) {

View file

@ -224,6 +224,10 @@ export class CreatePost extends Component<
if (res.state === "success") {
const postId = res.data.post_view.post.id;
this.props.history.replace(`/post/${postId}`);
} else {
this.setState({
loading: false,
});
}
}

View file

@ -552,7 +552,6 @@ export class Post extends Component<any, PostState> {
community_view={res.data.community_view}
moderators={res.data.moderators}
admins={this.state.siteRes.admins}
online={res.data.online}
enableNsfw={enableNsfw(this.state.siteRes)}
showIcon
allLanguages={this.state.siteRes.all_languages}
@ -729,19 +728,14 @@ export class Post extends Component<any, PostState> {
async handleBlockCommunity(form: BlockCommunity) {
const blockCommunityRes = await HttpService.client.blockCommunity(form);
// TODO Probably isn't necessary
this.setState(s => {
if (
s.postRes.state == "success" &&
blockCommunityRes.state == "success"
) {
s.postRes.data.community_view = blockCommunityRes.data.community_view;
}
return s;
});
if (blockCommunityRes.state == "success") {
updateCommunityBlock(blockCommunityRes.data);
this.setState(s => {
if (s.postRes.state == "success") {
s.postRes.data.community_view.blocked =
blockCommunityRes.data.blocked;
}
});
}
}