Skip to content

Icons, Fonts & Notifications #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 2, 2020
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "rm -rf build && npm run build:ext && npm run build:web",
"build:ext": "tsc -p ./",
"build:web": "cd web-app && npm run build",
"postbuild:web": "cp -R ./web-app/build/ ./build/",
"postbuild:web": "cp -R ./web-app/build/ ./build/ && node scripts/fixFontPaths.js",
"postinstall": "node ./node_modules/vscode/bin/install",
"lint": "eslint src/**/*ts",
"machine": "node ./out/state/index.js",
Expand All @@ -41,7 +41,6 @@
"@types/assert": "^1.4.5",
"@types/chokidar": "^2.1.3",
"@types/dotenv": "^8.2.0",
"@types/glob": "^7.1.1",
"@types/jest": "^25.1.1",
"@types/jsdom": "^12.2.4",
"@types/node": "^13.5.3",
Expand Down
Binary file removed resources/public/favicon.ico
Binary file not shown.
40 changes: 0 additions & 40 deletions resources/public/index.html

This file was deleted.

15 changes: 0 additions & 15 deletions resources/public/manifest.json

This file was deleted.

26 changes: 26 additions & 0 deletions scripts/fixFontPaths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* css url font paths do not match up from the web-app as it is moved inside of build
* in order to load fonts and icons, these paths must be reconciled.
*/
const fs = require('fs') // eslint-disable-line

// find the generated main css file
const getMainCSSFile = () => {
const regex = /^main.[a-z0-9]+.chunk.css$/
const mainCss = fs.readdirSync('build/static/css').filter(filename => filename.match(regex))
if (!mainCss.length) {
throw new Error('No main.css file found in build/static/css')
}
return mainCss[0]
}

// remap the font paths from the borken /fonts/ => ../../fonts/
const remapFontPaths = () => {
const mainCSSFile = getMainCSSFile()
const file = fs.readFileSync(`build/static/css/${mainCSSFile}`, 'utf8')
const fontUrlRegex = /url\(\/fonts\//g
const remappedFile = file.replace(fontUrlRegex, 'url(../../fonts/')
fs.writeFileSync(`build/static/css/${mainCSSFile}`, remappedFile)
}

remapFontPaths()
7 changes: 2 additions & 5 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }:
testRunner = createTestRunner(config, {
onSuccess: (payload: Payload) => {
// send test pass message back to client
notify({ message: 'PASS' })
webview.send({ type: 'TEST_PASS', payload })
// update local storage
},
onFail: (payload: Payload, message: string) => {
// send test fail message back to client
notify({ message: `FAIL ${message}` })
webview.send({ type: 'TEST_FAIL', payload })
// send test fail message back to client with failure message
webview.send({ type: 'TEST_FAIL', payload: { ...payload, message } })
},
onError: (payload: Payload) => {
// send test error message back to client
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"allowJs": true,
"removeComments": true
},
"exclude": ["node_modules", ".vscode-test", "build", "resources", "web-app", "*.js", "*.test.ts"]
"exclude": ["node_modules", ".vscode-test", "build", "resources", "web-app", "*.js", "*.test.ts", "scripts"]
}
8 changes: 7 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ export interface ErrorMessage {
description?: string
}

export interface TestStatus {
type: 'success' | 'warning' | 'error' | 'loading'
title: string
content?: string
}

export interface MachineContext {
env: Environment
error: ErrorMessage | null
tutorial: G.Tutorial | null
position: Position
progress: Progress
processes: ProcessEvent[]
testStatus: TestStatus | null
}

export interface MachineEvent {
Expand Down Expand Up @@ -83,7 +90,6 @@ export interface MachineStateSchema {
TestRunning: {}
TestPass: {}
TestFail: {}
TestError: {}
StepNext: {}
LevelComplete: {}
}
Expand Down
3 changes: 1 addition & 2 deletions web-app/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const { addBabelPreset, addBabelPlugin, addWebpackModuleRule } = require('customize-cra')
const { addBabelPreset, addWebpackModuleRule, addBabelPlugin } = require('customize-cra')

module.exports = function override(config) {
addWebpackModuleRule({
Expand Down
6 changes: 3 additions & 3 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Routes = () => {
<Route path={['Start.LoadTutorialSummary', 'Start.LoadTutorialData', 'Start.SetupNewTutorial']}>
<LoadingPage text="Loading Tutorial..." context={context} />
</Route>
<Route path={'Start.Error'}>
<Route path="Start.Error">
<LoadingPage text="Error" context={context} />
</Route>
<Route path="Start.SelectTutorial">
Expand All @@ -32,11 +32,11 @@ const Routes = () => {
<Route path="Start.Summary">
<OverviewPage send={send} context={context} />
</Route>
<Route path="SetupNewTutorial">
<Route path="Start.SetupNewTutorial">
<LoadingPage text="Configuring tutorial..." context={context} />
</Route>
{/* Tutorial */}
<Route path="Tutorial.LoadNext">
<Route path={['Tutorial.LoadNext', 'Tutorial.Level.Load']}>
<LoadingPage text="Loading Level..." context={context} />
</Route>
<Route path="Tutorial.Level">
Expand Down
11 changes: 10 additions & 1 deletion web-app/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ interface Props {
disabled?: boolean
type?: 'primary' | 'secondary' | 'normal'
onClick?: () => void
size?: 'small' | 'medium' | 'large'
iconSize?: 'xxs' | 'xs' | 'small' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl'
}

const Button = (props: Props) => (
<AlifdButton onClick={props.onClick} type={props.type} disabled={props.disabled} style={props.style}>
<AlifdButton
onClick={props.onClick}
type={props.type}
disabled={props.disabled}
style={props.style}
size={props.size}
iconSize={props.iconSize}
>
{props.children}
</AlifdButton>
)
Expand Down
24 changes: 2 additions & 22 deletions web-app/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import * as React from 'react'
import { css, jsx } from '@emotion/core'

const styles = {
box: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
input: {
border: '1px solid black',
},
loading: {
backgroundColor: 'red',
},
}
import { Checkbox as AlifdCheckbox } from '@alifd/next'

interface Props {
status: 'COMPLETE' | 'INCOMPLETE' | 'ACTIVE'
Expand All @@ -26,13 +12,7 @@ const Checkbox = (props: Props) => {

const checked = props.status === 'COMPLETE'

return (
<div css={styles.box}>
<label>
<input css={styles.input} type="checkbox" checked={checked} onChange={onChange} />
</label>
</div>
)
return <AlifdCheckbox checked={checked} onChange={onChange} />
}

export default Checkbox
28 changes: 24 additions & 4 deletions web-app/src/components/Message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,35 @@ import { Message as AlifdMessage } from '@alifd/next'
import * as React from 'react'

interface Props {
type: 'error'
type?: 'success' | 'warning' | 'error' | 'notice' | 'help' | 'loading'
shape?: 'inline' | 'addon' | 'toast'
size?: 'medium' | 'large'
title: string
description?: string
content?: string
closed?: boolean
closeable?: boolean
onClose?: () => void
handleClose?: () => void
}

const Message = (props: Props) => {
const [visible, setVisible] = React.useState(true)
function onClose() {
if (props.onClose) {
props.onClose()
}
setVisible(false)
}
return (
<AlifdMessage type={props.type} title={props.title}>
{props.description}
<AlifdMessage
type={props.type}
visible={props.closed ? !props.closed : visible}
title={props.title}
closeable={props.closeable}
onClose={onClose}
shape={props.shape}
>
{props.content}
</AlifdMessage>
)
}
Expand Down
43 changes: 43 additions & 0 deletions web-app/src/components/ProcessMessages/TestMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Message from '../Message'
import * as React from 'react'
import * as T from 'typings'
import { css, jsx } from '@emotion/core'

const durations = {
success: 1000,
warning: 4500,
error: 4500,
loading: 300000,
}

const useTimeout = ({ duration, key }: { duration: number; key: string }) => {
const [timeoutClose, setTimeoutClose] = React.useState(false)
React.useEffect(() => {
setTimeoutClose(false)
const timeout = setTimeout(() => {
setTimeoutClose(true)
}, duration)
return () => {
clearTimeout(timeout)
}
}, [key])
return timeoutClose
}

const TestMessage = (props: T.TestStatus) => {
const duration = durations[props.type]
const timeoutClose = useTimeout({ duration, key: props.title })
return (
<Message
key={props.title}
type={props.type}
title={props.title}
closed={timeoutClose}
size="medium"
closeable={props.type !== 'loading'}
content={props.content}
/>
)
}

export default TestMessage
Loading