Skip to content

Commit 4663266

Browse files
committed
Add interaction effect that reloads the detail page
1 parent bc18ce2 commit 4663266

15 files changed

Lines changed: 128 additions & 57 deletions

File tree

ts/WoltLabSuite/Core/Component/Interaction/FormBuilderDialog.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,65 @@
99

1010
import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog";
1111
import { showDefaultSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
12+
import { InteractionEffect } from "./InteractionEffect";
1213

1314
type Payload = Record<string, string>;
1415

15-
async function handleFormBuilderDialogAction(element: HTMLElement, endpoint: string, detail: Payload): Promise<void> {
16+
async function handleFormBuilderDialogAction(
17+
container: HTMLElement,
18+
element: HTMLElement,
19+
endpoint: string,
20+
interactionEffect: InteractionEffect = InteractionEffect.ReloadItem,
21+
detail: Payload,
22+
): Promise<void> {
1623
const { ok } = await dialogFactory().usingFormBuilder().fromEndpoint(endpoint);
1724

1825
if (!ok) {
1926
return;
2027
}
2128

22-
element.dispatchEvent(
23-
new CustomEvent<Payload>("interaction:invalidate", {
24-
bubbles: true,
25-
detail,
26-
}),
27-
);
29+
if (interactionEffect === InteractionEffect.ReloadItem || interactionEffect === InteractionEffect.ReloadPage) {
30+
element.dispatchEvent(
31+
new CustomEvent<Payload>("interaction:invalidate", {
32+
bubbles: true,
33+
detail: {
34+
...detail,
35+
_reloadPage: String(interactionEffect === InteractionEffect.ReloadPage),
36+
},
37+
}),
38+
);
39+
} else if (interactionEffect === InteractionEffect.ReloadList) {
40+
container.dispatchEvent(
41+
new CustomEvent<Payload>("interaction:invalidate-all", {
42+
detail: {
43+
...detail,
44+
},
45+
}),
46+
);
47+
} else {
48+
element.dispatchEvent(
49+
new CustomEvent<Payload>("interaction:remove", {
50+
bubbles: true,
51+
detail: {
52+
...detail,
53+
},
54+
}),
55+
);
56+
}
2857

2958
showDefaultSuccessSnackbar();
3059
}
3160

3261
export function setup(identifier: string, container: HTMLElement): void {
3362
container.addEventListener("interaction:execute", (event: CustomEvent<Payload>) => {
3463
if (event.detail.interaction === identifier) {
35-
void handleFormBuilderDialogAction(event.target as HTMLElement, event.detail.endpoint, event.detail);
64+
void handleFormBuilderDialogAction(
65+
container,
66+
event.target as HTMLElement,
67+
event.detail.endpoint,
68+
event.detail.interactionEffect as InteractionEffect,
69+
event.detail,
70+
);
3671
}
3772
});
3873
}

ts/WoltLabSuite/Core/Component/Interaction/InteractionEffect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
export enum InteractionEffect {
1111
ReloadItem = "ReloadItem",
1212
ReloadList = "ReloadList",
13+
ReloadPage = "ReloadPage",
1314
RemoveItem = "RemoveItem",
1415
}

ts/WoltLabSuite/Core/Component/Interaction/LegacyDboAction.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ async function handleDboAction(
3737
.payload(confirmationResult.reason ? { reason: confirmationResult.reason } : {})
3838
.dispatch();
3939

40-
if (interactionEffect === InteractionEffect.ReloadItem) {
40+
if (interactionEffect === InteractionEffect.ReloadItem || interactionEffect === InteractionEffect.ReloadPage) {
4141
element.dispatchEvent(
4242
new CustomEvent<Payload>("interaction:invalidate", {
4343
bubbles: true,
44-
detail,
44+
detail: {
45+
...detail,
46+
_reloadPage: String(interactionEffect === InteractionEffect.ReloadPage),
47+
},
4548
}),
4649
);
4750
} else if (interactionEffect === InteractionEffect.ReloadList) {

ts/WoltLabSuite/Core/Component/Interaction/Rpc.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ async function handleRpcInteraction(
4646
}
4747
}
4848

49-
if (interactionEffect === InteractionEffect.ReloadItem) {
49+
if (interactionEffect === InteractionEffect.ReloadItem || interactionEffect === InteractionEffect.ReloadPage) {
5050
element.dispatchEvent(
5151
new CustomEvent<Payload>("interaction:invalidate", {
5252
bubbles: true,
53-
detail,
53+
detail: {
54+
...detail,
55+
_reloadPage: String(interactionEffect === InteractionEffect.ReloadPage),
56+
},
5457
}),
5558
);
5659
} else if (interactionEffect === InteractionEffect.ReloadList) {

ts/WoltLabSuite/Core/Component/Interaction/StandaloneButton.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface HeaderContent {
1515
template: string;
1616
}
1717

18+
type Payload = Record<string, string>;
19+
1820
export class StandaloneButton {
1921
#container: HTMLElement;
2022
#providerClassName: string;
@@ -100,9 +102,15 @@ export class StandaloneButton {
100102
}
101103

102104
#initEventListeners(): void {
103-
this.#container.addEventListener("interaction:invalidate", () => {
104-
void this.#refreshContextMenu();
105-
void this.#refreshHeader();
105+
this.#container.addEventListener("interaction:invalidate", (event: CustomEvent<Payload>) => {
106+
if (event.detail._reloadPage === "true") {
107+
setTimeout(() => {
108+
window.location.reload();
109+
}, 2000);
110+
} else {
111+
void this.#refreshContextMenu();
112+
void this.#refreshHeader();
113+
}
106114
});
107115

108116
this.#container.addEventListener("interaction:invalidate-all", () => {
@@ -111,7 +119,9 @@ export class StandaloneButton {
111119
});
112120

113121
this.#container.addEventListener("interaction:remove", () => {
114-
window.location.href = this.#redirectUrl;
122+
setTimeout(() => {
123+
window.location.href = this.#redirectUrl;
124+
}, 2000);
115125
});
116126
}
117127
}

wcfsetup/install/files/acp/templates/articleAdd.tpl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@
1010
{if $action == 'edit'}
1111
<li>
1212
{unsafe:$interactionContextMenu->render()}
13-
<script data-relocate="true">
14-
{
15-
document.getElementById('{unsafe:$interactionContextMenu->getContainerID()|encodeJS}').addEventListener('interaction:invalidate', (event) => {
16-
if (event.detail.interaction === 'toggle-i18n') {
17-
setTimeout(() => {
18-
window.location.reload();
19-
}, 2000);
20-
}
21-
});
22-
}
23-
</script>
2413
</li>
2514
{/if}
2615

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/FormBuilderDialog.js

Lines changed: 27 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/InteractionEffect.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/LegacyDboAction.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Rpc.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)