|
| 1 | +import _ from 'lodash' |
| 2 | +import React, { Component } from 'react' |
| 3 | +import PropTypes from 'prop-types' |
| 4 | +import cx from 'classnames' |
| 5 | +import { observer, inject } from 'mobx-react' |
| 6 | +import { observable } from 'mobx' |
| 7 | +import dispatchCommand from 'commands/dispatchCommand' |
| 8 | +import api from '../../backendAPI' |
| 9 | + |
| 10 | +@observer |
| 11 | +class WelcomePage extends Component { |
| 12 | + constructor (props) { |
| 13 | + super(props) |
| 14 | + this.state = observable({ |
| 15 | + recentList: [] |
| 16 | + }) |
| 17 | + } |
| 18 | + componentWillMount () { |
| 19 | + this.loadRecentWS() |
| 20 | + } |
| 21 | + |
| 22 | + render () { |
| 23 | + return ( |
| 24 | + <div className='welcome-page'> |
| 25 | + <h1>Coding WebIDE</h1> |
| 26 | + <div className='subtitle'>Coding Anytime Anywhere</div> |
| 27 | + |
| 28 | + <h2>Start</h2> |
| 29 | + <div className='block start-block'> |
| 30 | + <div className='link-item'> |
| 31 | + <a href='#' onClick={this.createNewFile}>New File...</a> |
| 32 | + </div> |
| 33 | + <div className='link-item'> |
| 34 | + <a href='#' onClick={this.createNewFolder}>New Folder...</a> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + |
| 38 | + <h2>Recent</h2> |
| 39 | + <div className='block recent-block'> |
| 40 | + {this.renderRecentItem()} |
| 41 | + </div> |
| 42 | + |
| 43 | + <h2>Help</h2> |
| 44 | + <div className='block help-block'> |
| 45 | + <div className='link-item'> |
| 46 | + <a href='https://coding.net/help/doc/webide/' target='blank'>Document</a> |
| 47 | + </div> |
| 48 | + <div className='link-item'> |
| 49 | + <a href='https://coding.net/feedback' target='blank'>Feedback</a> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + ) |
| 54 | + } |
| 55 | + renderRecentItem () { |
| 56 | + return ( |
| 57 | + <div className='recent-list'> |
| 58 | + { |
| 59 | + this.state.recentList.map((recentItem) => { |
| 60 | + return ( |
| 61 | + <div className='recent-item' key={recentItem.name}> |
| 62 | + <a href={recentItem.link}>{recentItem.name}</a> |
| 63 | + </div> |
| 64 | + ) |
| 65 | + }) |
| 66 | + } |
| 67 | + </div> |
| 68 | + ) |
| 69 | + } |
| 70 | + createNewFile (e) { |
| 71 | + e.preventDefault() |
| 72 | + dispatchCommand('file:new_file') |
| 73 | + } |
| 74 | + createNewFolder (e) { |
| 75 | + e.preventDefault() |
| 76 | + dispatchCommand('file:new_folder') |
| 77 | + } |
| 78 | + loadRecentWS () { |
| 79 | + api.getWorkspaceList().then((res) => { |
| 80 | + if (res.contents && res.contents.length > 0) { |
| 81 | + const recentList = [] |
| 82 | + res.contents.forEach((ws) => { |
| 83 | + let name = '' |
| 84 | + if (ws.defaultWorkspace) { |
| 85 | + name = 'Default' |
| 86 | + } else { |
| 87 | + name = `${ws.project.ownerName}/${ws.project.name}` |
| 88 | + } |
| 89 | + const wsItem = { |
| 90 | + name, |
| 91 | + icon: '', |
| 92 | + link: `/ws/${ws.spaceKey}`, |
| 93 | + command: () => { |
| 94 | + window.open(`/ws/${ws.spaceKey}`) |
| 95 | + }, |
| 96 | + } |
| 97 | + recentList.push(wsItem) |
| 98 | + }) |
| 99 | + |
| 100 | + this.state.recentList = recentList |
| 101 | + } |
| 102 | + }) |
| 103 | + } |
| 104 | + |
| 105 | +} |
| 106 | + |
| 107 | +export default WelcomePage |
0 commit comments