Skip to content

Commit

Permalink
Added UUID fetching service for user heads using https://api.minetool…
Browse files Browse the repository at this point in the history
…s.eu/

https://api.minetools.eu/ had to be used because Mojang API does not
serve CORS Response headers.
  • Loading branch information
AuroraLS3 committed Jun 28, 2018
1 parent eb91cba commit c672ba9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
19 changes: 18 additions & 1 deletion react/dashboard/src/components/SidebarHeader/SidebarHeader.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'

import uuidSvc from '../../services/uuid'

class SidebarHeader extends Component {

constructor(props) {
super(props)

this.state = {
uuid: null
}
}

componentDidMount() {
const { store } = this.context
this.unsubscribe = store.subscribe(() => this.forceUpdate())
const login = this.context.store.getState().login.login
const name = login.username
uuidSvc.getUUID(name).then(uuid => {
this.setState({ uuid })
})
}

componentWillUnmount() {
Expand All @@ -15,7 +30,9 @@ class SidebarHeader extends Component {
render() {
const login = this.context.store.getState().login.login
const name = login.username
const url = login ? `https://visage.surgeplay.com/head/150/${name}.png` : ''
const uuid = this.state.uuid

const url = login ? `https://visage.surgeplay.com/head/150/${uuid ? uuid : 'X-Alex'}.png` : ''
return (
<div className="sidebar-header">
<img src={url}></img>
Expand Down
15 changes: 15 additions & 0 deletions react/dashboard/src/services/uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import axios from 'axios'

const getUUID = async (name) => {
const url = `https://api.minetools.eu/uuid/${name}`
const response = await axios.get(
url,
{}
).catch(e => { throw e })
const id = response.data.id

return id !== 'null' ? id : null
}

export default { getUUID }

33 changes: 33 additions & 0 deletions react/dashboard/src/views/Users/UserImg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'

import uuidSvc from '../../services/uuid'

class UserImg extends React.Component {

constructor(props) {
super(props)

this.state = {
name: this.props.name,
uuid: null
}
}

componentDidMount() {
const name = this.props.name
uuidSvc.getUUID(name).then(uuid => {
this.setState({ uuid, name })
})
}

render() {
if (this.props.name !== this.state.name) {
this.componentDidMount()
}
const uuid = this.state.uuid
const url = uuid && uuid !== null ? `https://visage.surgeplay.com/face/50/${uuid}` : 'https://visage.surgeplay.com/face/50/X-Steve'
return <img style={{ padding: 0, alignContent: 'center', width: '55px' }} src={url}></img>
}
}

export default UserImg
3 changes: 2 additions & 1 deletion react/dashboard/src/views/Users/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from 'reactstrap'

import User from './User'
import UserImg from './UserImg'
import { BigAddButton } from '../../components/Buttons/AddButton'
import { BiggerRemoveButton } from '../../components/Buttons/RemoveButton'
import { BiggerDuplicateButton } from '../../components/Buttons/DuplicateButton'
Expand Down Expand Up @@ -75,7 +76,7 @@ class Users extends Component {
}).map((user, indx) => (
<Media key={indx}>
<Media>
<img style={{ padding: 0, alignContent: 'center', width: '55px' }} src={`https://visage.surgeplay.com/face/50/${user.name}`}></img>
<UserImg name={user.name} />
</Media>
<Media body>
<ListGroupItem >
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/web/index.bundle.js

Large diffs are not rendered by default.

0 comments on commit c672ba9

Please sign in to comment.