@@ -930,6 +909,86 @@ export class SiteForm extends Component
{
);
}
+ federatedInstanceSelect(key: InstanceKey) {
+ const id = `create_site_${key}`;
+ const value = this.state.instance_select[key];
+ const selectedInstances = this.state.siteForm[key];
+ return (
+
+
+
+
+
+
+ {selectedInstances && selectedInstances.length > 0 && (
+
+ {selectedInstances.map(instance => (
+ -
+
+
+
+ ))}
+
+ )}
+
+ );
+ }
+
+ handleInstanceTextChange(type: InstanceKey, event: any) {
+ this.setState(s => ({
+ ...s,
+ instance_select: {
+ ...s.instance_select,
+ [type]: event.target.value,
+ },
+ }));
+ }
+
+ handleInstanceEnterPress(
+ key: InstanceKey,
+ event: InfernoKeyboardEvent
+ ) {
+ if (event.code.toLowerCase() === "enter") {
+ event.preventDefault();
+
+ this.handleAddInstance(key);
+ }
+ }
+
handleCreateSiteSubmit(i: SiteForm, event: any) {
event.preventDefault();
i.setState({ loading: true });
@@ -986,18 +1045,43 @@ export class SiteForm extends Component {
i.setState(i.state);
}
- instancesToString(opt?: string[]): string {
- return opt ? opt.join(",") : "";
+ handleAddInstance(key: InstanceKey) {
+ const instance = this.state.instance_select[key].trim();
+ if (!this.state.siteForm[key]?.includes(instance)) {
+ this.setState(s => ({
+ ...s,
+ siteForm: {
+ ...s.siteForm,
+ [key]: [...(s.siteForm[key] ?? []), instance],
+ },
+ instance_select: {
+ ...s.instance_select,
+ [key]: "",
+ },
+ }));
+
+ const oppositeKey: InstanceKey =
+ key === "allowed_instances" ? "blocked_instances" : "allowed_instances";
+ if (this.state.siteForm[oppositeKey]?.includes(instance)) {
+ this.handleRemoveInstance({ key: oppositeKey, instance });
+ }
+ }
}
- handleSiteAllowedInstances(i: SiteForm, event: any) {
- let list = splitToList(event.target.value);
- i.setState(s => ((s.siteForm.allowed_instances = list), s));
- }
-
- handleSiteBlockedInstances(i: SiteForm, event: any) {
- let list = splitToList(event.target.value);
- i.setState(s => ((s.siteForm.blocked_instances = list), s));
+ handleRemoveInstance({
+ key,
+ instance,
+ }: {
+ key: InstanceKey;
+ instance: string;
+ }) {
+ this.setState(s => ({
+ ...s,
+ siteForm: {
+ ...s.siteForm,
+ [key]: s.siteForm[key]?.filter(i => i !== instance),
+ },
+ }));
}
handleSiteNameChange(i: SiteForm, event: any) {
@@ -1259,12 +1343,3 @@ export class SiteForm extends Component {
this.setState(s => ((s.siteForm.default_post_listing_type = val), s));
}
}
-
-function splitToList(commaList: string): string[] {
- if (commaList !== "") {
- let list = commaList.trim().split(",");
- return list;
- } else {
- return [];
- }
-}
diff --git a/webpack.config.js b/webpack.config.js
index ef5717fe..51ca81db 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -123,9 +123,12 @@ const createClientConfig = (_env, mode) => {
urlPattern: ({ url: { pathname, host }, sameOrigin }) =>
(sameOrigin || host.includes("localhost")) &&
pathname.includes("static"),
- handler: "CacheFirst",
+ handler: mode === "development" ? "NetworkFirst" : "CacheFirst",
options: {
cacheName: "static-cache",
+ expiration: {
+ maxAgeSeconds: 60 * 60 * 24,
+ },
},
},
{