Skip to content

Commit 458e735

Browse files
committed
Merge branch 'dev'
2 parents 3c95475 + 1ffb639 commit 458e735

File tree

7 files changed

+73
-30
lines changed

7 files changed

+73
-30
lines changed

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
work correctly both with client-side routing and a non-root public URL.
2020
Learn how to configure a non-root public URL by running `npm run build`.
2121
-->
22-
<title>React App</title>
22+
<title>Pixeval</title>
2323
</head>
2424
<body>
2525
<noscript>

src/main/js/theme.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createTheme } from "@fluentui/react";
1+
import {createTheme} from "@fluentui/react";
22

33
export const lightTheme = createTheme({
44
palette: {
@@ -52,8 +52,4 @@ export const darkTheme = createTheme({
5252
white: '#323130',
5353
}});
5454

55-
export const isDarkMode = () => {
56-
const res = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
57-
console.log(res)
58-
return res
59-
}
55+
export const isDarkMode = () => window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches

src/main/resources/Contributor.css

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
.Contributor {
2-
margin-top: 100px;
3-
margin-bottom: 100px;
4-
}
5-
61
.Contributor-title {
72
text-align: center;
83
}
4+
5+
6+
@media(max-width: 900px) {
7+
8+
#Contributor-stack-div .ms-Persona-details {
9+
display: none;
10+
}
11+
12+
#Contributor-stack-div .ms-Persona {
13+
margin-left: 3px;
14+
margin-right: 3px;
15+
}
16+
}

src/main/resources/Header.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
.Header-logo {
66
text-align: center;
7-
height: 350px;
7+
height: auto;
8+
max-height: 350px;
9+
max-width: 100%;
810
}
911

1012
.Header-header {

src/main/resources/index.css

+10
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ body {
33
padding: 0;
44
font-family: 'Microsoft Yahei', Verdana, Simsun, 'Segoe UI', Tahoma, Arial, sans-serif;
55
}
6+
7+
section {
8+
margin-bottom: 100px;
9+
}
10+
11+
@media(max-width: 900px) {
12+
section {
13+
margin-bottom: 30px;
14+
}
15+
}

src/main/scala/com/github/pixeval/pixevalintro/component/section/ContributorSection.scala

+43-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import typings.officeUiFabricReact.personaTypesMod.{ IPersonaProps, PersonaSize
1616
import typings.officeUiFabricReact.stackTypesMod.{ Alignment, IStackProps }
1717
import typings.react.anon.Children
1818

19+
import scala.concurrent.Future
1920
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
2021
import scala.scalajs.js
2122
import scala.scalajs.js.JSON
@@ -28,25 +29,48 @@ class ContributorSection extends Component {
2829
import ContributorSection._
2930

3031
type Props = Unit
31-
case class State(personas: Seq[IPersonaProps], hrefs: Seq[String])
32-
override def initialState: State = State(Nil, Nil)
32+
case class State(
33+
texts: Seq[String], imageUrls: Seq[String], secondaryTexts: Seq[String], hrefs: Seq[String], isMain: Seq[Boolean]
34+
) {
35+
def toPersonaProps: Seq[PersonaProps] = texts.indices.map { i =>
36+
PersonaProps(imageUrls(i), texts(i), secondaryTexts(i), isMain(i))
37+
}
38+
}
39+
40+
override def initialState: State = State(Nil, Nil, Nil, Nil, Nil)
3341
val css: ContributorCSS.type = ContributorCSS
3442

3543
override def componentWillMount(): Unit = {
3644
Ajax.get("https://api.github.com/repos/Pixeval/Pixeval/contributors").onComplete {
3745
case Success(value) => {
38-
val contributors = JSON.parse(value.responseText).asInstanceOf[js.Array[GithubUser]].toSeq
39-
val personas: Seq[IPersonaProps] = contributors.zipWithIndex.map {
40-
case (user, i) => new PersonaProps(user, i).asJS
41-
}
42-
val order: Seq[Int] = centralizeContributors(personas.size);
46+
val contributors = JSON.parse(value.responseText).asInstanceOf[js.Array[Contributor]].toSeq
47+
val order: Seq[Int] = centralizeContributors(contributors.size)
48+
val texts: Seq[String] = order map contributors.map(_.login)
49+
val imageUrls: Seq[String] = order map contributors.map(_.avatar_url)
50+
val secondaryTexts: Seq[String] = order map contributors.map(info => s"贡献: ${ info.contributions }")
4351
val hrefs: Seq[String] = order map contributors.map(_.html_url)
44-
this.setState(State(order map personas, hrefs))
52+
val isMain: Seq[Boolean] = order map (true :: List.fill(contributors.size - 1)(false))
53+
54+
val namesFuture = Future.traverse(texts)(getUserName)
55+
namesFuture onComplete {
56+
case Success(newTexts) => this.setState(State(newTexts, imageUrls, secondaryTexts, hrefs, isMain))
57+
case Failure(_) => throw new Exception()
58+
}
4559
}
4660
case Failure(_) => throw new Exception()
4761
}
4862
}
4963

64+
private def getUserName(login: String): Future[String] =
65+
Ajax.get(s"https://api.github.com/users/$login").map {
66+
response => {
67+
val user = JSON.parse(response.responseText).asInstanceOf[GithubUser]
68+
val name = user.name
69+
if (name == null) login
70+
else name
71+
}
72+
}
73+
5074
final val headerDesc: String = "贡献者"
5175

5276
private def renderPersona(): ReactElement = Stack.withProps(IStackProps()
@@ -56,7 +80,7 @@ class ContributorSection extends Component {
5680
.setHorizontalAlign(Alignment.center)
5781
.setClassName("Contributor-stack").asInstanceOf[IStackProps with Children])(
5882

59-
this.state.personas.map(Persona.withProps)
83+
this.state.toPersonaProps.map(_.asJS).map(Persona.withProps)
6084
)
6185

6286
private def addAForPersonas(): Unit = {
@@ -93,7 +117,7 @@ class ContributorSection extends Component {
93117
}
94118

95119
override def render(): ReactElement = {
96-
if (this.state.personas.nonEmpty)
120+
if (this.state.isMain.nonEmpty)
97121
section(className := "Contributor")(
98122

99123
h2(className := "Contributor-title", style := js.Dynamic.literal(
@@ -113,19 +137,22 @@ object ContributorSection {
113137
object ContributorCSS extends js.Object
114138

115139
@js.native
116-
trait GithubUser extends js.Object {
140+
trait Contributor extends js.Object {
117141
val login: String
118142
val avatar_url: String
119143
val contributions: Int
120144
val html_url: String
121145
}
122146

123-
class PersonaProps(info: GithubUser, i: Int) {
124-
val imageUrl: String = info.avatar_url
125-
val text: String = info.login
126-
val secondaryText: String = s"贡献: ${ info.contributions }"
147+
@js.native
148+
trait GithubUser extends js.Object {
149+
val login: String
150+
val name: String
151+
}
152+
153+
case class PersonaProps(imageUrl: String, text: String, secondaryText: String, isMain: Boolean) {
127154

128-
def getSize: PersonaSize with Double = if (i == 0) mainSize else otherSize
155+
def getSize: PersonaSize with Double = if (isMain) mainSize else otherSize
129156

130157
def asJS: IPersonaProps = {
131158
val obj = IPersonaProps()

webpack/webpack-core.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = {
4646
devtoolModuleFilenameTemplate: (f) => {
4747
if (f.resourcePath.startsWith("http://") ||
4848
f.resourcePath.startsWith("https://") ||
49-
f.resourcePath.startsWith("file:///")) {
49+
f.resourcePath.startsWith("file://")) {
5050
return f.resourcePath;
5151
} else {
5252
return "webpack://" + f.namespace + "/" + f.resourcePath;

0 commit comments

Comments
 (0)