Skip to content

Commit 4ef3159

Browse files
Merge branch 'cn' into cn
2 parents 60bf5b9 + f61958d commit 4ef3159

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+720
-374
lines changed

antwar.config.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ module.exports = {
3838
}
3939
),
4040

41-
'get-started': section(
42-
'起步',
43-
function() {
44-
return require.context(
45-
'json-loader!yaml-frontmatter-loader!./content/get-started',
46-
false,
47-
/^\.\/.*\.md$/
48-
)
41+
'get-started': {
42+
redirects: {
43+
'': '/guides/get-started',
44+
'install-webpack': '/guides/installation',
45+
'why-webpack': '/guides/why-webpack',
4946
}
50-
),
47+
},
5148

5249
concepts: section(
5350
'概念',
@@ -242,8 +239,6 @@ function combineContexts(context1, context2) {
242239
}
243240
}
244241
webpackContext.keys = () => {
245-
"use strict";
246-
247242
let keys1 = context1.keys();
248243
let keys2 = context2.keys();
249244
return _.chain(keys1).concat(keys2).sortBy().uniq().value();

assets/awesome-badge.svg

Lines changed: 1 addition & 0 deletions
Loading

components/footer/footer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export default (props) => {
1010
<footer className="footer">
1111
<Container className="footer__inner">
1212
<section className="footer__left">
13-
<Link className="footer__link" to="/get-started">起步</Link>
13+
<Link className="footer__link" to="/guides/get-started">起步</Link>
1414
<Link className="footer__link" to="/organization">组织</Link>
1515
<Link className="footer__link" to="/contribute">贡献</Link>
16-
<Link className="footer__link" to="/get-started/why-webpack#comparison">比较</Link>
16+
<Link className="footer__link" to="/guides/why-webpack#comparison">比较</Link>
1717
</section>
1818

1919
<section className="footer__middle">

components/page/page-style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.page > div:first-of-type {
1313
flex: 0 0 auto;
1414
position: relative;
15+
overflow: hidden;
1516

1617
@include break {
1718
flex:0 0 30%;

components/sidebar/sidebar-style.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@import 'mixins';
33

44
.sidebar {
5-
position: absolute;
65
display: none;
76
width: 100%;
87
max-height: 100%;

components/sidebar/sidebar.jsx

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,25 @@ export default class Sidebar extends Component {
77

88
this.state = {
99
fixed: false,
10-
top: 0
10+
extraHeight: null,
11+
maxWidth: null
1112
};
1213
}
1314

14-
componentDidMount() {
15-
document.addEventListener('scroll', this._recalculate.bind(this));
16-
}
17-
18-
componentWillUnmount() {
19-
document.removeEventListener('scroll', this._recalculate.bind(this));
20-
}
21-
22-
/**
23-
* Re-calculate fixed state and position
24-
*
25-
*/
26-
_recalculate() {
27-
let { scrollY, innerHeight } = window;
28-
let { scrollHeight } = document.body;
29-
let { offsetHeight } = this._container;
30-
let distToBottom = scrollHeight - scrollY - innerHeight;
31-
let headerHeight = document.querySelector('header').offsetHeight;
32-
let footerHeight = document.querySelector('footer').offsetHeight;
33-
let allowedHeight = distToBottom < footerHeight ? innerHeight - (footerHeight - distToBottom) : offsetHeight;
34-
let extraHeight = offsetHeight > allowedHeight ? offsetHeight - allowedHeight : 0;
35-
let fixed = scrollY >= headerHeight;
36-
37-
this.setState({
38-
fixed,
39-
top: scrollY - headerHeight - extraHeight
40-
});
41-
}
42-
4315
render() {
4416
let { sectionName, pages, currentPage } = this.props;
45-
let { fixed, top, allowedHeight } = this.state;
17+
let { fixed, extraHeight, maxWidth } = this.state;
4618
let isGuides = sectionName === 'guides';
4719

4820
return (
4921
<nav
5022
className="sidebar"
5123
ref={ ref => this._container = ref }
5224
style={ fixed ? {
53-
top: top
25+
position: 'fixed',
26+
top: -extraHeight,
27+
width: maxWidth,
28+
maxHeight: 'none'
5429
} : null }>
5530

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

65-
{ isGuides ? (
66-
<SidebarItem
67-
url={ `/get-started` }
68-
title="起步" />
69-
) : null }
7040
{
7141
pages.map(({ url, title, anchors }, i) =>
7242
<SidebarItem
@@ -84,4 +54,39 @@ export default class Sidebar extends Component {
8454
</nav>
8555
);
8656
}
57+
58+
componentDidMount() {
59+
document.addEventListener(
60+
'scroll',
61+
this._recalculate.bind(this)
62+
);
63+
}
64+
65+
componentWillUnmount() {
66+
document.removeEventListener(
67+
'scroll',
68+
this._recalculate.bind(this)
69+
);
70+
}
71+
72+
/**
73+
* Re-calculate fixed state and position
74+
*
75+
*/
76+
_recalculate() {
77+
let { scrollY, innerHeight } = window;
78+
let { scrollHeight } = document.body;
79+
let { offsetHeight: sidebarHeight } = this._container;
80+
let { offsetWidth: parentWidth, offsetHeight: parentHeight } = this._container.parentNode;
81+
let headerHeight = document.querySelector('header').offsetHeight;
82+
let footerHeight = document.querySelector('footer').offsetHeight;
83+
let distToBottom = scrollHeight - scrollY - innerHeight;
84+
let availableSpace = innerHeight + distToBottom - footerHeight;
85+
86+
this.setState({
87+
fixed: scrollY >= headerHeight && sidebarHeight < parentHeight,
88+
extraHeight: sidebarHeight > availableSpace ? sidebarHeight - availableSpace : 0,
89+
maxWidth: parentWidth
90+
});
91+
}
8792
}

components/vote/api.dev.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ export function vote(token, itemId, voteName, value) {
147147
usedCurrencies[pv.currency] += value;
148148
}
149149
allItems[itemId][voteName] = (allItems[itemId][voteName] || 0) + value;
150-
return delay(500).then(() => ({
151-
ok: true
152-
}));
150+
return delay(500).then(() => true);
151+
}
152+
153+
export function configItem(token, itemId, config) {
154+
if(token !== "developer")
155+
return Promise.reject(new Error("Not logged in as developer"));
156+
var item = allItems[itemId];
157+
Object.keys(config).forEach(key => {
158+
item[key] = config[key];
159+
});
160+
return delay(500).then(() => true);
153161
}

components/vote/api.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
getSelf as devGetSelf,
66
getList as devGetList,
77
createItem as devCreateItem,
8-
vote as devVote
8+
vote as devVote,
9+
configItem as devConfigItem
910
} from "./api.dev";
1011

1112
const API_URL = "https://oswils44oj.execute-api.us-east-1.amazonaws.com/production/";
@@ -110,3 +111,19 @@ export function vote(token, itemId, voteName, value) {
110111
return true;
111112
});
112113
}
114+
115+
export function configItem(token, itemId, config) {
116+
if(window.location.host !== PRODUCTION_HOST)
117+
return devConfigItem(token, itemId, config);
118+
return fetch(API_URL + "/config/" + itemId + "?token=" + token, {
119+
headers: {
120+
"Content-Type": "application/json"
121+
},
122+
body: JSON.stringify({
123+
config: config
124+
}),
125+
method: "POST"
126+
}).then((res) => res.json()).then(result => {
127+
return true;
128+
});
129+
}

components/vote/app-style.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
margin-right: 10px;
125125
}
126126

127+
&__item-edit-title {
128+
width: 100%;
129+
}
130+
131+
&__item-edit-description {
132+
width: 100%;
133+
}
134+
127135
&__currency-list {
128136
display: block;
129137

components/vote/app.jsx

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default class VoteApp extends React.Component {
153153
if(!this.isBrowserSupported())
154154
return <div>Your browser is not supported.</div>;
155155

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

158158
let { voteAppToken } = localStorage;
159159

@@ -177,6 +177,9 @@ export default class VoteApp extends React.Component {
177177
listInfo && console.log(listInfo);
178178
return (
179179
<div className="vote-app">
180+
<div className="vote-app__title">
181+
Vote
182+
</div>
180183
<div className="vote-app__influence">
181184
<div className="vote-app__top">
182185
<div className="vote-app__influence">
@@ -217,18 +220,95 @@ export default class VoteApp extends React.Component {
217220
maxUp={userVote ? maximum - value : 0}
218221
maxDown={userVote ? value - minimum : 0}
219222
color={this.getColor(voteSettings.name)}
220-
isLoggedIn = {!!voteAppToken}
223+
canVote = {!!voteAppToken && !item.locked}
221224
onVote={(diffValue) => {
222225
this.vote(item.id, voteSettings.name, diffValue, voteSettings.currency, voteSettings.score);
223226
}}
224227
/>
225228
</div>;
226229
})}
227230
</div>
228-
<div className="vote-app__item-content">
231+
{ editItem !== item.id && <div className="vote-app__item-content">
229232
<span className="vote-app__item-title">{item.title}</span>
230233
<span>{item.description}</span>
231-
</div>
234+
{ listInfo.isAdmin && <div>
235+
<button onClick={() => {
236+
this.setState({
237+
isCreating: true
238+
});
239+
api.configItem(voteAppToken, item.id, { locked: true }).then(() => {
240+
this.setState({
241+
isCreating: false
242+
});
243+
this.updateList();
244+
});
245+
}}>Lock</button>
246+
<button onClick={() => {
247+
this.setState({
248+
isCreating: true
249+
});
250+
api.configItem(voteAppToken, item.id, { locked: false }).then(() => {
251+
this.setState({
252+
isCreating: false
253+
});
254+
this.updateList();
255+
});
256+
}}>Unlock</button>
257+
<button onClick={() => {
258+
this.setState({
259+
isCreating: true
260+
});
261+
api.configItem(voteAppToken, item.id, { archived: true }).then(() => {
262+
this.setState({
263+
isCreating: false
264+
});
265+
this.updateList();
266+
});
267+
}}>Archive</button>
268+
<button onClick={() => {
269+
this.setState({
270+
isCreating: true
271+
});
272+
api.configItem(voteAppToken, item.id, { archived: false }).then(() => {
273+
this.setState({
274+
isCreating: false
275+
});
276+
this.updateList();
277+
});
278+
}}>Unarchive</button>
279+
<button onClick={() => {
280+
this.setState({
281+
isCreating: true,
282+
editItem: item.id,
283+
editItemTitle: item.title,
284+
editItemDescription: item.description
285+
});
286+
}}>Edit</button>
287+
</div> }
288+
</div> }
289+
{ editItem === item.id && <div className="vote-app__item-content">
290+
<div className="vote-app__item-title">
291+
<input className="vote-app__item-edit-title" type="text" value={editItemTitle} onChange={e => this.setState({ editItemTitle: e.target.value })} />
292+
</div>
293+
<div>
294+
<textarea className="vote-app__item-edit-description" value={editItemDescription} onChange={e => this.setState({ editItemDescription: e.target.value })} />
295+
</div>
296+
<div><button onClick={() => {
297+
this.setState({
298+
editItem: null,
299+
isCreating: true
300+
});
301+
api.configItem(voteAppToken, item.id, {
302+
description: editItemDescription,
303+
title: editItemTitle
304+
}).then(() => {
305+
this.setState({
306+
isCreating: false
307+
});
308+
this.updateList();
309+
});
310+
}}>Done Editing</button></div>
311+
</div> }
232312
</div>
233313
</li>)}
234314
{ listInfo.isAdmin && <li className="vote-app__admin">
@@ -270,7 +350,7 @@ export default class VoteApp extends React.Component {
270350
return <div className="vote-app__self-info">Loading user info...</div>;
271351
}
272352
return <div className="vote-app__login-button"><button onClick={() => {
273-
api.startLogin(window.location + "");
353+
api.startLogin(window.location + "");
274354
}}>Login with Github <img src={GithubMark}/> </button></div>;
275355
} else {
276356
return <div className="vote-app__self-info">

components/vote/button/button.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export default class NewButton extends Component {
9393
}
9494

9595
render() {
96-
const {color, className, value, myValue, isLoggedIn} = this.props;
97-
return isLoggedIn ? (<div className="vote-new-button" style={{color: color}}>
96+
const {color, className, value, myValue, canVote} = this.props;
97+
return canVote ? (<div className="vote-new-button" style={{color: color}}>
9898
<div className="vote-new-button__arrows">
9999
{this.makeTriangle(1, triangleUp, 10, 1, true)}
100100
{this.makeTriangle(-1, triangleDown, 10, 1, false)}

content/api/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ For proper usage and easy distribution of this configuration, webpack can be con
1111

1212
## Installation
1313

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

1616
?> 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)
1717

0 commit comments

Comments
 (0)