Skip to content
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

Enhancement: Clans page error handling and Snowflake timeframe constraint #544

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions grunt/run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
webpack: {
args: ['node_modules/.bin/webpack']
}
args: ['node_modules/.bin/webpack'],
},
}
17 changes: 15 additions & 2 deletions public/styles/site/getClans.sass
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,21 @@
grid-template-columns: repeat(3, 1fr)
li
font-size: 10px


.spinner
border: 6px solid rgba(0, 0, 0, 0.0)
border-left-color: #ffa300
border-radius: 50%
width: 220px
height: 220px
animation: spin 1s linear infinite
margin: 20px auto

@keyframes spin
0%
transform: rotate(0deg)
100%
transform: rotate(360deg)

#iAmMember
display: none

9 changes: 1 addition & 8 deletions src/backend/templates/layouts/default.pug
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,7 @@ html(lang='en')
a(href=forumUrl) FORUMS

script(src=webpackAssetJS('navigation'))
script(
src='https://unpkg.com/magic-snowflakes/dist/snowflakes.min.js',
crossorigin='anonymous'
)
script(type='text/javascript').
if (typeof Snowflakes !== 'undefined') {
new Snowflakes()
}
script(src=webpackAssetJS('snowflakes'))

//- Include template-specific javascript files by extending the js block
block js
2 changes: 2 additions & 0 deletions src/backend/templates/mixins/loading-spinner.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mixin loading-spinner
.spinner
2 changes: 2 additions & 0 deletions src/backend/templates/views/clans/clans.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
extends ../../layouts/default
include ../../mixins/loading-spinner

block content
h1 Clans
+loading-spinner
table#clan-table
block js
script(src=webpackAssetJS('clans'))
32 changes: 15 additions & 17 deletions src/frontend/js/entrypoint/clans.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@ import 'simple-datatables/dist/style.css'
axios
.get('/data/clans.json')
.then((response) => {
if (
response.status !== 200 ||
!response.data ||
!response.data.length
) {
console.error('request clans failed')

return
}

const clans = response.data
const datatable = new DataTable('#clan-table', {
document.querySelector('.spinner').remove()
const dataTable = new DataTable('#clan-table', {
perPageSelect: null,
data: {
headings: ['TAG', 'NAME', 'LEADER', 'POPULATION'],
data: clans.map((item) => {
data: response.data.map((item) => {
return [
item.tag,
item.name,
Expand All @@ -31,13 +21,21 @@ axios
},
})

datatable.on('datatable.selectrow', (rowIndex, event) => {
dataTable.on('datatable.selectrow', (rowIndex, event) => {
if (typeof rowIndex === 'number') {
event.preventDefault()
window.location.href = '/clans/view/' + clans[rowIndex].id
window.location.href =
'/clans/view/' + response.data[rowIndex].id
}
})
})
.catch((err) => {
console.log(err, 'loading clans failed')
.catch((error) => {
document.querySelector('.spinner').remove()
const header = document.querySelector('h1')
const errorElement = document.createElement('h2')
errorElement.textContent =
'Failed to load clans. Please try again later'

console.error(error)
header.insertAdjacentElement('afterend', errorElement)
})
8 changes: 4 additions & 4 deletions src/frontend/js/entrypoint/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,19 @@ document.addEventListener('DOMContentLoaded', () => {

// function to make highligthed text change colors/pulsate (it goes from white to gold and viceversa)
const highlightText = document.querySelectorAll('.highlightText')
let highLigthCounter = 0
let highlightCounter = 0

function highlightPulse() {
if (highLigthCounter < 1) {
highLigthCounter++
if (highlightCounter < 1) {
highlightCounter++
highlightText.forEach((element) => {
element.style.transition = '1s'
})
highlightText.forEach((element) => {
element.style.color = '#FFFFFF'
})
} else {
highLigthCounter--
highlightCounter--
highlightText.forEach((element) => {
element.style.color = '#f7941d'
})
Expand Down
17 changes: 17 additions & 0 deletions src/frontend/js/entrypoint/snowflakes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const script = document.createElement('script')

script.src = 'https://unpkg.com/magic-snowflakes/dist/snowflakes.min.js'
script.setAttribute('crossorigin', 'anonymous')

document.body.appendChild(script)

script.onload = function () {
const currentMonth = new Date().getMonth() + 1
if (
typeof Snowflakes !== 'undefined' &&
(currentMonth <= 2 || currentMonth >= 10)
) {
// eslint-disable-next-line no-new, no-undef
new Snowflakes()
}
}
19 changes: 10 additions & 9 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ module.exports = {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
use: ['style-loader', 'css-loader'],
},
],
},
entry: {
clan: ['./src/frontend/js/entrypoint/clan.js'],
clans: ['./src/frontend/js/entrypoint/clans.js'],
'content-creators': ['./src/frontend/js/entrypoint/content-creators.js'],
'content-creators': [
'./src/frontend/js/entrypoint/content-creators.js',
],
donation: ['./src/frontend/js/entrypoint/donation.js'],
'faf-teams': ['./src/frontend/js/entrypoint/faf-teams.js'],
leaderboards: ['./src/frontend/js/entrypoint/leaderboards.js'],
navigation: ['./src/frontend/js/entrypoint/navigation.js'],
snowflakes: ['./src/frontend/js/entrypoint/snowflakes.js'],
newshub: ['./src/frontend/js/entrypoint/newshub.js'],
play: ['./src/frontend/js/entrypoint/play.js'],
report: ['./src/frontend/js/entrypoint/report.js'],
'clan-invite': ['./src/frontend/js/entrypoint/clan-invite.js']
'clan-invite': ['./src/frontend/js/entrypoint/clan-invite.js'],
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist/js'),
publicPath: '/dist/js',
clean: true
clean: true,
},
plugins: [
new WebpackManifestPlugin({ useEntryKeys: true })
]
plugins: [new WebpackManifestPlugin({ useEntryKeys: true })],
}