mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-23 23:58:06 +01:00
f6654e0842
Conflicts: - `app/javascript/packs/admin.jsx`: This file was split between `app/javascript/core/admin.js`, `app/javascript/pack/admin.jsx`, and `app/javascript/flavours/glitch/packs/admin.jsx`. Ported upstream's change, splitting the new file to `app/javascript/core/admin.ts`, `app/javascript/packs/admin.tsx`, and `app/javascript/flavours/glitch/packs/admin.tsx`
37 lines
953 B
TypeScript
37 lines
953 B
TypeScript
import './public-path';
|
|
import { createRoot } from 'react-dom/client';
|
|
|
|
import ready from '../mastodon/ready';
|
|
|
|
async function mountReactComponent(element: Element) {
|
|
const componentName = element.getAttribute('data-admin-component');
|
|
const stringProps = element.getAttribute('data-props');
|
|
|
|
if (!stringProps) return;
|
|
|
|
const componentProps = JSON.parse(stringProps) as object;
|
|
|
|
const { default: AdminComponent } = await import(
|
|
'@/mastodon/containers/admin_component'
|
|
);
|
|
|
|
const { default: Component } = (await import(
|
|
`@/mastodon/components/admin/${componentName}`
|
|
)) as { default: React.ComponentType };
|
|
|
|
const root = createRoot(element);
|
|
|
|
root.render(
|
|
<AdminComponent>
|
|
<Component {...componentProps} />
|
|
</AdminComponent>,
|
|
);
|
|
}
|
|
|
|
ready(() => {
|
|
document.querySelectorAll('[data-admin-component]').forEach((element) => {
|
|
void mountReactComponent(element);
|
|
});
|
|
}).catch((reason) => {
|
|
throw reason;
|
|
});
|