Skip to content

Commit

Permalink
Merge branch 'cn' into cn
Browse files Browse the repository at this point in the history
  • Loading branch information
dear-lizhihua authored Feb 5, 2017
2 parents 60bf5b9 + f61958d commit 4ef3159
Show file tree
Hide file tree
Showing 64 changed files with 720 additions and 374 deletions.
17 changes: 6 additions & 11 deletions antwar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ module.exports = {
}
),

'get-started': section(
'起步',
function() {
return require.context(
'json-loader!yaml-frontmatter-loader!./content/get-started',
false,
/^\.\/.*\.md$/
)
'get-started': {
redirects: {
'': '/guides/get-started',
'install-webpack': '/guides/installation',
'why-webpack': '/guides/why-webpack',
}
),
},

concepts: section(
'概念',
Expand Down Expand Up @@ -242,8 +239,6 @@ function combineContexts(context1, context2) {
}
}
webpackContext.keys = () => {
"use strict";

let keys1 = context1.keys();
let keys2 = context2.keys();
return _.chain(keys1).concat(keys2).sortBy().uniq().value();
Expand Down
1 change: 1 addition & 0 deletions assets/awesome-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions components/footer/footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default (props) => {
<footer className="footer">
<Container className="footer__inner">
<section className="footer__left">
<Link className="footer__link" to="/get-started">起步</Link>
<Link className="footer__link" to="/guides/get-started">起步</Link>
<Link className="footer__link" to="/organization">组织</Link>
<Link className="footer__link" to="/contribute">贡献</Link>
<Link className="footer__link" to="/get-started/why-webpack#comparison">比较</Link>
<Link className="footer__link" to="/guides/why-webpack#comparison">比较</Link>
</section>

<section className="footer__middle">
Expand Down
1 change: 1 addition & 0 deletions components/page/page-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.page > div:first-of-type {
flex: 0 0 auto;
position: relative;
overflow: hidden;

@include break {
flex:0 0 30%;
Expand Down
1 change: 0 additions & 1 deletion components/sidebar/sidebar-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@import 'mixins';

.sidebar {
position: absolute;
display: none;
width: 100%;
max-height: 100%;
Expand Down
79 changes: 42 additions & 37 deletions components/sidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,25 @@ export default class Sidebar extends Component {

this.state = {
fixed: false,
top: 0
extraHeight: null,
maxWidth: null
};
}

componentDidMount() {
document.addEventListener('scroll', this._recalculate.bind(this));
}

componentWillUnmount() {
document.removeEventListener('scroll', this._recalculate.bind(this));
}

/**
* Re-calculate fixed state and position
*
*/
_recalculate() {
let { scrollY, innerHeight } = window;
let { scrollHeight } = document.body;
let { offsetHeight } = this._container;
let distToBottom = scrollHeight - scrollY - innerHeight;
let headerHeight = document.querySelector('header').offsetHeight;
let footerHeight = document.querySelector('footer').offsetHeight;
let allowedHeight = distToBottom < footerHeight ? innerHeight - (footerHeight - distToBottom) : offsetHeight;
let extraHeight = offsetHeight > allowedHeight ? offsetHeight - allowedHeight : 0;
let fixed = scrollY >= headerHeight;

this.setState({
fixed,
top: scrollY - headerHeight - extraHeight
});
}

render() {
let { sectionName, pages, currentPage } = this.props;
let { fixed, top, allowedHeight } = this.state;
let { fixed, extraHeight, maxWidth } = this.state;
let isGuides = sectionName === 'guides';

return (
<nav
className="sidebar"
ref={ ref => this._container = ref }
style={ fixed ? {
top: top
position: 'fixed',
top: -extraHeight,
width: maxWidth,
maxHeight: 'none'
} : null }>

<div className="sidebar__inner">
Expand All @@ -62,11 +37,6 @@ export default class Sidebar extends Component {
currentPage= { currentPage }
/>

{ isGuides ? (
<SidebarItem
url={ `/get-started` }
title="起步" />
) : null }
{
pages.map(({ url, title, anchors }, i) =>
<SidebarItem
Expand All @@ -84,4 +54,39 @@ export default class Sidebar extends Component {
</nav>
);
}

componentDidMount() {
document.addEventListener(
'scroll',
this._recalculate.bind(this)
);
}

componentWillUnmount() {
document.removeEventListener(
'scroll',
this._recalculate.bind(this)
);
}

/**
* Re-calculate fixed state and position
*
*/
_recalculate() {
let { scrollY, innerHeight } = window;
let { scrollHeight } = document.body;
let { offsetHeight: sidebarHeight } = this._container;
let { offsetWidth: parentWidth, offsetHeight: parentHeight } = this._container.parentNode;
let headerHeight = document.querySelector('header').offsetHeight;
let footerHeight = document.querySelector('footer').offsetHeight;
let distToBottom = scrollHeight - scrollY - innerHeight;
let availableSpace = innerHeight + distToBottom - footerHeight;

this.setState({
fixed: scrollY >= headerHeight && sidebarHeight < parentHeight,
extraHeight: sidebarHeight > availableSpace ? sidebarHeight - availableSpace : 0,
maxWidth: parentWidth
});
}
}
14 changes: 11 additions & 3 deletions components/vote/api.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ export function vote(token, itemId, voteName, value) {
usedCurrencies[pv.currency] += value;
}
allItems[itemId][voteName] = (allItems[itemId][voteName] || 0) + value;
return delay(500).then(() => ({
ok: true
}));
return delay(500).then(() => true);
}

export function configItem(token, itemId, config) {
if(token !== "developer")
return Promise.reject(new Error("Not logged in as developer"));
var item = allItems[itemId];
Object.keys(config).forEach(key => {
item[key] = config[key];
});
return delay(500).then(() => true);
}
19 changes: 18 additions & 1 deletion components/vote/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
getSelf as devGetSelf,
getList as devGetList,
createItem as devCreateItem,
vote as devVote
vote as devVote,
configItem as devConfigItem
} from "./api.dev";

const API_URL = "https://oswils44oj.execute-api.us-east-1.amazonaws.com/production/";
Expand Down Expand Up @@ -110,3 +111,19 @@ export function vote(token, itemId, voteName, value) {
return true;
});
}

export function configItem(token, itemId, config) {
if(window.location.host !== PRODUCTION_HOST)
return devConfigItem(token, itemId, config);
return fetch(API_URL + "/config/" + itemId + "?token=" + token, {
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
config: config
}),
method: "POST"
}).then((res) => res.json()).then(result => {
return true;
});
}
8 changes: 8 additions & 0 deletions components/vote/app-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@
margin-right: 10px;
}

&__item-edit-title {
width: 100%;
}

&__item-edit-description {
width: 100%;
}

&__currency-list {
display: block;

Expand Down
90 changes: 85 additions & 5 deletions components/vote/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class VoteApp extends React.Component {
if(!this.isBrowserSupported())
return <div>Your browser is not supported.</div>;

let { selfInfo, listInfo, isVoting, isFetchingList, isFetchingSelf, isCreating, isLoginActive } = this.state;
let { selfInfo, listInfo, isVoting, isFetchingList, isFetchingSelf, isCreating, isLoginActive, editItem, editItemTitle, editItemDescription } = this.state;

let { voteAppToken } = localStorage;

Expand All @@ -177,6 +177,9 @@ export default class VoteApp extends React.Component {
listInfo && console.log(listInfo);
return (
<div className="vote-app">
<div className="vote-app__title">
Vote
</div>
<div className="vote-app__influence">
<div className="vote-app__top">
<div className="vote-app__influence">
Expand Down Expand Up @@ -217,18 +220,95 @@ export default class VoteApp extends React.Component {
maxUp={userVote ? maximum - value : 0}
maxDown={userVote ? value - minimum : 0}
color={this.getColor(voteSettings.name)}
isLoggedIn = {!!voteAppToken}
canVote = {!!voteAppToken && !item.locked}
onVote={(diffValue) => {
this.vote(item.id, voteSettings.name, diffValue, voteSettings.currency, voteSettings.score);
}}
/>
</div>;
})}
</div>
<div className="vote-app__item-content">
{ editItem !== item.id && <div className="vote-app__item-content">
<span className="vote-app__item-title">{item.title}</span>
<span>{item.description}</span>
</div>
{ listInfo.isAdmin && <div>
<button onClick={() => {
this.setState({
isCreating: true
});
api.configItem(voteAppToken, item.id, { locked: true }).then(() => {
this.setState({
isCreating: false
});
this.updateList();
});
}}>Lock</button>
<button onClick={() => {
this.setState({
isCreating: true
});
api.configItem(voteAppToken, item.id, { locked: false }).then(() => {
this.setState({
isCreating: false
});
this.updateList();
});
}}>Unlock</button>
<button onClick={() => {
this.setState({
isCreating: true
});
api.configItem(voteAppToken, item.id, { archived: true }).then(() => {
this.setState({
isCreating: false
});
this.updateList();
});
}}>Archive</button>
<button onClick={() => {
this.setState({
isCreating: true
});
api.configItem(voteAppToken, item.id, { archived: false }).then(() => {
this.setState({
isCreating: false
});
this.updateList();
});
}}>Unarchive</button>
<button onClick={() => {
this.setState({
isCreating: true,
editItem: item.id,
editItemTitle: item.title,
editItemDescription: item.description
});
}}>Edit</button>
</div> }
</div> }
{ editItem === item.id && <div className="vote-app__item-content">
<div className="vote-app__item-title">
<input className="vote-app__item-edit-title" type="text" value={editItemTitle} onChange={e => this.setState({ editItemTitle: e.target.value })} />
</div>
<div>
<textarea className="vote-app__item-edit-description" value={editItemDescription} onChange={e => this.setState({ editItemDescription: e.target.value })} />
</div>
<div><button onClick={() => {
this.setState({
editItem: null,
isCreating: true
});
api.configItem(voteAppToken, item.id, {
description: editItemDescription,
title: editItemTitle
}).then(() => {
this.setState({
isCreating: false
});
this.updateList();
});
}}>Done Editing</button></div>
</div> }
</div>
</li>)}
{ listInfo.isAdmin && <li className="vote-app__admin">
Expand Down Expand Up @@ -270,7 +350,7 @@ export default class VoteApp extends React.Component {
return <div className="vote-app__self-info">Loading user info...</div>;
}
return <div className="vote-app__login-button"><button onClick={() => {
api.startLogin(window.location + "");
api.startLogin(window.location + "");
}}>Login with Github <img src={GithubMark}/> </button></div>;
} else {
return <div className="vote-app__self-info">
Expand Down
4 changes: 2 additions & 2 deletions components/vote/button/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export default class NewButton extends Component {
}

render() {
const {color, className, value, myValue, isLoggedIn} = this.props;
return isLoggedIn ? (<div className="vote-new-button" style={{color: color}}>
const {color, className, value, myValue, canVote} = this.props;
return canVote ? (<div className="vote-new-button" style={{color: color}}>
<div className="vote-new-button__arrows">
{this.makeTriangle(1, triangleUp, 10, 1, true)}
{this.makeTriangle(-1, triangleDown, 10, 1, false)}
Expand Down
2 changes: 1 addition & 1 deletion content/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For proper usage and easy distribution of this configuration, webpack can be con

## Installation

Have a look at [this page](/get-started/install-webpack)
Have a look at [this page](/guides/installation)

?> The new CLI for webpack is under development. New features are being added such as the `--init` flag. [Check it out!](https://github.com/webpack/webpack-cli)

Expand Down
Loading

0 comments on commit 4ef3159

Please sign in to comment.