From c4f12804bb7014cd169e9b0d004d8dc1b9320c62 Mon Sep 17 00:00:00 2001 From: lianahus Date: Mon, 26 Sep 2022 18:51:11 +0200 Subject: [PATCH] Title section, File section, Learn section for Hoe tab --- .../src/app/ui/landing-page/landing-page.js | 6 +- .../src/lib/components/homeTabFile.tsx | 161 ++++++++++++++ .../src/lib/components/homeTabLearn.tsx | 56 +++++ .../src/lib/components/homeTabTitle.tsx | 101 +++++++++ .../home-tab/src/lib/remix-ui-home-tab.css | 2 +- .../home-tab/src/lib/remix-ui-home-tab.tsx | 204 ++++-------------- 6 files changed, 362 insertions(+), 168 deletions(-) create mode 100644 libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx create mode 100644 libs/remix-ui/home-tab/src/lib/components/homeTabLearn.tsx create mode 100644 libs/remix-ui/home-tab/src/lib/components/homeTabTitle.tsx diff --git a/apps/remix-ide/src/app/ui/landing-page/landing-page.js b/apps/remix-ide/src/app/ui/landing-page/landing-page.js index 978c4fdb1c..90511dd1d4 100644 --- a/apps/remix-ide/src/app/ui/landing-page/landing-page.js +++ b/apps/remix-ide/src/app/ui/landing-page/landing-page.js @@ -30,9 +30,9 @@ export class LandingPage extends ViewPlugin { } render () { - return
+ return
+ +
} } diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx new file mode 100644 index 0000000000..4b6609c613 --- /dev/null +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx @@ -0,0 +1,161 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import React, { useState, useRef, useReducer } from 'react' +import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line +import { Toaster } from '@remix-ui/toaster' // eslint-disable-line + +interface HomeTabFileProps { + plugin: any +} + +const loadingInitialState = { + tooltip: '', + showModalDialog: false, + importSource: '' +} + +const loadingReducer = (state = loadingInitialState, action) => { + return { ...state, tooltip: action.tooltip, showModalDialog: false, importSource: '' } +} + +function HomeTabFile ({plugin}: HomeTabFileProps) { + const [state, setState] = useState<{ + searchInput: string, + showModalDialog: boolean, + modalInfo: { title: string, loadItem: string, examples: Array }, + importSource: string, + toasterMsg: string + }>({ + searchInput: '', + showModalDialog: false, + modalInfo: { title: '', loadItem: '', examples: [] }, + importSource: '', + toasterMsg: '' + }) + + const [, dispatch] = useReducer(loadingReducer, loadingInitialState) + + const inputValue = useRef(null) + + const processLoading = () => { + const contentImport = plugin.contentImport + const workspace = plugin.fileManager.getProvider('workspace') + contentImport.import( + state.importSource, + (loadingMsg) => dispatch({ tooltip: loadingMsg }), + async (error, content, cleanUrl, type, url) => { + if (error) { + toast(error.message || error) + } else { + try { + if (await workspace.exists(type + '/' + cleanUrl)) toast('File already exists in workspace') + else { + workspace.addExternal(cleanUrl, content, url) + plugin.call('menuicons', 'select', 'filePanel') + } + } catch (e) { + toast(e.message) + } + } + } + ) + setState(prevState => { + return { ...prevState, showModalDialog: false, importSource: '' } + }) + } + + const toast = (message: string) => { + setState(prevState => { + return { ...prevState, toasterMsg: message } + }) + } + + const createNewFile = async () => { + plugin.verticalIcons.select('filePanel') + await plugin.call('filePanel', 'createNewFile') + } + + const uploadFile = async (target) => { + await plugin.call('filePanel', 'uploadFile', target) + } + + const connectToLocalhost = () => { + plugin.appManager.activatePlugin('remixd') + } + const importFromGist = () => { + plugin.call('gistHandler', 'load', '') + plugin.verticalIcons.select('filePanel') + } + + const showFullMessage = (title: string, loadItem: string, examples: Array) => { + setState(prevState => { + return { ...prevState, showModalDialog: true, modalInfo: { title: title, loadItem: loadItem, examples: examples } } + }) + } + + const hideFullMessage = () => { //eslint-disable-line + setState(prevState => { + return { ...prevState, showModalDialog: false, importSource: '' } + }) + } + + const examples = state.modalInfo.examples.map((urlEl, key) => (
{urlEl}
)) + + return ( + <> + hideFullMessage() } + okFn={ () => processLoading() } + > +
+ { state.modalInfo.loadItem !== '' && Enter the { state.modalInfo.loadItem } you would like to load. } + { state.modalInfo.examples.length !== 0 && + <> +
e.g
+
+ { examples } +
+ } + { + setState(prevState => { + return { ...prevState, importSource: inputValue.current.value } + }) + }} + /> +
+
+ +
+ + + + { + event.stopPropagation() + plugin.verticalIcons.select('filePanel') + uploadFile(event.target) + }} multiple /> + + +
+ + + + +
+
+ + ) +} + +export default HomeTabFile \ No newline at end of file diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabLearn.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabLearn.tsx new file mode 100644 index 0000000000..d53d103cfe --- /dev/null +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabLearn.tsx @@ -0,0 +1,56 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import React, { useEffect, useState, useContext } from 'react' +import { ThemeContext } from '../themeContext' + +enum VisibleTutorial { + Basics, + Intermediate, + Advanced +} + +function HomeTabLearn () { + const [state, setState] = useState<{ + visibleTutorial: VisibleTutorial + }>({ + visibleTutorial: VisibleTutorial.Basics + }) + + const themeFilter = useContext(ThemeContext) + + const openLink = () => { + window.open("https://remix-ide.readthedocs.io/en/latest/search.html?q=learneth&check_keywords=yes&area=default", '_blank') + } + + return ( +
+
+ + +
+
+ + + +
+
+
+ ) +} + +export default HomeTabLearn \ No newline at end of file diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabTitle.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabTitle.tsx new file mode 100644 index 0000000000..a53e4c4329 --- /dev/null +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabTitle.tsx @@ -0,0 +1,101 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import React, { useEffect, useState, useRef } from 'react' + +function HomeTabTitle () { + const [state, setState] = useState<{ + searchInput: string + }>({ + searchInput: '' + }) + useEffect(() => { + + document.addEventListener("keyup", (e) => handleSearchKeyDown(e)) + + return () => { + document.removeEventListener("keyup", handleSearchKeyDown) + } + }, []) + + const searchInputRef = useRef(null) + const remiAudioEl = useRef(null) + + const playRemi = async () => { + remiAudioEl.current.play() + } + const handleSearchKeyDown = (e: KeyboardEvent) => { + if (e.target !== searchInputRef.current) return + if (e.key === "Enter") { + openLink() + setState(prevState => { + return { ...prevState, searchInput: '' } + }) + searchInputRef.current.value = "" + } + } + + const openLink = (url = "") => { + if (url === "") { + window.open("https://remix-ide.readthedocs.io/en/latest/search.html?q=" + state.searchInput + "&check_keywords=yes&area=default", '_blank') + } else { + window.open(url, '_blank') + } + } + + return ( +
+
+ playRemi() } alt=""> + +
+
+ Remix + + + + +
+ The Native IDE for Solidity Development. + +
+ { + setState(prevState => { + return { ...prevState, searchInput: event.target.value.trim() } + }) + }} + type="text" + className="border form-control border-right-0" + id="searchInput" + placeholder="Search Documentation" + data-id="terminalInputSearch" + /> + +
+
+ ) +} + +export default HomeTabTitle diff --git a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.css b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.css index 4464c8d2fa..5a780e8600 100644 --- a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.css +++ b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.css @@ -31,7 +31,7 @@ text-align: center; } .remixui_home_logoImg { - height: 10em; + height: 4rem; } .remixui_home_rightPanel { right: 0; diff --git a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx index 2914b9ee69..c3f56d458d 100644 --- a/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx +++ b/libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx @@ -1,11 +1,14 @@ import React, { useState, useRef, useEffect, useReducer } from 'react' // eslint-disable-line import './remix-ui-home-tab.css' -import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line -import { Toaster } from '@remix-ui/toaster' // eslint-disable-line import PluginButton from './components/pluginButton' // eslint-disable-line import { ThemeContext, themes } from './themeContext' import { RSSFeed } from './components/rssFeed' +import BasicLogo from 'libs/remix-ui/vertical-icons-panel/src/lib/components/BasicLogo' +import HomeTabTitle from './components/homeTabTitle' +import HomeTabFile from './components/homeTabFile' +import HomeTabLearn from './components/homeTabLearn' + declare global { interface Window { _paq: any @@ -18,71 +21,17 @@ export interface RemixUiHomeTabProps { plugin: any } -const loadingInitialState = { - tooltip: '', - showModalDialog: false, - importSource: '' -} - -const loadingReducer = (state = loadingInitialState, action) => { - return { ...state, tooltip: action.tooltip, showModalDialog: false, importSource: '' } -} - export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { const { plugin } = props - const fileManager = plugin.fileManager const [state, setState] = useState<{ themeQuality: { filter: string, name: string }, - showMediaPanel: 'none' | 'twitter' | 'medium', - showModalDialog: boolean, - modalInfo: { title: string, loadItem: string, examples: Array }, - importSource: string, - toasterMsg: string + showMediaPanel: 'none' | 'twitter' | 'medium' }>({ themeQuality: themes.light, - showMediaPanel: 'none', - showModalDialog: false, - modalInfo: { title: '', loadItem: '', examples: [] }, - importSource: '', - toasterMsg: '' + showMediaPanel: 'none' }) - const processLoading = () => { - const contentImport = plugin.contentImport - const workspace = fileManager.getProvider('workspace') - contentImport.import( - state.importSource, - (loadingMsg) => dispatch({ tooltip: loadingMsg }), - async (error, content, cleanUrl, type, url) => { - if (error) { - toast(error.message || error) - } else { - try { - if (await workspace.exists(type + '/' + cleanUrl)) toast('File already exists in workspace') - else { - workspace.addExternal(type + '/' + cleanUrl, content, url) - plugin.call('menuicons', 'select', 'filePanel') - } - } catch (e) { - toast(e.message) - } - } - } - ) - setState(prevState => { - return { ...prevState, showModalDialog: false, importSource: '' } - }) - } - - const [, dispatch] = useReducer(loadingReducer, loadingInitialState) - - const playRemi = async () => { - remiAudioEl.current.play() - } - - const remiAudioEl = useRef(null) - const inputValue = useRef(null) const rightPanel = useRef(null) useEffect(() => { @@ -101,7 +50,7 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { window.addEventListener('click', (event) => { const target = event.target as Element const id = target.id - if (id !== 'remixIDEHomeTwitterbtn' && id !== 'remixIDEHomeMediumbtn' && !rightPanel.current.contains(event.target)) { + if (id !== 'remixIDEHomeTwitterbtn' && id !== 'remixIDEHomeMediumbtn' && (rightPanel && rightPanel.current && !rightPanel.current.contains(event.target))) { // todo check event.target setState(prevState => { return { ...prevState, showMediaPanel: 'none' } }) } @@ -111,33 +60,13 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { scriptTwitter.src = 'https://platform.twitter.com/widgets.js' scriptTwitter.async = true document.body.appendChild(scriptTwitter) + return () => { document.body.removeChild(scriptTwitter) } }, []) - const toast = (message: string) => { - setState(prevState => { - return { ...prevState, toasterMsg: message } - }) - } - - const createNewFile = async () => { - plugin.verticalIcons.select('filePanel') - await plugin.call('filePanel', 'createNewFile') - } - - const uploadFile = async (target) => { - await plugin.call('filePanel', 'uploadFile', target) - } - - const connectToLocalhost = () => { - plugin.appManager.activatePlugin('remixd') - } - const importFromGist = () => { - plugin.call('gistHandler', 'load', '') - plugin.verticalIcons.select('filePanel') - } + const startSolidity = async () => { await plugin.appManager.activatePlugin(['solidity', 'udapp', 'solidityStaticAnalysis', 'solidityUnitTesting']) plugin.verticalIcons.select('solidity') @@ -167,58 +96,38 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => { plugin.verticalIcons.select('pluginManager') } - const showFullMessage = (title: string, loadItem: string, examples: Array) => { - setState(prevState => { - return { ...prevState, showModalDialog: true, modalInfo: { title: title, loadItem: loadItem, examples: examples } } - }) - } - - const hideFullMessage = () => { //eslint-disable-line - setState(prevState => { - return { ...prevState, showModalDialog: false, importSource: '' } - }) - } - const maxHeight = Math.max(window.innerHeight - 150, 250) + 'px' - const examples = state.modalInfo.examples.map((urlEl, key) => ()) const elHeight = '4000px' + return ( - <> - hideFullMessage() } - okFn={ () => processLoading() } - > -
- { state.modalInfo.loadItem !== '' && Enter the { state.modalInfo.loadItem } you would like to load. } - { state.modalInfo.examples.length !== 0 && - <> -
e.g
-
- { examples } -
- } - { - setState(prevState => { - return { ...prevState, importSource: inputValue.current.value } - }) - }} - /> +
+
+ + + + + +
+
+
+
- - -
+
+ +
+
+ +
+
+
+ ) +} + +export default RemixUiHomeTab + + +/* +
@@ -268,36 +177,7 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => {
-
-
-

File

-

- - -

-

- - - { - event.stopPropagation() - plugin.verticalIcons.select('filePanel') - uploadFile(event.target) - }} multiple /> -

-

- - -

-

-
- - - - -
-
+ ------------------------

Resources

@@ -367,8 +247,4 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => {

- - ) -} - -export default RemixUiHomeTab + */ \ No newline at end of file