import React from 'react'; import { filter } from 'lodash'; import { Link } from 'react-router-dom'; import axios from '../../axios/axios'; import { ContentContainer } from '../../components'; import './realms.scss'; import header_realmforums from '../../assets/header-realmforums.gif'; import realms_large from '../../assets/realms-large.gif'; interface Props {} interface State { realms: Realm[]; } interface Realm { id: number; category: string; title: string; } export class Realms extends React.Component { constructor(props: Props) { super(props); this.state = { realms: [], }; } async componentDidMount() { try { const res = await axios.get('/api/category'); const realms = filter(res.data.data, { category: 'realm' }); this.setState({ realms }); } catch (e) { console.error(e); } } private renderRealms(realms: Realm[]): any { return realms.map((realm) => { return (
  • {realm.title}
  • ); }); } render() { const { realms } = this.state; // copy list so we don't modify state const realmsCopy = realms.slice(); // split realms into 3 lists const list1 = realmsCopy.splice(0, realmsCopy.length / 3); const list2 = realmsCopy.splice(0, realmsCopy.length / 2); const list3 = realmsCopy; return realms.length === 0 ?
    : (
    Welcome to the World of Warcraft Realm Forums!
    Use these forums to discuss topics related to World of Warcraft with player on your own Realm.
      {this.renderRealms(list1)}
      {this.renderRealms(list2)}
      {this.renderRealms(list3)}
    ); } }