Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/remix-ide/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import Terminal from './app/panels/terminal'
import TabProxy from './app/panels/tab-proxy.js'
import { Plugin } from '@remixproject/engine'
import BottomBarPanel from './app/components/bottom-bar-panel'
import { TemplateExplorerModalPlugin } from './app/plugins/remix-template-explorer-modal'

const _paq = (window._paq = window._paq || [])

Expand Down Expand Up @@ -157,6 +158,7 @@ class AppComponent {
popupPanel: PopupPanel
statusBar: StatusBar
topBar: Topbar
templateExplorerModal: TemplateExplorerModalPlugin
settings: SettingsTab
params: any
desktopClientMode: boolean
Expand Down Expand Up @@ -267,6 +269,7 @@ class AppComponent {
this.gistHandler = new GistHandler()
// ----------------- theme service ---------------------------------
this.themeModule = new ThemeModule()
this.templateExplorerModal = new TemplateExplorerModalPlugin(this.themeModule)
// ----------------- locale service ---------------------------------
this.localeModule = new LocaleModule()
Registry.getInstance().put({ api: this.themeModule, name: 'themeModule' })
Expand Down Expand Up @@ -401,6 +404,8 @@ class AppComponent {

const templateSelection = new TemplatesSelectionPlugin()

const templateExplorerModal = this.templateExplorerModal

const walletConnect = new WalletConnect()

this.engine.register([
Expand Down Expand Up @@ -459,6 +464,7 @@ class AppComponent {
scriptRunnerUI,
remixAI,
remixAiAssistant,
templateExplorerModal,
walletConnect
])

Expand Down Expand Up @@ -611,6 +617,7 @@ class AppComponent {
await this.appManager.activatePlugin(['mainPanel', 'menuicons', 'tabs'])
await this.appManager.activatePlugin(['topbar'])
await this.appManager.activatePlugin(['statusBar'])
// await this.appManager.activatePlugin(['remix-template-explorer-modal'])
await this.appManager.activatePlugin(['bottomBar'])
await this.appManager.activatePlugin(['sidePanel']) // activating host plugin separately
await this.appManager.activatePlugin(['pinnedPanel'])
Expand Down
2 changes: 2 additions & 0 deletions apps/remix-ide/src/app/plugins/notification.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @nrwl/nx/enforce-module-boundaries */
import { Plugin } from '@remixproject/engine'
import { LibraryProfile, MethodApi, StatusEvents } from '@remixproject/plugin-utils'
import { AppModal } from '@remix-ui/app'
Expand All @@ -10,6 +11,7 @@ interface INotificationApi {
modal: (args: AppModal) => void
alert: (args: AlertModal) => void
toast: (message: string) => void

}
}

Expand Down
70 changes: 70 additions & 0 deletions apps/remix-ide/src/app/plugins/remix-template-explorer-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable @nrwl/nx/enforce-module-boundaries */
import React from 'react'
import { AppAction, AppState } from '@remix-ui/app'
import { PluginViewWrapper } from '@remix-ui/helper'
import { Plugin } from '@remixproject/engine'
import { EventEmitter } from 'events'
import { ThemeModule } from '../tabs/theme-module'
import { TemplateExplorerProvider } from 'libs/remix-ui/template-explorer-modal/context/template-explorer-context'

const pluginProfile = {
name: 'remix-template-explorer-modal',
displayName: 'Remix Generic Modal',
description: 'Remix Generic Modal for every type of content meant for a modal',
methods: ['openModal']
}

export class TemplateExplorerModalPlugin extends Plugin {
element: HTMLDivElement
dispatch: React.Dispatch<any> = () => { }
event: any
appStateDispatch: any
theme: any = null
constructor(theme: ThemeModule) {
super(pluginProfile)
this.element = document.createElement('div')
this.element.setAttribute('id', 'template-explorer-modal')
this.dispatch = () => { }
this.event = new EventEmitter()
this.theme = theme
}

async onActivation(): Promise<void> {
this.on('theme', 'themeChanged', (theme: any) => {
this.theme = theme
})
}

onDeactivation(): void {
this.element.remove()
}

setDispatch(dispatch: React.Dispatch<any>) {
this.dispatch = dispatch
this.renderComponent()
}

setAppStateDispatch(appStateDispatch: React.Dispatch<AppAction>) {
this.appStateDispatch = appStateDispatch
}

render() {
return (
<div id="inner-remix-template-explorer-modal">
<PluginViewWrapper plugin={this} useAppContext={true} />
</div>
)
}

renderComponent(): void {
this.dispatch({
plugins: this,
})
}

updateComponent() {
return (
<TemplateExplorerProvider plugin={this} />
)
}
}
2 changes: 1 addition & 1 deletion apps/remix-ide/src/app/plugins/remixGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class RemixGuidePlugin extends ViewPlugin {
>
{ section.cells.map((cell, index) => {
return <RemixUIGridCell
plugin={this}
// plugin={this}
title={cell.title}
titleTooltip={cell.titleTooltip}
tagList={cell.tagList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class TemplatesSelectionPlugin extends ViewPlugin {
if (!item.opts) {
return (
<RemixUIGridCell
plugin={this}
// plugin={this}
title={item.displayName}
key={item.name || index}
id={item.name}
Expand Down Expand Up @@ -353,7 +353,7 @@ export class TemplatesSelectionPlugin extends ViewPlugin {
}
})}
{template.name === 'Cookbook' && <RemixUIGridCell
plugin={this}
// plugin={this}
title={"More from Cookbook"}
key={"cookbookMore"}
id={"cookBookMore"}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion apps/remix-ide/src/remixAppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ let requiredModules = [
'remixAID',
'remixaiassistant',
'topbar',
'remix-template-explorer-modal',
'githubAuthHandler',
'desktopClient'
]
Expand Down Expand Up @@ -162,7 +163,8 @@ export function isNative(name) {
'desktopClient',
'LearnEth',
'noir-compiler',
'remixaiassistant'
'remixaiassistant',
'remix-template-explorer-modal'
]
return nativePlugins.includes(name) || requiredModules.includes(name) || isInjectedProvider(name) || isVM(name) || isScriptRunner(name)
}
Expand Down
5 changes: 4 additions & 1 deletion libs/remix-ui/app/src/lib/remix-app/actions/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { branch, desktopConnection, GitHubUser } from '@remix-api';
import { GenericModal } from '../interface';

type ActionMap<M extends { [index: string]: any }> = {
[Key in keyof M]: M[Key] extends undefined
Expand All @@ -18,6 +19,7 @@ export const enum appActionTypes {
setCanUseGit = 'SET_CAN_USE_GIT',
setShowPopupPanel = 'SET_SHOW_POPUP_PANEL',
setConnectedToDesktop = 'SET_CONNECTED_TO_DESKTOP',
showGenericModal = 'SHOW_GENERIC_MODAL',
}

type AppPayload = {
Expand All @@ -26,7 +28,8 @@ type AppPayload = {
[appActionTypes.setNeedsGitInit]: boolean,
[appActionTypes.setCanUseGit]: boolean,
[appActionTypes.setShowPopupPanel]: boolean,
[appActionTypes.setConnectedToDesktop]: desktopConnection
[appActionTypes.setConnectedToDesktop]: desktopConnection,
[appActionTypes.showGenericModal]: boolean
}

export type AppAction = ActionMap<AppPayload>[keyof ActionMap<
Expand Down
8 changes: 5 additions & 3 deletions libs/remix-ui/app/src/lib/remix-app/actions/modals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppModal } from '../interface'
import { AppModal, GenericModal } from '../interface'

type ActionMap<M extends { [index: string]: any }> = {
[Key in keyof M]: M[Key] extends undefined
Expand All @@ -16,15 +16,17 @@ export const enum modalActionTypes {
setToast = 'SET_TOAST',
processQueue = 'PROCESS_QUEUEU',
handleHideModal = 'HANDLE_HIDE_MODAL',
handleToaster = 'HANDLE_HIDE_TOAST'
handleToaster = 'HANDLE_HIDE_TOAST',
setTemplateExplorer = 'SET_TEMPLATE_EXPLORER'
}

type ModalPayload = {
[modalActionTypes.setModal]: AppModal
[modalActionTypes.handleHideModal]: any
[modalActionTypes.setToast]: { message: string | JSX.Element, timestamp: number }
[modalActionTypes.handleToaster]: any,
[modalActionTypes.processQueue]: any
[modalActionTypes.processQueue]: any,
[modalActionTypes.setTemplateExplorer]: GenericModal
}

export type ModalAction = ActionMap<ModalPayload>[keyof ActionMap<
Expand Down
15 changes: 12 additions & 3 deletions libs/remix-ui/app/src/lib/remix-app/context/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { modalReducer } from '../reducer/modals'
import { ModalInitialState } from '../state/modals'
import { ModalTypes } from '../types'
import { AppContext, dispatchModalContext, modalContext, platformContext, onLineContext } from './context'

declare global {
interface Window {
_intl: IntlShape
}
}

export const ModalProvider = ({ children = [], reducer = modalReducer, initialState = ModalInitialState } = {}) => {
const [{ modals, toasters, focusModal, focusToaster }, dispatch] = useReducer(reducer, initialState)
const [{ modals, toasters, focusModal, focusToaster, focusTemplateExplorer }, dispatch] = useReducer(reducer, initialState)

const onNextFn = async () => {
dispatch({
Expand Down Expand Up @@ -86,7 +85,9 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt

return (
<dispatchModalContext.Provider value={{ modal, toast, alert, handleHideModal, handleToaster }}>
<modalContext.Provider value={{ modals, toasters, focusModal, focusToaster }}>{children}</modalContext.Provider>
<modalContext.Provider value={{ modals, toasters, focusModal, focusToaster, focusTemplateExplorer }}>
{children}
</modalContext.Provider>
</dispatchModalContext.Provider>
)
}
Expand All @@ -109,3 +110,11 @@ export const useDialogs = () => {
export const useDialogDispatchers = () => {
return React.useContext(dispatchModalContext)
}

export const defaultFocusTemplateExplorer = () => {
return (
<>
<p className="fs-3 text-center">Template Explorer</p>
</>
)
}
47 changes: 46 additions & 1 deletion libs/remix-ui/app/src/lib/remix-app/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable @nrwl/nx/enforce-module-boundaries */
import { branch, desktopConnection, GitHubUser } from '@remix-api'
import { AppModalCancelTypes, ModalTypes } from '../types'
import { Template, TemplateGroup, TemplateOption } from 'libs/remix-ui/workspace/src/lib/utils/constants'

export type ValidationResult = {
valid: boolean,
Expand Down Expand Up @@ -40,7 +42,8 @@ export interface ModalState {
modals: AppModal[],
toasters: {message: (string | JSX.Element), timestamp: number }[],
focusModal: AppModal,
focusToaster: {message: (string | JSX.Element), timestamp: number }
focusToaster: {message: (string | JSX.Element), timestamp: number },
focusTemplateExplorer: GenericModal
}

export interface forceChoiceModal {
Expand All @@ -49,6 +52,47 @@ export interface forceChoiceModal {
message: string | JSX.Element,
}

export interface TemplateExplorerGenericData {
workspaceName: string,
modifyWorkspaceName: boolean,
workspaceDescription: string,
workspaceTemplateOptions: TemplateOption,
workspaceTemplateGroup: TemplateGroup,
workspaceTemplate: Template,
workspaceTags: string[]
searchTerm?: string
modifyWorkspace?: boolean
}

export interface GenericModal {
id: string
title?: JSX.Element,
message: JSX.Element,
footer?: JSX.Element,
genericData?: any,
timestamp?: number
hide?: boolean
showModal?: boolean
validationFn?: (value: string) => ValidationResult
// eslint-disable-next-line no-undef
okLabel: string | JSX.Element
okFn?: (value?:any) => void
cancelLabel?: string | JSX.Element
cancelFn?: (reason?: AppModalCancelTypes) => void,
modalType?: ModalTypes,
modalParentClass?: string
defaultValue?: string
hideFn?: () => void,
resolve?: (value?:any) => void,
next?: () => void,
data?: any,
showCancelIcon?: boolean,
preventBlur?: boolean
placeholderText?: string
width?: string
height?: string
}

export interface AppState {
gitHubUser: GitHubUser
currentBranch: branch
Expand All @@ -57,5 +101,6 @@ export interface AppState {
showPopupPanel: boolean
connectedToDesktop: desktopConnection
desktopClientConnected: desktopConnection
genericModalState?: GenericModal
}

9 changes: 8 additions & 1 deletion libs/remix-ui/app/src/lib/remix-app/reducer/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@ export const appReducer = (state: AppState, action: AppAction): AppState => {
connectedToDesktop: action.payload
}
}

case appActionTypes.showGenericModal: {
return {
...state,
genericModalState: { ...state.genericModalState, showModal: action.payload }
}
}
}
}
}
4 changes: 4 additions & 0 deletions libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda
return { ...state, toasters: []}
}
}

case modalActionTypes.setTemplateExplorer: {
return { ...state, focusTemplateExplorer: action.payload }
}
}
}
Loading