diff --git a/src/main/resources/site/parts/upcomingReleases/upcomingReleases.jsx b/src/main/resources/site/parts/upcomingReleases/upcomingReleases.jsx index 1175751b0..b9bb3ba03 100644 --- a/src/main/resources/site/parts/upcomingReleases/upcomingReleases.jsx +++ b/src/main/resources/site/parts/upcomingReleases/upcomingReleases.jsx @@ -5,158 +5,25 @@ import axios from 'axios' import { ChevronDown } from 'react-feather' function UpcomingReleases(props) { - const [releases, setReleases] = useState(mergeContentReleases(props.releases)) + const [releases, setReleases] = useState(props.releases) const [loading, setLoading] = useState(false) const [showAll, setShowAll] = useState(false) let lastCountedDay = undefined - const unitProps = ['year', 'month', 'day'] - - function mergeReleases(array1, array2, lvl) { - let array1Index = 0 - let array2Index = 0 - const unitProp = unitProps[lvl] - const mergedArrays = [] - while (array1Index < array1.length || array2Index < array2.length) { - const value1 = array1[array1Index] ? parseInt(array1[array1Index][unitProp]) : undefined - const value2 = array2[array2Index] ? parseInt(array2[array2Index][unitProp]) : undefined - if (value1 === value2) { - const mergedReleases = - unitProp === 'day' - ? array1[array1Index].releases.concat(array2[array2Index].releases) - : mergeReleases(array1[array1Index].releases, array2[array2Index].releases, lvl + 1) - mergedArrays.push({ - ...array1[array1Index], - releases: mergedReleases, - }) - array1Index++ - array2Index++ - } else if ((!value2 && value1) || (array1[array1Index] && value1 < value2)) { - mergedArrays.push(array1[array1Index]) - array1Index++ - } else if ((!value1 && value2) || (array2[array2Index] && value2 < value1)) { - mergedArrays.push(array2[array2Index]) - array2Index++ - } else { - array1Index++ - array2Index++ - } - } - return mergedArrays - } - - function mergeContentReleases(newReleases) { - const lastYearIndex = newReleases.length - 1 - const lastYear = newReleases[lastYearIndex] - const lastMonthIndex = lastYear.releases.length - 1 - const lastMonth = lastYear.releases[lastMonthIndex] - const lastDayIndex = lastMonth.releases.length - 1 - const lastDay = lastMonth.releases[lastDayIndex] - const last = new Date().setFullYear(lastYear.year, lastMonth.month, lastDay.day) - const contentReleases = props.contentReleases.filter((r) => { - if (new Date(r.date) <= last) { - return true - } - return false - }) - // eslint-disable-next-line complexity - contentReleases.forEach((release) => { - const releaseDate = new Date(release.date) - let yearReleases - for (let i = 0; i < newReleases.length; i += 1) { - if (newReleases[i].year < releaseDate.getFullYear() && i !== newReleases.length - 1) { - continue - } else if (newReleases[i].year == releaseDate.getFullYear()) { - yearReleases = newReleases[i] - break - } else if (newReleases[i].year > releaseDate.getFullYear() || i === newReleases.length - 1) { - yearReleases = { - year: releaseDate.getFullYear(), - releases: [ - { - month: releaseDate.getMonth(), - monthName: release.monthName, - releases: [ - { - day: releaseDate.getDate(), - releases: [], - }, - ], - }, - ], - } - newReleases.splice(i + (newReleases[i].year > releaseDate.getFullYear() ? 0 : 1), 0, yearReleases) - break - } - } - let monthReleases - for (let i = 0; i < yearReleases.releases.length; i += 1) { - if (yearReleases.releases[i].month < releaseDate.getMonth() && i !== yearReleases.releases.length - 1) { - continue - } else if (yearReleases.releases[i].month == releaseDate.getMonth()) { - monthReleases = yearReleases.releases[i] - break - } else if (yearReleases.releases[i].month > releaseDate.getMonth() || i === yearReleases.releases.length - 1) { - monthReleases = { - month: releaseDate.getMonth(), - monthName: release.monthName, - releases: [ - { - day: releaseDate.getDate(), - releases: [], - }, - ], - } - yearReleases.releases.splice( - i + (yearReleases.releases[i].month > releaseDate.getMonth() ? 0 : 1), - 0, - monthReleases - ) - break - } - } - let dayReleases - for (let i = 0; i < monthReleases.releases.length; i += 1) { - if (monthReleases.releases[i].day < releaseDate.getDate() && i !== monthReleases.releases.length - 1) { - continue - } else if (monthReleases.releases[i].day == releaseDate.getDate()) { - dayReleases = monthReleases.releases[i] - break - } else if (monthReleases.releases[i].day > releaseDate.getDate() || i === monthReleases.releases.length - 1) { - dayReleases = { - day: releaseDate.getDate(), - releases: [], - } - monthReleases.releases.splice( - i + (monthReleases.releases[i].day > releaseDate.getDate() ? 0 : 1), - 0, - dayReleases - ) - break - } - } - if (dayReleases && !dayReleases.releases.find((r) => r.id === release.id)) { - dayReleases.releases.push(release) - } - }) - return newReleases - } - function fetchAllReleases() { setLoading(true) setShowAll(true) axios .get(props.upcomingReleasesServiceUrl, { params: { - start: `${lastCountedDay.year}-${parseInt(lastCountedDay.month) + 1}-${lastCountedDay.day}`, + start: `${lastCountedDay.year}-${parseInt(lastCountedDay.month) + 1}-${parseInt(lastCountedDay.day) + 1}`, showAll: true, language: props.language, }, }) .then((res) => { if (res.data.releases.length) { - let newReleases = mergeReleases(releases, res.data.releases, 0) - newReleases = mergeContentReleases(newReleases) + const newReleases = [...releases, ...res.data.releases] setReleases(newReleases) } else { setLoading(true) @@ -250,7 +117,6 @@ function UpcomingReleases(props) { 'desember', ] const monthNameLong = monthNames[monthNumber] - return (