mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-10 06:06:24 +08:00
fixes global activities
This commit is contained in:
parent
6ef19725f1
commit
2e83322f76
7 changed files with 48 additions and 28 deletions
1
.babelrc
1
.babelrc
|
|
@ -15,6 +15,7 @@
|
||||||
"react"
|
"react"
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
"transform-object-rest-spread",
|
||||||
"syntax-dynamic-import",
|
"syntax-dynamic-import",
|
||||||
[
|
[
|
||||||
"transform-class-properties",
|
"transform-class-properties",
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,24 @@
|
||||||
module ClientApi
|
module ClientApi
|
||||||
class ActivitiesController < ApplicationController
|
class ActivitiesController < ApplicationController
|
||||||
include ActivityHelper
|
|
||||||
before_action :load_vars
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@per_page =
|
|
||||||
@activities = current_user.last_activities(@last_activity_id,
|
|
||||||
Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render template: '/client_api/activities/index',
|
render template: '/client_api/activities/index',
|
||||||
status: :ok,
|
status: :ok,
|
||||||
locals: { activities: @activities }
|
locals: activities_vars
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_vars
|
def activities_vars
|
||||||
@last_activity_id = params[:from].to_i || 0
|
last_activity_id = params[:from].to_i || 0
|
||||||
@last_activity = Activity.find_by_id(@last_activity_id)
|
per_page = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT
|
||||||
|
activities = current_user.last_activities(last_activity_id, per_page + 1)
|
||||||
|
more = activities.length > per_page
|
||||||
|
{ activities: activities, more: more }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,14 @@ class GlobalActivitiesModal extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
displayActivities() {
|
displayActivities() {
|
||||||
console.log(this.props.global_activities);
|
if (this.props.activities.length === 0) {
|
||||||
if (this.props.global_activities.length === 0) {
|
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<FormattedMessage id="activities.no_data" />
|
<FormattedMessage id="activities.no_data" />
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this.props.global_activities.map((activity, i, arr) => {
|
return this.props.activities.map((activity, i, arr) => {
|
||||||
let newDate = new Date(activity.created_at);
|
let newDate = new Date(activity.created_at);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
let prevDate = new Date(arr[i - 1].created_at);
|
let prevDate = new Date(arr[i - 1].created_at);
|
||||||
|
|
@ -46,13 +45,12 @@ class GlobalActivitiesModal extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
addMoreActivities() {
|
addMoreActivities() {
|
||||||
let last_id = _.last(this.props.global_activities).id;
|
let last_id = _.last(this.props.activities).id;
|
||||||
this.props.fetchActivities(last_id);
|
this.props.fetchActivities(last_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
addMoreButton() {
|
addMoreButton() {
|
||||||
console.log(this.props.more_global_activities);
|
if (this.props.more) {
|
||||||
if(this.props.more_global_activities) {
|
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<Button onClick={this.addMoreActivities}>
|
<Button onClick={this.addMoreActivities}>
|
||||||
|
|
@ -91,8 +89,8 @@ GlobalActivitiesModal.propTypes = {
|
||||||
showModal: PropTypes.bool.isRequired,
|
showModal: PropTypes.bool.isRequired,
|
||||||
onCloseModal: PropTypes.func.isRequired,
|
onCloseModal: PropTypes.func.isRequired,
|
||||||
fetchActivities: PropTypes.func.isRequired,
|
fetchActivities: PropTypes.func.isRequired,
|
||||||
more_global_activities: PropTypes.bool.isRequired,
|
more: PropTypes.bool.isRequired,
|
||||||
global_activities: PropTypes.arrayOf(
|
activities: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
id: PropTypes.number.isRequired,
|
id: PropTypes.number.isRequired,
|
||||||
message: PropTypes.string.isRequired,
|
message: PropTypes.string.isRequired,
|
||||||
|
|
@ -101,8 +99,9 @@ GlobalActivitiesModal.propTypes = {
|
||||||
).isRequired
|
).isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = ({ global_activities, more_global_activities }) => {
|
const mapStateToProps = ({ global_activities }) => {
|
||||||
return { global_activities, more_global_activities };
|
let { activities, more } = global_activities;
|
||||||
|
return { activities, more };
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,19 @@ import {
|
||||||
MORE_GLOBAL_ACTIVITIES
|
MORE_GLOBAL_ACTIVITIES
|
||||||
} from "../actions/types";
|
} from "../actions/types";
|
||||||
|
|
||||||
export function globalActivities(state = [], action) {
|
export function globalActivities(
|
||||||
|
state = { more: true, activities: [] },
|
||||||
|
action
|
||||||
|
) {
|
||||||
if (action.type === GLOBAL_ACTIVITIES_DATA) {
|
if (action.type === GLOBAL_ACTIVITIES_DATA) {
|
||||||
return Object.assign([], state, action.payload, {
|
return {
|
||||||
last_payload: () => action.payload.lenght < 10
|
...state,
|
||||||
});
|
activities: [
|
||||||
|
...state.activities,
|
||||||
|
...action.payload.global_activities.activities
|
||||||
|
],
|
||||||
|
more: action.payload.global_activities.more
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
json.array! activities do |activity|
|
json.global_activities do
|
||||||
json.id activity.id
|
json.more more
|
||||||
json.message activity.message
|
json.activities activities do |activity|
|
||||||
json.created_at activity.created_at
|
json.id activity.id
|
||||||
|
json.message activity.message
|
||||||
|
json.created_at activity.created_at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
"babel-loader": "7.x",
|
"babel-loader": "7.x",
|
||||||
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
||||||
"babel-plugin-transform-class-properties": "^6.24.1",
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||||
|
"babel-plugin-transform-object-rest-spread": "^6.23.0",
|
||||||
"babel-polyfill": "^6.23.0",
|
"babel-polyfill": "^6.23.0",
|
||||||
"babel-preset-env": "^1.6.0",
|
"babel-preset-env": "^1.6.0",
|
||||||
"babel-preset-react": "^6.24.1",
|
"babel-preset-react": "^6.24.1",
|
||||||
|
|
|
||||||
11
yarn.lock
11
yarn.lock
|
|
@ -478,6 +478,10 @@ babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
|
||||||
version "6.18.0"
|
version "6.18.0"
|
||||||
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
|
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
|
||||||
|
|
||||||
|
babel-plugin-syntax-object-rest-spread@^6.8.0:
|
||||||
|
version "6.13.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"
|
||||||
|
|
||||||
babel-plugin-syntax-trailing-function-commas@^6.22.0:
|
babel-plugin-syntax-trailing-function-commas@^6.22.0:
|
||||||
version "6.22.0"
|
version "6.22.0"
|
||||||
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3"
|
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3"
|
||||||
|
|
@ -682,6 +686,13 @@ babel-plugin-transform-flow-strip-types@^6.22.0:
|
||||||
babel-plugin-syntax-flow "^6.18.0"
|
babel-plugin-syntax-flow "^6.18.0"
|
||||||
babel-runtime "^6.22.0"
|
babel-runtime "^6.22.0"
|
||||||
|
|
||||||
|
babel-plugin-transform-object-rest-spread@^6.23.0:
|
||||||
|
version "6.23.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.23.0.tgz#875d6bc9be761c58a2ae3feee5dc4895d8c7f921"
|
||||||
|
dependencies:
|
||||||
|
babel-plugin-syntax-object-rest-spread "^6.8.0"
|
||||||
|
babel-runtime "^6.22.0"
|
||||||
|
|
||||||
babel-plugin-transform-react-display-name@^6.23.0:
|
babel-plugin-transform-react-display-name@^6.23.0:
|
||||||
version "6.25.0"
|
version "6.25.0"
|
||||||
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-display-name/-/babel-plugin-transform-react-display-name-6.25.0.tgz#67e2bf1f1e9c93ab08db96792e05392bf2cc28d1"
|
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-display-name/-/babel-plugin-transform-react-display-name-6.25.0.tgz#67e2bf1f1e9c93ab08db96792e05392bf2cc28d1"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue