mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 00:38:27 +00:00
Merge commit '958a810553aac6b6cf21d9d107a47b6f68b2a401' into glitch-soc/merge-upstream
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`
This commit is contained in:
37
app/javascript/packs/admin.tsx
Normal file
37
app/javascript/packs/admin.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
});
|
||||
Reference in New Issue
Block a user