Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
600e5846
Commit
600e5846
authored
May 10, 2021
by
Paul Kaplan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move activity loading to studio-activity-actions, include pagination
parent
dbec1c7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
23 deletions
+61
-23
src/views/studio/lib/fetchers.js
src/views/studio/lib/fetchers.js
+0
-9
src/views/studio/lib/studio-activity-actions.js
src/views/studio/lib/studio-activity-actions.js
+43
-0
src/views/studio/studio-activity.jsx
src/views/studio/studio-activity.jsx
+18
-14
No files found.
src/views/studio/lib/fetchers.js
deleted
100644 → 0
View file @
dbec1c7a
// TODO move this to studio-activity-actions, include pagination
const
activityFetcher
=
studioId
=>
fetch
(
`
${
process
.
env
.
API_HOST
}
/studios/
${
studioId
}
/activity`
)
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
({
items
:
data
,
moreToLoad
:
false
}));
// No pagination on the activity feed
export
{
activityFetcher
};
src/views/studio/lib/studio-activity-actions.js
0 → 100644
View file @
600e5846
import
keyMirror
from
'
keymirror
'
;
import
api
from
'
../../../lib/api
'
;
import
{
activity
}
from
'
./redux-modules
'
;
import
{
selectStudioId
}
from
'
../../../redux/studio
'
;
const
Errors
=
keyMirror
({
NETWORK
:
null
,
SERVER
:
null
,
PERMISSION
:
null
});
const
normalizeError
=
(
err
,
body
,
res
)
=>
{
if
(
err
)
return
Errors
.
NETWORK
;
if
(
res
.
statusCode
===
401
||
res
.
statusCode
===
403
)
return
Errors
.
PERMISSION
;
if
(
res
.
statusCode
!==
200
)
return
Errors
.
SERVER
;
return
null
;
};
const
loadActivity
=
()
=>
((
dispatch
,
getState
)
=>
{
const
state
=
getState
();
const
studioId
=
selectStudioId
(
state
);
const
items
=
activity
.
selector
(
state
).
items
;
const
params
=
{
limit
:
20
};
if
(
items
.
length
>
0
)
{
// dateLimit is the newest notification you want to get back, which is
// the date of the oldest one we've already loaded
params
.
dateLimit
=
items
[
items
.
length
-
1
].
datetime_created
;
}
api
({
uri
:
`/studios/
${
studioId
}
/activity/`
,
params
},
(
err
,
body
,
res
)
=>
{
const
error
=
normalizeError
(
err
,
body
,
res
);
if
(
error
)
return
dispatch
(
activity
.
actions
.
error
(
error
));
const
ids
=
items
.
map
(
item
=>
item
.
id
);
// Deduplication is needed because pagination based on date can contain duplicates
const
deduped
=
body
.
filter
(
item
=>
ids
.
indexOf
(
item
.
id
)
===
-
1
);
dispatch
(
activity
.
actions
.
append
(
deduped
,
body
.
length
===
params
.
limit
));
});
});
export
{
loadActivity
};
src/views/studio/studio-activity.jsx
View file @
600e5846
...
@@ -2,20 +2,15 @@ import React, {useEffect} from 'react';
...
@@ -2,20 +2,15 @@ import React, {useEffect} from 'react';
import
PropTypes
from
'
prop-types
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
useParams
}
from
'
react-router
'
;
import
{
activity
}
from
'
./lib/redux-modules
'
;
import
{
activity
}
from
'
./lib/redux-modules
'
;
import
{
activityFetcher
}
from
'
./lib/fetcher
s
'
;
import
{
loadActivity
}
from
'
./lib/studio-activity-action
s
'
;
import
Debug
from
'
./debug.jsx
'
;
import
Debug
from
'
./debug.jsx
'
;
const
StudioActivity
=
({
items
,
loading
,
error
,
onInitialLoad
})
=>
{
const
StudioActivity
=
({
items
,
loading
,
error
,
moreToLoad
,
onLoadMore
})
=>
{
const
{
studioId
}
=
useParams
();
// Fetch the data if none has been loaded yet. This would run only once,
// since studioId doesnt change, but the component is potentially mounted
// multiple times because of tab routing, so need to check for empty items.
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
studioId
&&
items
.
length
===
0
)
onInitialLoad
(
studioId
);
if
(
items
.
length
===
0
)
onLoadMore
(
);
},
[
studioId
]);
// items.length intentionally left out
},
[
]);
return
(
return
(
<
div
>
<
div
>
...
@@ -33,6 +28,15 @@ const StudioActivity = ({items, loading, error, onInitialLoad}) => {
...
@@ -33,6 +28,15 @@ const StudioActivity = ({items, loading, error, onInitialLoad}) => {
key=
{
index
}
key=
{
index
}
/>)
/>)
)
}
)
}
<
div
>
{
loading
?
<
small
>
Loading...
</
small
>
:
(
moreToLoad
?
<
button
onClick=
{
onLoadMore
}
>
Load more
</
button
>
:
<
small
>
No more to load
</
small
>
)
}
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
);
);
...
@@ -42,13 +46,13 @@ StudioActivity.propTypes = {
...
@@ -42,13 +46,13 @@ StudioActivity.propTypes = {
items
:
PropTypes
.
array
,
// eslint-disable-line react/forbid-prop-types
items
:
PropTypes
.
array
,
// eslint-disable-line react/forbid-prop-types
loading
:
PropTypes
.
bool
,
loading
:
PropTypes
.
bool
,
error
:
PropTypes
.
object
,
// eslint-disable-line react/forbid-prop-types
error
:
PropTypes
.
object
,
// eslint-disable-line react/forbid-prop-types
onInitialLoad
:
PropTypes
.
func
moreToLoad
:
PropTypes
.
bool
,
onLoadMore
:
PropTypes
.
func
};
};
export
default
connect
(
export
default
connect
(
state
=>
activity
.
selector
(
state
),
state
=>
activity
.
selector
(
state
),
dispatch
=>
({
{
onInitialLoad
:
studioId
=>
dispatch
(
onLoadMore
:
loadActivity
activity
.
actions
.
loadMore
(
activityFetcher
.
bind
(
null
,
studioId
,
0
)))
}
})
)(
StudioActivity
);
)(
StudioActivity
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment