Commit c57a690b by Jason Song Committed by GitHub

Merge pull request #429 from lepdou/index_page_refactor

optimize not reload page when delete favorite app
parents a4c3f278 4edcb169
...@@ -93,7 +93,14 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi ...@@ -93,7 +93,14 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi
if (userVisitedApps && userVisitedApps.length > 0) { if (userVisitedApps && userVisitedApps.length > 0) {
AppService.find_apps(userVisitedApps.join(",")) AppService.find_apps(userVisitedApps.join(","))
.then(function (apps) { .then(function (apps) {
//sort
var appIdMapApp = {};
apps.forEach(function (app) { apps.forEach(function (app) {
appIdMapApp[app.appId] = app;
});
userVisitedApps.forEach(function (appId) {
var app = appIdMapApp[appId];
$scope.visitedApps.push(app); $scope.visitedApps.push(app);
}); });
}); });
...@@ -116,7 +123,7 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi ...@@ -116,7 +123,7 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi
function toTop(favoriteId) { function toTop(favoriteId) {
FavoriteService.toTop(favoriteId).then(function () { FavoriteService.toTop(favoriteId).then(function () {
toastr.success("置顶成功"); toastr.success("置顶成功");
reload(); refreshFavorites();
}) })
} }
...@@ -124,15 +131,16 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi ...@@ -124,15 +131,16 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi
function deleteFavorite(favoriteId) { function deleteFavorite(favoriteId) {
FavoriteService.deleteFavorite(favoriteId).then(function () { FavoriteService.deleteFavorite(favoriteId).then(function () {
toastr.success("取消收藏成功"); toastr.success("取消收藏成功");
reload(); refreshFavorites();
}) })
} }
function reload() { function refreshFavorites() {
setTimeout(function () { $scope.favoritesPage = 0;
$window.location.reload(); $scope.favorites = [];
}, 500); $scope.hasMoreFavorites = true;
getUserFavorites();
} }
} }
...@@ -61,7 +61,7 @@ function ConfigBaseInfoController($rootScope, $scope, $location, toastr, UserSer ...@@ -61,7 +61,7 @@ function ConfigBaseInfoController($rootScope, $scope, $location, toastr, UserSer
if (currentUserVisitedApps.length >= 6){ if (currentUserVisitedApps.length >= 6){
currentUserVisitedApps.splice(0, 1); currentUserVisitedApps.splice(0, 1);
} }
visitedAppsObject[$rootScope.pageContext.userId].push($rootScope.pageContext.appId); currentUserVisitedApps.push($rootScope.pageContext.appId);
localStorage.setItem(VISITED_APPS_STORAGE_KEY, localStorage.setItem(VISITED_APPS_STORAGE_KEY,
JSON.stringify(visitedAppsObject)); JSON.stringify(visitedAppsObject));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment