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
7812d163
Commit
7812d163
authored
Oct 13, 2015
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify the code for updating the focused group when session state changes
parent
0d0e47ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
15 deletions
+8
-15
groups.js
h/static/scripts/groups.js
+8
-15
No files found.
h/static/scripts/groups.js
View file @
7812d163
...
...
@@ -48,9 +48,10 @@ function groups(localStorage, session, $rootScope, features, $http) {
url
:
baseURI
+
'groups/'
+
id
+
'/leave'
,
});
// TODO - Optimistically call remove() to
// remove the group locally when
// https://github.com/hypothesis/h/pull/2587 has been merged
// the groups list will be updated in response to a session state
// change notification from the server. We could improve the UX here
// by optimistically updating the session state
return
response
;
};
...
...
@@ -65,12 +66,7 @@ function groups(localStorage, session, $rootScope, features, $http) {
}
else
if
(
features
.
flagEnabled
(
'groups'
))
{
var
fromStorage
=
get
(
localStorage
.
getItem
(
STORAGE_KEY
));
if
(
fromStorage
)
{
var
matches
=
all
().
filter
(
function
(
group
)
{
return
group
.
id
===
fromStorage
.
id
;
});
if
(
matches
.
length
>
0
)
{
focusedGroup
=
matches
[
0
];
}
focusedGroup
=
fromStorage
;
return
focusedGroup
;
}
}
...
...
@@ -80,7 +76,7 @@ function groups(localStorage, session, $rootScope, features, $http) {
/** Set the group with the passed id as the currently focused group. */
function
focus
(
id
)
{
var
g
=
get
(
id
);
if
(
typeof
g
!==
'undefined'
)
{
if
(
g
)
{
focusedGroup
=
g
;
localStorage
.
setItem
(
STORAGE_KEY
,
g
.
id
);
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
g
.
id
);
...
...
@@ -90,11 +86,8 @@ function groups(localStorage, session, $rootScope, features, $http) {
// reset the focused group if the user leaves it
$rootScope
.
$on
(
events
.
SESSION_CHANGED
,
function
()
{
if
(
focusedGroup
)
{
var
match
=
session
.
state
.
groups
.
filter
(
function
(
group
)
{
return
group
.
id
===
focusedGroup
.
id
;
});
if
(
match
.
length
===
0
)
{
focusedGroup
=
null
;
focusedGroup
=
get
(
focusedGroup
.
id
);
if
(
!
focusedGroup
)
{
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
focused
());
}
}
...
...
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