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
Show 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) {
...
@@ -48,9 +48,10 @@ function groups(localStorage, session, $rootScope, features, $http) {
url
:
baseURI
+
'groups/'
+
id
+
'/leave'
,
url
:
baseURI
+
'groups/'
+
id
+
'/leave'
,
});
});
// TODO - Optimistically call remove() to
// the groups list will be updated in response to a session state
// remove the group locally when
// change notification from the server. We could improve the UX here
// https://github.com/hypothesis/h/pull/2587 has been merged
// by optimistically updating the session state
return
response
;
return
response
;
};
};
...
@@ -65,12 +66,7 @@ function groups(localStorage, session, $rootScope, features, $http) {
...
@@ -65,12 +66,7 @@ function groups(localStorage, session, $rootScope, features, $http) {
}
else
if
(
features
.
flagEnabled
(
'groups'
))
{
}
else
if
(
features
.
flagEnabled
(
'groups'
))
{
var
fromStorage
=
get
(
localStorage
.
getItem
(
STORAGE_KEY
));
var
fromStorage
=
get
(
localStorage
.
getItem
(
STORAGE_KEY
));
if
(
fromStorage
)
{
if
(
fromStorage
)
{
var
matches
=
all
().
filter
(
function
(
group
)
{
focusedGroup
=
fromStorage
;
return
group
.
id
===
fromStorage
.
id
;
});
if
(
matches
.
length
>
0
)
{
focusedGroup
=
matches
[
0
];
}
return
focusedGroup
;
return
focusedGroup
;
}
}
}
}
...
@@ -80,7 +76,7 @@ function groups(localStorage, session, $rootScope, features, $http) {
...
@@ -80,7 +76,7 @@ function groups(localStorage, session, $rootScope, features, $http) {
/** Set the group with the passed id as the currently focused group. */
/** Set the group with the passed id as the currently focused group. */
function
focus
(
id
)
{
function
focus
(
id
)
{
var
g
=
get
(
id
);
var
g
=
get
(
id
);
if
(
typeof
g
!==
'undefined'
)
{
if
(
g
)
{
focusedGroup
=
g
;
focusedGroup
=
g
;
localStorage
.
setItem
(
STORAGE_KEY
,
g
.
id
);
localStorage
.
setItem
(
STORAGE_KEY
,
g
.
id
);
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
g
.
id
);
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
g
.
id
);
...
@@ -90,11 +86,8 @@ function groups(localStorage, session, $rootScope, features, $http) {
...
@@ -90,11 +86,8 @@ function groups(localStorage, session, $rootScope, features, $http) {
// reset the focused group if the user leaves it
// reset the focused group if the user leaves it
$rootScope
.
$on
(
events
.
SESSION_CHANGED
,
function
()
{
$rootScope
.
$on
(
events
.
SESSION_CHANGED
,
function
()
{
if
(
focusedGroup
)
{
if
(
focusedGroup
)
{
var
match
=
session
.
state
.
groups
.
filter
(
function
(
group
)
{
focusedGroup
=
get
(
focusedGroup
.
id
);
return
group
.
id
===
focusedGroup
.
id
;
if
(
!
focusedGroup
)
{
});
if
(
match
.
length
===
0
)
{
focusedGroup
=
null
;
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
focused
());
$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