You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/web/src/init.tsx

43 lines
911 B
TypeScript

import { message, Modal } from 'antd';
import {
buildStorage,
setAlert,
setServiceUrl,
setStorage,
setToasts,
setTokenGetter,
} from 'pawchat-shared';
import { getUserJWT } from './utils/jwt-helper';
const webStorage = buildStorage(window.localStorage);
setStorage(() => webStorage);
setTokenGetter(async () => {
return await getUserJWT();
});
if (window.localStorage.getItem('serviceUrl')) {
setServiceUrl(() => String(window.localStorage.getItem('serviceUrl')));
} else if (process.env.SERVICE_URL) {
setServiceUrl(() => String(process.env.SERVICE_URL));
}
setToasts((msg, type = 'info') => {
message.open({
type,
duration: 30000,
content: String(msg),
});
});
setAlert((options) => {
Modal.confirm({
content: options.message,
onOk: async () => {
if (typeof options.onConfirm === 'function') {
await options.onConfirm();
}
},
});
});