mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-26 06:11:15 +00:00
Start modifying settings
This commit is contained in:
parent
d9fe7d1488
commit
2a43e248d9
3 changed files with 80 additions and 4 deletions
|
@ -3,6 +3,7 @@ import {
|
||||||
fetchCommunities,
|
fetchCommunities,
|
||||||
fetchThemeList,
|
fetchThemeList,
|
||||||
fetchUsers,
|
fetchUsers,
|
||||||
|
instanceToChoice,
|
||||||
myAuth,
|
myAuth,
|
||||||
personToChoice,
|
personToChoice,
|
||||||
setIsoData,
|
setIsoData,
|
||||||
|
@ -12,7 +13,7 @@ import {
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
} from "@utils/app";
|
} from "@utils/app";
|
||||||
import { capitalizeFirstLetter, debounce } from "@utils/helpers";
|
import { capitalizeFirstLetter, debounce } from "@utils/helpers";
|
||||||
import { Choice } from "@utils/types";
|
import { Choice, RouteDataResponse } from "@utils/types";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { NoOptionI18nKeys } from "i18next";
|
import { NoOptionI18nKeys } from "i18next";
|
||||||
import { Component, linkEvent } from "inferno";
|
import { Component, linkEvent } from "inferno";
|
||||||
|
@ -21,7 +22,10 @@ import {
|
||||||
BlockPersonResponse,
|
BlockPersonResponse,
|
||||||
CommunityBlockView,
|
CommunityBlockView,
|
||||||
DeleteAccountResponse,
|
DeleteAccountResponse,
|
||||||
|
GetFederatedInstancesResponse,
|
||||||
GetSiteResponse,
|
GetSiteResponse,
|
||||||
|
Instance,
|
||||||
|
InstanceBlockView,
|
||||||
ListingType,
|
ListingType,
|
||||||
LoginResponse,
|
LoginResponse,
|
||||||
PersonBlockView,
|
PersonBlockView,
|
||||||
|
@ -45,11 +49,17 @@ import { SortSelect } from "../common/sort-select";
|
||||||
import Tabs from "../common/tabs";
|
import Tabs from "../common/tabs";
|
||||||
import { CommunityLink } from "../community/community-link";
|
import { CommunityLink } from "../community/community-link";
|
||||||
import { PersonListing } from "./person-listing";
|
import { PersonListing } from "./person-listing";
|
||||||
|
import { InitialFetchRequest } from "shared/interfaces";
|
||||||
|
|
||||||
|
type SettingsData = RouteDataResponse<{
|
||||||
|
instancesRes: GetFederatedInstancesResponse;
|
||||||
|
}>;
|
||||||
|
|
||||||
interface SettingsState {
|
interface SettingsState {
|
||||||
saveRes: RequestState<LoginResponse>;
|
saveRes: RequestState<LoginResponse>;
|
||||||
changePasswordRes: RequestState<LoginResponse>;
|
changePasswordRes: RequestState<LoginResponse>;
|
||||||
deleteAccountRes: RequestState<DeleteAccountResponse>;
|
deleteAccountRes: RequestState<DeleteAccountResponse>;
|
||||||
|
instancesRes: RequestState<GetFederatedInstancesResponse>;
|
||||||
// TODO redo these forms
|
// TODO redo these forms
|
||||||
saveUserSettingsForm: {
|
saveUserSettingsForm: {
|
||||||
show_nsfw?: boolean;
|
show_nsfw?: boolean;
|
||||||
|
@ -86,6 +96,7 @@ interface SettingsState {
|
||||||
};
|
};
|
||||||
personBlocks: PersonBlockView[];
|
personBlocks: PersonBlockView[];
|
||||||
communityBlocks: CommunityBlockView[];
|
communityBlocks: CommunityBlockView[];
|
||||||
|
instanceBlocks: InstanceBlockView[];
|
||||||
currentTab: string;
|
currentTab: string;
|
||||||
themeList: string[];
|
themeList: string[];
|
||||||
deleteAccountShowConfirm: boolean;
|
deleteAccountShowConfirm: boolean;
|
||||||
|
@ -94,22 +105,23 @@ interface SettingsState {
|
||||||
searchCommunityOptions: Choice[];
|
searchCommunityOptions: Choice[];
|
||||||
searchPersonLoading: boolean;
|
searchPersonLoading: boolean;
|
||||||
searchPersonOptions: Choice[];
|
searchPersonOptions: Choice[];
|
||||||
|
searchInstanceOptions: Choice[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilterType = "user" | "community";
|
type FilterType = "user" | "community" | "instance";
|
||||||
|
|
||||||
const Filter = ({
|
const Filter = ({
|
||||||
filterType,
|
filterType,
|
||||||
options,
|
options,
|
||||||
onChange,
|
onChange,
|
||||||
onSearch,
|
onSearch,
|
||||||
loading,
|
loading = true,
|
||||||
}: {
|
}: {
|
||||||
filterType: FilterType;
|
filterType: FilterType;
|
||||||
options: Choice[];
|
options: Choice[];
|
||||||
onSearch: (text: string) => void;
|
onSearch: (text: string) => void;
|
||||||
onChange: (choice: Choice) => void;
|
onChange: (choice: Choice) => void;
|
||||||
loading: boolean;
|
loading?: boolean;
|
||||||
}) => (
|
}) => (
|
||||||
<div className="mb-3 row">
|
<div className="mb-3 row">
|
||||||
<label
|
<label
|
||||||
|
@ -138,12 +150,14 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
saveRes: { state: "empty" },
|
saveRes: { state: "empty" },
|
||||||
deleteAccountRes: { state: "empty" },
|
deleteAccountRes: { state: "empty" },
|
||||||
changePasswordRes: { state: "empty" },
|
changePasswordRes: { state: "empty" },
|
||||||
|
instancesRes: { state: "empty" },
|
||||||
saveUserSettingsForm: {},
|
saveUserSettingsForm: {},
|
||||||
changePasswordForm: {},
|
changePasswordForm: {},
|
||||||
deleteAccountShowConfirm: false,
|
deleteAccountShowConfirm: false,
|
||||||
deleteAccountForm: {},
|
deleteAccountForm: {},
|
||||||
personBlocks: [],
|
personBlocks: [],
|
||||||
communityBlocks: [],
|
communityBlocks: [],
|
||||||
|
instanceBlocks: [],
|
||||||
currentTab: "settings",
|
currentTab: "settings",
|
||||||
siteRes: this.isoData.site_res,
|
siteRes: this.isoData.site_res,
|
||||||
themeList: [],
|
themeList: [],
|
||||||
|
@ -151,6 +165,7 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
searchCommunityOptions: [],
|
searchCommunityOptions: [],
|
||||||
searchPersonLoading: false,
|
searchPersonLoading: false,
|
||||||
searchPersonOptions: [],
|
searchPersonOptions: [],
|
||||||
|
searchInstanceOptions: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
|
@ -234,6 +249,14 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async fetchInitialData({
|
||||||
|
client,
|
||||||
|
}: InitialFetchRequest): Promise<SettingsData> {
|
||||||
|
return {
|
||||||
|
instancesRes: await client.getFederatedInstances(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
setupTippy();
|
setupTippy();
|
||||||
this.setState({ themeList: await fetchThemeList() });
|
this.setState({ themeList: await fetchThemeList() });
|
||||||
|
@ -315,6 +338,11 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
<div className="card-body">{this.blockCommunityCard()}</div>
|
<div className="card-body">{this.blockCommunityCard()}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="col-12 col-md-6">
|
||||||
|
<div className="card border-secondary mb-3">
|
||||||
|
<div className="card-body">{this.blockCommunityCard()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -459,6 +487,22 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockInstanceCard() {
|
||||||
|
const { searchInstanceOptions } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Filter
|
||||||
|
filterType="instance"
|
||||||
|
onChange={this.handleBlockPerson}
|
||||||
|
onSearch={this.handlePersonSearch}
|
||||||
|
options={searchInstanceOptions}
|
||||||
|
/>
|
||||||
|
{this.blockedUsersList()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
saveUserSettingsHtmlForm() {
|
saveUserSettingsHtmlForm() {
|
||||||
const selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
|
const selectedLangs = this.state.saveUserSettingsForm.discussion_languages;
|
||||||
|
|
||||||
|
@ -987,6 +1031,27 @@ export class Settings extends Component<any, SettingsState> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handleInstanceSearch = debounce(async (text: string) => {
|
||||||
|
let searchInstanceOptions: Instance[] = [];
|
||||||
|
|
||||||
|
if (this.state.instancesRes.state === "success") {
|
||||||
|
searchInstanceOptions =
|
||||||
|
this.state.instancesRes.data.federated_instances?.linked.filter(
|
||||||
|
instance =>
|
||||||
|
instance.domain.toLowerCase().includes(text.toLowerCase()) ||
|
||||||
|
!this.state.instanceBlocks.some(
|
||||||
|
blockedIntance => blockedIntance.instance.id === instance.id,
|
||||||
|
),
|
||||||
|
) ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
searchInstanceOptions: searchInstanceOptions
|
||||||
|
.slice(0, 30)
|
||||||
|
.map(instanceToChoice),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
async handleBlockPerson({ value }: Choice) {
|
async handleBlockPerson({ value }: Choice) {
|
||||||
if (value !== "0") {
|
if (value !== "0") {
|
||||||
const res = await HttpService.client.blockPerson({
|
const res = await HttpService.client.blockPerson({
|
||||||
|
|
|
@ -52,6 +52,7 @@ import showScores from "./show-scores";
|
||||||
import siteBannerCss from "./site-banner-css";
|
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";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
buildCommentsTree,
|
buildCommentsTree,
|
||||||
|
@ -108,4 +109,5 @@ export {
|
||||||
siteBannerCss,
|
siteBannerCss,
|
||||||
updateCommunityBlock,
|
updateCommunityBlock,
|
||||||
updatePersonBlock,
|
updatePersonBlock,
|
||||||
|
instanceToChoice,
|
||||||
};
|
};
|
||||||
|
|
9
src/shared/utils/app/instance-to-choice.ts
Normal file
9
src/shared/utils/app/instance-to-choice.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { Choice } from "@utils/types";
|
||||||
|
import { Instance } from "lemmy-js-client";
|
||||||
|
|
||||||
|
export default function instanceToChoice({ id, domain }: Instance): Choice {
|
||||||
|
return {
|
||||||
|
value: id.toString(),
|
||||||
|
label: domain,
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue