mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 20:31:13 +00:00
feat: Finish making block instance setting
This commit is contained in:
parent
2a43e248d9
commit
3e52203162
3 changed files with 104 additions and 4 deletions
|
@ -10,6 +10,7 @@ import {
|
||||||
setTheme,
|
setTheme,
|
||||||
showLocal,
|
showLocal,
|
||||||
updateCommunityBlock,
|
updateCommunityBlock,
|
||||||
|
updateInstanceBlock,
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
} from "@utils/app";
|
} from "@utils/app";
|
||||||
import { capitalizeFirstLetter, debounce } from "@utils/helpers";
|
import { capitalizeFirstLetter, debounce } from "@utils/helpers";
|
||||||
|
@ -19,6 +20,7 @@ import { NoOptionI18nKeys } from "i18next";
|
||||||
import { Component, linkEvent } from "inferno";
|
import { Component, linkEvent } from "inferno";
|
||||||
import {
|
import {
|
||||||
BlockCommunityResponse,
|
BlockCommunityResponse,
|
||||||
|
BlockInstanceResponse,
|
||||||
BlockPersonResponse,
|
BlockPersonResponse,
|
||||||
CommunityBlockView,
|
CommunityBlockView,
|
||||||
DeleteAccountResponse,
|
DeleteAccountResponse,
|
||||||
|
@ -187,6 +189,7 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
|
|
||||||
this.handleBlockPerson = this.handleBlockPerson.bind(this);
|
this.handleBlockPerson = this.handleBlockPerson.bind(this);
|
||||||
this.handleBlockCommunity = this.handleBlockCommunity.bind(this);
|
this.handleBlockCommunity = this.handleBlockCommunity.bind(this);
|
||||||
|
this.handleBlockInstance = this.handleBlockInstance.bind(this);
|
||||||
|
|
||||||
const mui = UserService.Instance.myUserInfo;
|
const mui = UserService.Instance.myUserInfo;
|
||||||
if (mui) {
|
if (mui) {
|
||||||
|
@ -340,7 +343,7 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 col-md-6">
|
<div className="col-12 col-md-6">
|
||||||
<div className="card border-secondary mb-3">
|
<div className="card border-secondary mb-3">
|
||||||
<div className="card-body">{this.blockCommunityCard()}</div>
|
<div className="card-body">{this.blockInstanceCard()}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -494,15 +497,43 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
<div>
|
<div>
|
||||||
<Filter
|
<Filter
|
||||||
filterType="instance"
|
filterType="instance"
|
||||||
onChange={this.handleBlockPerson}
|
onChange={this.handleBlockInstance}
|
||||||
onSearch={this.handlePersonSearch}
|
onSearch={this.handleInstanceSearch}
|
||||||
options={searchInstanceOptions}
|
options={searchInstanceOptions}
|
||||||
/>
|
/>
|
||||||
{this.blockedUsersList()}
|
{this.blockedInstancesList()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockedInstancesList() {
|
||||||
|
// TODO: Make translations
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h2 className="h5">{I18NextService.i18n.t("blocked_users")}</h2>
|
||||||
|
<ul className="list-unstyled mb-0">
|
||||||
|
{this.state.instanceBlocks.map(ib => (
|
||||||
|
<li key={ib.instance.id}>
|
||||||
|
<span>
|
||||||
|
{ib.instance.domain}
|
||||||
|
<button
|
||||||
|
className="btn btn-sm"
|
||||||
|
onClick={linkEvent(
|
||||||
|
{ ctx: this, instanceId: ib.instance.id },
|
||||||
|
this.handleUnblockInstance,
|
||||||
|
)}
|
||||||
|
data-tippy-content={I18NextService.i18n.t("unblock_user")}
|
||||||
|
>
|
||||||
|
<Icon icon="x" classes="icon-inline" />
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
saveUserSettingsHtmlForm() {
|
saveUserSettingsHtmlForm() {
|
||||||
const selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
|
const selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
|
||||||
|
|
||||||
|
@ -1096,6 +1127,31 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleBlockInstance({ value }: Choice) {
|
||||||
|
if (value !== "0") {
|
||||||
|
const id = Number(value);
|
||||||
|
const res = await HttpService.client.blockInstance({
|
||||||
|
block: true,
|
||||||
|
instance_id: id,
|
||||||
|
});
|
||||||
|
this.instanceBlock(id, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleUnblockInstance({
|
||||||
|
ctx,
|
||||||
|
instanceId,
|
||||||
|
}: {
|
||||||
|
ctx: Settings;
|
||||||
|
instanceId: number;
|
||||||
|
}) {
|
||||||
|
const res = await HttpService.client.blockInstance({
|
||||||
|
block: false,
|
||||||
|
instance_id: instanceId,
|
||||||
|
});
|
||||||
|
ctx.instanceBlock(instanceId, res);
|
||||||
|
}
|
||||||
|
|
||||||
handleShowNsfwChange(i: Settings, event: any) {
|
handleShowNsfwChange(i: Settings, event: any) {
|
||||||
i.setState(
|
i.setState(
|
||||||
s => ((s.saveUserSettingsForm.show_nsfw = event.target.checked), s),
|
s => ((s.saveUserSettingsForm.show_nsfw = event.target.checked), s),
|
||||||
|
@ -1380,4 +1436,19 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instanceBlock(id: number, res: RequestState<BlockInstanceResponse>) {
|
||||||
|
if (
|
||||||
|
res.state === "success" &&
|
||||||
|
this.state.instancesRes.state === "success"
|
||||||
|
) {
|
||||||
|
const linkedInstances =
|
||||||
|
this.state.instancesRes.data.federated_instances?.linked ?? [];
|
||||||
|
updateInstanceBlock(res.data, id, linkedInstances);
|
||||||
|
const mui = UserService.Instance.myUserInfo;
|
||||||
|
if (mui) {
|
||||||
|
this.setState({ instanceBlocks: mui.instance_blocks });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ import siteBannerCss from "./site-banner-css";
|
||||||
import updateCommunityBlock from "./update-community-block";
|
import updateCommunityBlock from "./update-community-block";
|
||||||
import updatePersonBlock from "./update-person-block";
|
import updatePersonBlock from "./update-person-block";
|
||||||
import instanceToChoice from "./instance-to-choice";
|
import instanceToChoice from "./instance-to-choice";
|
||||||
|
import updateInstanceBlock from "./update-instance-block";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
buildCommentsTree,
|
buildCommentsTree,
|
||||||
|
@ -110,4 +111,5 @@ export {
|
||||||
updateCommunityBlock,
|
updateCommunityBlock,
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
instanceToChoice,
|
instanceToChoice,
|
||||||
|
updateInstanceBlock,
|
||||||
};
|
};
|
||||||
|
|
27
src/shared/utils/app/update-instance-block.ts
Normal file
27
src/shared/utils/app/update-instance-block.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { BlockInstanceResponse, Instance, MyUserInfo } from "lemmy-js-client";
|
||||||
|
import { I18NextService, UserService } from "../../services";
|
||||||
|
import { toast } from "../../toast";
|
||||||
|
|
||||||
|
export default function updateInstanceBlock(
|
||||||
|
data: BlockInstanceResponse,
|
||||||
|
id: number,
|
||||||
|
linkedInstances: Instance[],
|
||||||
|
myUserInfo: MyUserInfo | undefined = UserService.Instance.myUserInfo,
|
||||||
|
) {
|
||||||
|
if (myUserInfo) {
|
||||||
|
const instance = linkedInstances.find(i => i.id === id)!;
|
||||||
|
|
||||||
|
if (data.blocked) {
|
||||||
|
myUserInfo.instance_blocks.push({
|
||||||
|
person: myUserInfo.local_user_view.person,
|
||||||
|
instance,
|
||||||
|
});
|
||||||
|
toast(`${I18NextService.i18n.t("blocked")} ${instance.domain}`);
|
||||||
|
} else {
|
||||||
|
myUserInfo.instance_blocks = myUserInfo.instance_blocks.filter(
|
||||||
|
i => i.instance.id !== id,
|
||||||
|
);
|
||||||
|
toast(`${I18NextService.i18n.t("unblocked")} ${instance.domain}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue