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
cd0ab5db
Unverified
Commit
cd0ab5db
authored
Mar 22, 2021
by
Paul Kaplan
Committed by
GitHub
Mar 22, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5164 from paulkaplan/studio-roles
Fetch studio info and roles in redux
parents
a087ac4f
57495259
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
162 additions
and
24 deletions
+162
-24
src/redux/studio.js
src/redux/studio.js
+120
-0
src/views/studio/lib/fetchers.js
src/views/studio/lib/fetchers.js
+0
-4
src/views/studio/studio-info.jsx
src/views/studio/studio-info.jsx
+38
-19
src/views/studio/studio.jsx
src/views/studio/studio.jsx
+4
-1
No files found.
src/redux/studio.js
0 → 100644
View file @
cd0ab5db
const
keyMirror
=
require
(
'
keymirror
'
);
const
api
=
require
(
'
../lib/api
'
);
const
log
=
require
(
'
../lib/log
'
);
const
Status
=
keyMirror
({
FETCHED
:
null
,
NOT_FETCHED
:
null
,
FETCHING
:
null
,
ERROR
:
null
});
const
getInitialState
=
()
=>
({
infoStatus
:
Status
.
NOT_FETCHED
,
title
:
''
,
description
:
''
,
openToAll
:
false
,
commentingAllowed
:
false
,
thumbnail
:
''
,
followers
:
0
,
rolesStatus
:
Status
.
NOT_FETCHED
,
manager
:
false
,
curator
:
false
,
follower
:
false
,
invited
:
false
});
const
studioReducer
=
(
state
,
action
)
=>
{
if
(
typeof
state
===
'
undefined
'
)
{
state
=
getInitialState
();
}
switch
(
action
.
type
)
{
case
'
SET_INFO
'
:
return
{
...
state
,
...
action
.
info
};
case
'
SET_ROLES
'
:
return
{
...
state
,
...
action
.
roles
};
case
'
SET_FETCH_STATUS
'
:
if
(
action
.
error
)
{
log
.
error
(
action
.
error
);
}
return
{
...
state
,
[
action
.
fetchType
]:
action
.
fetchStatus
};
default
:
return
state
;
}
};
const
setFetchStatus
=
(
fetchType
,
fetchStatus
,
error
)
=>
({
type
:
'
SET_FETCH_STATUS
'
,
fetchType
,
fetchStatus
,
error
});
const
setInfo
=
info
=>
({
type
:
'
SET_INFO
'
,
info
:
info
});
const
setRoles
=
roles
=>
({
type
:
'
SET_ROLES
'
,
roles
:
roles
});
const
getInfo
=
studioId
=>
(
dispatch
=>
{
dispatch
(
setFetchStatus
(
'
infoStatus
'
,
Status
.
FETCHING
));
api
({
uri
:
`/studios/
${
studioId
}
`
},
(
err
,
body
,
res
)
=>
{
if
(
err
||
typeof
body
===
'
undefined
'
||
res
.
statusCode
!==
200
)
{
dispatch
(
setFetchStatus
(
'
infoStatus
'
,
Status
.
ERROR
,
err
));
return
;
}
dispatch
(
setFetchStatus
(
'
infoStatus
'
,
Status
.
FETCHED
));
dispatch
(
setInfo
({
title
:
body
.
title
,
description
:
body
.
description
,
openToAll
:
body
.
open_to_all
,
commentingAllowed
:
body
.
commenting_allowed
,
updated
:
new
Date
(
body
.
history
.
modified
),
followers
:
body
.
stats
.
followers
}));
});
});
const
getRoles
=
(
studioId
,
username
,
token
)
=>
(
dispatch
=>
{
dispatch
(
setFetchStatus
(
'
rolesStatus
'
,
Status
.
FETCHING
));
api
({
uri
:
`/studios/
${
studioId
}
/users/
${
username
}
`
,
authentication
:
token
},
(
err
,
body
,
res
)
=>
{
if
(
err
||
typeof
body
===
'
undefined
'
||
res
.
statusCode
!==
200
)
{
dispatch
(
setFetchStatus
(
'
rolesStatus
'
,
Status
.
ERROR
,
err
));
return
;
}
dispatch
(
setFetchStatus
(
'
rolesStatus
'
,
Status
.
FETCHED
));
dispatch
(
setRoles
({
manager
:
body
.
manager
,
curator
:
body
.
curator
,
following
:
body
.
following
,
invited
:
body
.
invited
}));
});
});
module
.
exports
=
{
getInitialState
,
studioReducer
,
Status
,
getInfo
,
getRoles
};
src/views/studio/lib/fetchers.js
View file @
cd0ab5db
const
ITEM_LIMIT
=
4
;
const
ITEM_LIMIT
=
4
;
const
infoFetcher
=
studioId
=>
fetch
(
`
${
process
.
env
.
API_HOST
}
/studios/
${
studioId
}
`
)
.
then
(
response
=>
response
.
json
());
const
projectFetcher
=
(
studioId
,
offset
)
=>
const
projectFetcher
=
(
studioId
,
offset
)
=>
fetch
(
`
${
process
.
env
.
API_HOST
}
/studios/
${
studioId
}
/projects?limit=
${
ITEM_LIMIT
}
&offset=
${
offset
}
`
)
fetch
(
`
${
process
.
env
.
API_HOST
}
/studios/
${
studioId
}
/projects?limit=
${
ITEM_LIMIT
}
&offset=
${
offset
}
`
)
.
then
(
response
=>
response
.
json
())
.
then
(
response
=>
response
.
json
())
...
@@ -25,7 +22,6 @@ const activityFetcher = studioId =>
...
@@ -25,7 +22,6 @@ const activityFetcher = studioId =>
export
{
export
{
activityFetcher
,
activityFetcher
,
infoFetcher
,
projectFetcher
,
projectFetcher
,
curatorFetcher
,
curatorFetcher
,
managerFetcher
managerFetcher
...
...
src/views/studio/studio-info.jsx
View file @
cd0ab5db
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useEffect
}
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
useParams
}
from
'
react-router-dom
'
;
import
{
useParams
}
from
'
react-router-dom
'
;
import
{
infoFetcher
}
from
'
./lib/fetchers
'
;
import
{
connect
}
from
'
react-redux
'
;
import
Debug
from
'
./debug.jsx
'
;
import
Debug
from
'
./debug.jsx
'
;
import
{
getInfo
,
getRoles
}
from
'
../../redux/studio
'
;
const
StudioInfo
=
()
=>
{
const
StudioInfo
=
(
{
username
,
studio
,
token
,
onLoadInfo
,
onLoadRoles
}
)
=>
{
const
{
studioId
}
=
useParams
();
const
{
studioId
}
=
useParams
();
const
[
state
,
setState
]
=
useState
({
loading
:
false
,
error
:
null
,
data
:
null
});
// Since this data is in a component that is always visible, it doesn't necessarily
useEffect
(()
=>
{
// Load studio info after first render
// need to be kept in redux. One alternative is to use the infinite-list redux
if
(
studioId
)
onLoadInfo
(
studioId
);
// module and just treat the studio info as the first and only item in the list.
useEffect
(()
=>
{
if
(
!
studioId
)
return
;
infoFetcher
(
studioId
)
.
then
(
data
=>
setState
({
loading
:
false
,
error
:
null
,
data
}))
.
catch
(
error
=>
setState
({
loading
:
false
,
error
,
data
:
null
}));
},
[
studioId
]);
},
[
studioId
]);
useEffect
(()
=>
{
// Load roles info once the username is available
if
(
studioId
&&
username
&&
token
)
onLoadRoles
(
studioId
,
username
,
token
);
},
[
studioId
,
username
,
token
]);
return
(
return
(
<
div
>
<
div
>
<
h2
>
Studio Info
</
h2
>
<
h2
>
Studio Info
</
h2
>
{
state
.
loading
&&
<
div
>
Loading..
</
div
>
}
{
state
.
error
&&
<
Debug
label=
"Error"
data=
{
state
.
error
}
/>
}
<
Debug
<
Debug
label=
"Studio Info"
label=
"Studio Info"
data=
{
st
ate
.
data
}
data=
{
st
udio
}
/>
/>
</
div
>
</
div
>
);
);
};
};
export
default
StudioInfo
;
StudioInfo
.
propTypes
=
{
username
:
PropTypes
.
string
,
token
:
PropTypes
.
string
,
studio
:
PropTypes
.
shape
({
// Fill this in as the data is used, just for demo now
}),
onLoadInfo
:
PropTypes
.
func
,
onLoadRoles
:
PropTypes
.
func
};
export
default
connect
(
state
=>
{
const
user
=
state
.
session
.
session
.
user
;
return
{
studio
:
state
.
studio
,
username
:
user
&&
user
.
username
,
token
:
user
&&
user
.
token
};
},
dispatch
=>
({
onLoadInfo
:
studioId
=>
dispatch
(
getInfo
(
studioId
)),
onLoadRoles
:
(
studioId
,
username
,
token
)
=>
dispatch
(
getRoles
(
studioId
,
username
,
token
))
})
)(
StudioInfo
);
src/views/studio/studio.jsx
View file @
cd0ab5db
...
@@ -24,6 +24,8 @@ import {
...
@@ -24,6 +24,8 @@ import {
activity
activity
}
from
'
./lib/redux-modules
'
;
}
from
'
./lib/redux-modules
'
;
const
{
studioReducer
}
=
require
(
'
../../redux/studio
'
);
const
StudioShell
=
()
=>
{
const
StudioShell
=
()
=>
{
const
match
=
useRouteMatch
();
const
match
=
useRouteMatch
();
...
@@ -72,6 +74,7 @@ render(
...
@@ -72,6 +74,7 @@ render(
[
projects
.
key
]:
projects
.
reducer
,
[
projects
.
key
]:
projects
.
reducer
,
[
curators
.
key
]:
curators
.
reducer
,
[
curators
.
key
]:
curators
.
reducer
,
[
managers
.
key
]:
managers
.
reducer
,
[
managers
.
key
]:
managers
.
reducer
,
[
activity
.
key
]:
activity
.
reducer
[
activity
.
key
]:
activity
.
reducer
,
studio
:
studioReducer
}
}
);
);
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