fix the Addon installer and add openModalLazy to @vizality/modal

pull/91/head
bakzkndd 2 years ago
parent d407ab33f0
commit 34b281b717

@ -7,7 +7,7 @@ import fs, { stat, renameSync, readFileSync, existsSync, lstatSync, readdirSync
import { AddonInfoMessage, AddonUninstallModal } from '@vizality/components/addon';
import { removeDirRecursive } from '@vizality/util/file';
import { log, warn, error } from '@vizality/util/logger';
import { open as openModal } from '@vizality/modal';
import { openModalLazy as openModal } from '@vizality/modal';
import { isArray } from '@vizality/util/array';
import { Avatars, Events as _Events } from '@vizality/constants';
import http from 'isomorphic-git/http/node';
@ -565,6 +565,13 @@ export default class AddonManager extends Events {
git = `https://github.com/vizality-community/${addonId}`;
}
/**
* The addonId supplied might be a GitHub repository URL
*/
if (!git) {
git = addonId
}
/**
* The URL must end in git to get processed by isomorphic-git below.
*/
@ -635,7 +642,7 @@ export default class AddonManager extends Events {
vizality.api.notifications.sendToast({
id: 'addon-installed',
header: Messages.VIZALITY_ADDON_SUCCESSFULLY_INSTALLED.format({ type: toTitleCase(this.type) }),
content: <AddonInfoMessage addon={this.get(addonId)} message={Messages.VIZALITY_ADDON_SUCCESSFULLY_INSTALLED_DESC.format({ type: toTitleCase(this.type) })} />,
content: <AddonInfoMessage addon={this.get(addonId) || { manifest: { name: addonId }}} message={Messages.VIZALITY_ADDON_SUCCESSFULLY_INSTALLED_DESC.format({ type: toTitleCase(this.type) })} />,
icon: toTitleCase(this.type),
buttons: [
{
@ -920,7 +927,9 @@ export default class AddonManager extends Events {
if (!addon) {
return;
}
openModal(() => <AddonUninstallModal addon={addon} type={this.type} />);
if (!openModal) return this._error(`Can't find DeprecatedModal module within Discord`)
openModal(() => ModalArgs => <AddonUninstallModal {...ModalArgs} addon={addon} type={this.type} />);
} catch (err) {
return this._error(err);
}

@ -20,7 +20,7 @@ export default memo(({ addon, message, iconSize }) => {
<ul className='vz-addon-info-message-ul'>
<li className='vz-addon-info-message-li' vz-addon-id={addon?.addonId} key={addon?.addonId}>
<div className='vz-addon-info-message-icon'>
{addon && (
{addon?.manifest?.icon && (
<LazyImage
className='vz-addon-info-message-icon-image-wrapper'
imageClassName='vz-addon-info-message-icon-img'

@ -1,5 +1,4 @@
import { toTitleCase, toPlural } from '@vizality/util/string';
import { close as closeModal } from '@vizality/modal';
import { Messages } from '@vizality/i18n';
import { AddonInfoMessage } from '.';
import React, { memo } from 'react';
@ -12,15 +11,15 @@ import { Confirm } from '..';
* @param {object} props.addon Addon
* @param {string} props.type Addon type
*/
export default memo(({ addon, type }) => {
export default memo(({ onClose, addon, type }) => {
return (
<Confirm
header={Messages.VIZALITY_ADDON_UNINSTALL.format({ type: toTitleCase(type) })}
confirmText={Messages.VIZALITY_UNINSTALL}
cancelText={Messages.CANCEL}
onCancel={closeModal}
onCancel={onClose}
onConfirm={async () => {
closeModal();
onClose();
await vizality.manager[toPlural(type)]?._uninstall(addon.addonId);
}}
>

@ -7,7 +7,7 @@ import { getModule, modal } from '@vizality/webpack';
import { deprecate } from '@vizality/util/logger';
import React from 'react';
const { closeModal: closeNewModal, openModal: openNewModal } = getModule('openModal', 'openModalLazy');
const { closeModal: closeNewModal, openModal: openNewModal, openModalLazy: openLazy } = getModule('openModal', 'openModalLazy');
/**
* Opens a new modal.
@ -55,3 +55,9 @@ export const closeModal = closeNewModal;
* @param {React.Component|function(): React.ReactElement} Component Component to show
*/
export const openModal = openNewModal;
/**
* Opens a lazy modal (for LazyModal).
* @param {React.Component|function(): React.ReactElement} Component Component to show
*/
export const openModalLazy = openLazy
Loading…
Cancel
Save