Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
09a1ccaa
Commit
09a1ccaa
authored
Apr 07, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing types to groups store module
parent
cf104119
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
25 deletions
+30
-25
groups.js
src/sidebar/store/modules/groups.js
+30
-25
No files found.
src/sidebar/store/modules/groups.js
View file @
09a1ccaa
import
{
createSelector
}
from
'reselect'
;
import
*
as
util
from
'../util'
;
import
{
createStoreModule
}
from
'../create-store'
;
import
{
createStoreModule
,
makeAction
}
from
'../create-store'
;
import
{
sessionModule
}
from
'./session'
;
...
...
@@ -35,6 +34,10 @@ const initialState = {
/** @typedef {typeof initialState} State */
const
reducers
=
{
/**
* @param {State} state
* @param {{ filteredGroupIds: string[] }} action
*/
FILTER_GROUPS
(
state
,
action
)
{
if
(
!
action
.
filteredGroupIds
?.
length
)
{
return
{
...
...
@@ -62,6 +65,10 @@ const reducers = {
};
},
/**
* @param {State} state
* @param {{ id: string }} action
*/
FOCUS_GROUP
(
state
,
action
)
{
const
group
=
state
.
groups
.
find
(
g
=>
g
.
id
===
action
.
id
);
if
(
!
group
)
{
...
...
@@ -73,6 +80,10 @@ const reducers = {
return
{
focusedGroupId
:
action
.
id
};
},
/**
* @param {State} state
* @param {{ groups: Group[] }} action
*/
LOAD_GROUPS
(
state
,
action
)
{
const
groups
=
action
.
groups
;
let
focusedGroupId
=
state
.
focusedGroupId
;
...
...
@@ -104,12 +115,8 @@ const reducers = {
},
};
const
actions
=
util
.
actionTypes
(
reducers
);
function
clearGroups
()
{
return
{
type
:
actions
.
CLEAR_GROUPS
,
};
return
makeAction
(
reducers
,
'CLEAR_GROUPS'
,
undefined
);
}
/**
...
...
@@ -118,10 +125,7 @@ function clearGroups() {
* @param {Group["id"][]} filteredGroupIds
*/
function
filterGroups
(
filteredGroupIds
)
{
return
{
type
:
actions
.
FILTER_GROUPS
,
filteredGroupIds
,
};
return
makeAction
(
reducers
,
'FILTER_GROUPS'
,
{
filteredGroupIds
});
}
/**
...
...
@@ -130,10 +134,7 @@ function filterGroups(filteredGroupIds) {
* @param {string} id
*/
function
focusGroup
(
id
)
{
return
{
type
:
actions
.
FOCUS_GROUP
,
id
,
};
return
makeAction
(
reducers
,
'FOCUS_GROUP'
,
{
id
});
}
/**
...
...
@@ -142,16 +143,13 @@ function focusGroup(id) {
* @param {Group[]} groups
*/
function
loadGroups
(
groups
)
{
return
{
type
:
actions
.
LOAD_GROUPS
,
groups
,
};
return
makeAction
(
reducers
,
'LOAD_GROUPS'
,
{
groups
});
}
/**
* Return the currently focused group.
*
* @
return {Group|undefined|null}
* @
param {State} state
*/
function
focusedGroup
(
state
)
{
if
(
!
state
.
focusedGroupId
)
{
...
...
@@ -163,7 +161,7 @@ function focusedGroup(state) {
/**
* Return the current focused group ID or `null`.
*
* @
return {string|null}
* @
param {State} state
*/
function
focusedGroupId
(
state
)
{
return
state
.
focusedGroupId
;
...
...
@@ -172,7 +170,7 @@ function focusedGroupId(state) {
/**
* Return the list of all groups, ignoring any filter present.
*
* @
return {Group[]}
* @
param {State} state
*/
function
allGroups
(
state
)
{
return
state
.
groups
;
...
...
@@ -200,8 +198,8 @@ function filteredGroupIds(state) {
/**
* Return the group with the given ID.
*
* @param {State} state
* @param {string} id
* @return {Group|undefined}
*/
function
getGroup
(
state
,
id
)
{
return
state
.
groups
.
find
(
g
=>
g
.
id
===
id
);
...
...
@@ -229,12 +227,17 @@ const getInScopeGroups = createSelector(
// Selectors that receive root state.
/**
* @typedef {{ groups: State, session: SessionState }} RootState
*/
/**
* Return groups the logged in user is a member of.
*/
const
getMyGroups
=
createSelector
(
/** @param {
{ groups: State, session: SessionState }
} rootState */
/** @param {
RootState
} rootState */
rootState
=>
filteredGroups
(
rootState
.
groups
),
/** @param {RootState} rootState */
rootState
=>
sessionModule
.
selectors
.
isLoggedIn
(
rootState
.
session
),
(
groups
,
loggedIn
)
=>
{
// If logged out, the Public group still has isMember set to true so only
...
...
@@ -250,9 +253,11 @@ const getMyGroups = createSelector(
* Return groups that don't show up in Featured and My Groups.
*/
const
getCurrentlyViewingGroups
=
createSelector
(
/** @param {
{ groups: State, session: SessionState }
} rootState */
/** @param {
RootState
} rootState */
rootState
=>
filteredGroups
(
rootState
.
groups
),
/** @param {RootState} rootState */
rootState
=>
getMyGroups
(
rootState
),
/** @param {RootState} rootState */
rootState
=>
getFeaturedGroups
(
rootState
.
groups
),
(
allGroups
,
myGroups
,
featuredGroups
)
=>
{
return
allGroups
.
filter
(
...
...
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