📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix problems, added state
kruzhambusa405f49934d7
diff --git a/src/pages/Dashboard/Dashboard.container.jsx b/src/pages/Dashboard/Dashboard.container.jsxindex 2b8efc946..2a1b7ecb5 100644--- a/src/pages/Dashboard/Dashboard.container.jsx+++ b/src/pages/Dashboard/Dashboard.container.jsx@@ -9,7 +9,9 @@ const mapStateToProps = (state) => ({projects: state.ui.projects.projects,user: state.auth.user,isLoading: state.ui.projects.isLoading,+ total: state.ui.projects.total,error: state.ui.projects.error,+ curentPageRedux: state.ui.projects.curentPage,})const mapDispatchToProps = (dispatch) => ({@@ -28,6 +30,12 @@ const mapDispatchToProps = (dispatch) => ({sharedProjectError: (message) => {dispatch(errorsActions.sharedProjectFailed(message))},+ loadProjects: (take, skip) => {+ dispatch(UIActions.loadProjects(take, skip))+ },+ setCurentPageRedux: (page) => {+ dispatch(UIActions.setCurentPage(page))+ },})export default connect(mapStateToProps, mapDispatchToProps)(Dashboard)diff --git a/src/pages/Dashboard/Dashboard.jsx b/src/pages/Dashboard/Dashboard.jsxindex 9c2d6ba45..6b0644bba 100644--- a/src/pages/Dashboard/Dashboard.jsx+++ b/src/pages/Dashboard/Dashboard.jsx@@ -27,7 +27,7 @@ import routes from 'routes'import { isSelfhosted, ENTRIES_PER_PAGE_DASHBOARD } from 'redux/constants'import EventsRunningOutBanner from 'components/EventsRunningOutBanner'-import { acceptShareProject, getProjects } from 'api'+import { acceptShareProject } from 'api'import Pagination from 'ui/Pagination'@@ -171,15 +171,13 @@ const NoProjects = ({ t }) => ()const Dashboard = ({- projects, isLoading, error, user, deleteProjectFailed, setProjectsShareData, setUserShareData, userSharedUpdate, sharedProjectError,+ projects, isLoading, error, user, deleteProjectFailed, setProjectsShareData, setUserShareData, userSharedUpdate, sharedProjectError, loadProjects, total, setCurentPageRedux, curentPageRedux,}) => {const { t, i18n: { language } } = useTranslation('common')const [showActivateEmailModal, setShowActivateEmailModal] = useState(false)const history = useHistory()- const [paginationProject, setPaginationProject] = useState(projects)- const [currentPage, setCurrentPage] = useState(1)- const pageAmount = useMemo(() => Math.ceil(paginationProject.total / ENTRIES_PER_PAGE_DASHBOARD), [paginationProject])+ const pageAmount = useMemo(() => Math.ceil(total / ENTRIES_PER_PAGE_DASHBOARD), [total])const onNewProject = () => {if (user.isActive || isSelfhosted) {@@ -190,18 +188,9 @@ const Dashboard = ({}useEffect(() => {- getProjects(ENTRIES_PER_PAGE_DASHBOARD, (currentPage - 1) * ENTRIES_PER_PAGE_DASHBOARD)- .then((res) => {- const { results } = res-- if (!_isEmpty(results)) {- setPaginationProject({ ...res })- }- })- .catch((e) => {- console.log(e)- })- }, [currentPage])+ loadProjects(ENTRIES_PER_PAGE_DASHBOARD, (curentPageRedux - 1) * ENTRIES_PER_PAGE_DASHBOARD)+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [curentPageRedux])if (error && !isLoading) {return (@@ -242,7 +231,7 @@ const Dashboard = ({) : (<div className='shadow overflow-hidden sm:rounded-md mt-10'><ul className='divide-y divide-gray-200 dark:divide-gray-500'>- {_map(_filter(paginationProject.results, ({ uiHidden }) => !uiHidden), ({+ {_map(_filter(projects, ({ uiHidden }) => !uiHidden), ({name, id, created, active, overall, live, public: isPublic, confirmed, shared,}) => (<div key={confirmed ? `${id}-confirmed` : id}>@@ -289,12 +278,13 @@ const Dashboard = ({</ul></div>)}++ {+ pageAmount > 1 && (+ <Pagination page={curentPageRedux} setPage={(page) => setCurentPageRedux(page)} pageAmount={pageAmount || 0} />+ )+ }</div>- {- pageAmount > 1 && (- <Pagination page={currentPage} setPage={(page) => setCurrentPage(page)} pageAmount={pageAmount || 0} />- )- }</div></div><Modal@@ -329,6 +319,10 @@ Dashboard.propTypes = {setUserShareData: PropTypes.func.isRequired,sharedProjectError: PropTypes.func.isRequired,userSharedUpdate: PropTypes.func.isRequired,+ loadProjects: PropTypes.func.isRequired,+ total: PropTypes.number.isRequired,+ setCurentPageRedux: PropTypes.func.isRequired,+ curentPageRedux: PropTypes.number.isRequired,}Dashboard.defaultProps = {diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.jsindex f3d257ac9..431d6a234 100644--- a/src/redux/actions/ui/index.js+++ b/src/redux/actions/ui/index.js@@ -1,7 +1,8 @@import { types } from './types'-const loadProjects = () => ({+const loadProjects = (take, skip) => ({type: types.LOAD_PROJECTS,+ payload: { take, skip },})const setProjects = (projects) => ({@@ -18,6 +19,20 @@ const setTotalMonthlyEvents = (totalMonthlyEvents) => ({},})+const setTotal = (total) => ({+ type: types.SET_TOTAL,+ payload: {+ total,+ },+})++const setCurentPage = (page) => ({+ type: types.SET_CURENT_PAGE,+ payload: {+ page,+ },+})+const setShowNoEventsLeftBanner = (showNoEventsLeftBanner) => ({type: types.SET_SHOW_NO_EVENTS_LEFT,payload: {@@ -138,6 +153,8 @@ const UIActions = {setGeneralStats,setPaddleLastEvent,setTotalMonthlyEvents,+ setCurentPage,+ setTotal,setShowNoEventsLeftBanner,setProjectsShareData,shareVerifyAsync,diff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.jsindex bcee83b78..8684dccc5 100644--- a/src/redux/actions/ui/types.js+++ b/src/redux/actions/ui/types.js@@ -14,6 +14,8 @@ export const types = {SET_GENERAL_STATS: 'UI_SET_GENERAL_STATS',SET_PADDLE_LAST_EVENT: 'UI_SET_PADDLE_LAST_EVENT',SET_TOTAL_MONTHLY_EVENTS: 'UI_SET_TOTAL_MONTHLY_EVENTS',+ SET_TOTAL: 'UI_SET_TOTAL',+ SET_CURENT_PAGE: 'UI_SET_CURENT_PAGE',SET_SHOW_NO_EVENTS_LEFT: 'UI_SET_SHOW_NO_EVENTS_LEFT',SET_PROJECTS_SHARE_DATA: 'UI_SET_PROJECTS_SHARE_DATA',SHARE_VERIFY_ASYNC: 'UI_SHARE_VERIFY_ASYNC',diff --git a/src/redux/constants/index.js b/src/redux/constants/index.jsindex d3b7b9b8f..79ae7d319 100644--- a/src/redux/constants/index.js+++ b/src/redux/constants/index.js@@ -165,4 +165,4 @@ export const roleAdmin = {}export const INVITATION_EXPIRES_IN = 48 // hours-export const ENTRIES_PER_PAGE_DASHBOARD = 5+export const ENTRIES_PER_PAGE_DASHBOARD = 4diff --git a/src/redux/reducers/ui/projects.js b/src/redux/reducers/ui/projects.jsindex 68d01f968..23ea79756 100644--- a/src/redux/reducers/ui/projects.js+++ b/src/redux/reducers/ui/projects.js@@ -9,6 +9,8 @@ const getInitialState = () => {isLoading: true,error: null,totalMonthlyEvents: null,+ total: 0,+ curentPage: 1,}}@@ -24,6 +26,14 @@ const projectsReducer = (state = getInitialState(), { type, payload }) => {}}+ case types.SET_CURENT_PAGE: {+ const { page } = payload+ return {+ ...state,+ curentPage: page,+ }+ }+case types.SET_TOTAL_MONTHLY_EVENTS: {const { totalMonthlyEvents } = payloadreturn {@@ -32,6 +42,14 @@ const projectsReducer = (state = getInitialState(), { type, payload }) => {}}+ case types.SET_TOTAL: {+ const { total } = payload+ return {+ ...state,+ total,+ }+ }+case types.SET_LIVE_STATS: {const { data } = payloaddiff --git a/src/redux/sagas/ui/load_projects.js b/src/redux/sagas/ui/load_projects.jsindex 5c42e4924..322565df7 100644--- a/src/redux/sagas/ui/load_projects.js+++ b/src/redux/sagas/ui/load_projects.js@@ -4,16 +4,22 @@ import _isString from 'lodash/isString'import Debug from 'debug'import UIActions from 'redux/actions/ui'++import { ENTRIES_PER_PAGE_DASHBOARD } from 'redux/constants'import {getProjects, getOverallStats, getLiveVisitors,} from '../../../api'const debug = Debug('swetrix:rx:s:load-projects')-export default function* loadProjects() {+export default function* loadProjects({ payload: { take = ENTRIES_PER_PAGE_DASHBOARD, skip = 0 } }) {try {- // eslint-disable-next-line prefer-const- let { results, totalMonthlyEvents, shared } = yield call(getProjects)+ yield put(UIActions.setProjectsLoading(true))++ let {+ // eslint-disable-next-line prefer-const+ results, totalMonthlyEvents, shared, total,+ } = yield call(getProjects, take, skip)const projectWithShared = [..._map(shared, (item) => {return {shared: true,@@ -38,6 +44,7 @@ export default function* loadProjects() {yield put(UIActions.setProjects(results))yield put(UIActions.setTotalMonthlyEvents(totalMonthlyEvents))+ yield put(UIActions.setTotal(total))const liveStats = yield call(getLiveVisitors, pids)yield put(UIActions.setLiveStats(liveStats))diff --git a/src/ui/Pagination.jsx b/src/ui/Pagination.jsxindex 70b387483..3c5fe5e30 100644--- a/src/ui/Pagination.jsx+++ b/src/ui/Pagination.jsx@@ -4,22 +4,47 @@ import _map from 'lodash/map'import cx from 'clsx'const Pagination = ({ page, setPage, pageAmount }) => {- console.log(page, pageAmount)return (<nav className='border-t border-gray-200 px-4 flex items-center justify-between sm:px-0'><div className='-mt-px w-0 flex-1 flex'>- <button- type='button'- onClick={() => setPage(page - 1)}- className='border-t-2 border-transparent pt-4 pr-1 inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300'- >- <ArrowNarrowLeftIcon className='mr-3 h-5 w-5 text-gray-400' aria-hidden='true' />- Previous- </button>+ {+ page > 1 && (+ <button+ type='button'+ onClick={() => setPage(page - 1)}+ className='border-t-2 border-transparent pt-4 pr-1 inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300'+ >+ <ArrowNarrowLeftIcon className='mr-3 h-5 w-5 text-gray-400' aria-hidden='true' />+ Previous+ </button>+ )+ }</div><div className='hidden md:-mt-px md:flex'>{_map(Array(pageAmount), (_, index) => {+ // if (pageAmount > 6 && Math.ceil(pageAmount / 2) + page === index && page < pageAmount - 3 && page !== pageAmount) {+ // return (+ // <span className='border-transparent text-gray-500 border-t-2 pt-4 px-4 inline-flex items-center text-sm font-medium' key={index}>+ // true+ // </span>+ // )+ // }++ // if (pageAmount > 6 && Math.ceil(pageAmount / 2) + page === index && page < pageAmount - 3 && page !== pageAmount) {+ // return (+ // <span className='border-transparent text-gray-500 border-t-2 pt-4 px-4 inline-flex items-center text-sm font-medium' key={index}>+ // false+ // </span>+ // )+ // }++ // if (index >= pageAmount && index < pageAmount - 3) {+ // return (+ // <div className='sr-only' key={index} />+ // )+ // }+return (<buttonkey={index}@@ -35,19 +60,20 @@ const Pagination = ({ page, setPage, pageAmount }) => {)})}- {/* <span className='border-transparent text-gray-500 border-t-2 pt-4 px-4 inline-flex items-center text-sm font-medium'>- ...- </span> */}</div><div className='-mt-px w-0 flex-1 flex justify-end'>- <button- type='button'- onClick={() => setPage(page + 1)}- className='border-t-2 border-transparent pt-4 pl-1 inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300'- >- Next- <ArrowNarrowRightIcon className='ml-3 h-5 w-5 text-gray-400' aria-hidden='true' />- </button>+ {+ page !== pageAmount && (+ <button+ type='button'+ onClick={() => setPage(page + 1)}+ className='border-t-2 border-transparent pt-4 pl-1 inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300'+ >+ Next+ <ArrowNarrowRightIcon className='ml-3 h-5 w-5 text-gray-400' aria-hidden='true' />+ </button>+ )+ }</div></nav>)