Commit 4edcb169 by zhangle

optimize not reload page when delete favorite app

parent a4c3f278
......@@ -93,7 +93,14 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi
if (userVisitedApps && userVisitedApps.length > 0) {
AppService.find_apps(userVisitedApps.join(","))
.then(function (apps) {
//sort
var appIdMapApp = {};
apps.forEach(function (app) {
appIdMapApp[app.appId] = app;
});
userVisitedApps.forEach(function (appId) {
var app = appIdMapApp[appId];
$scope.visitedApps.push(app);
});
});
......@@ -116,7 +123,7 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi
function toTop(favoriteId) {
FavoriteService.toTop(favoriteId).then(function () {
toastr.success("置顶成功");
reload();
refreshFavorites();
})
}
......@@ -124,15 +131,16 @@ function IndexController($scope, $window, toastr, AppUtil, AppService, UserServi
function deleteFavorite(favoriteId) {
FavoriteService.deleteFavorite(favoriteId).then(function () {
toastr.success("取消收藏成功");
reload();
refreshFavorites();
})
}
function reload() {
setTimeout(function () {
$window.location.reload();
}, 500);
function refreshFavorites() {
$scope.favoritesPage = 0;
$scope.favorites = [];
$scope.hasMoreFavorites = true;
getUserFavorites();
}
}
......@@ -61,7 +61,7 @@ function ConfigBaseInfoController($rootScope, $scope, $location, toastr, UserSer
if (currentUserVisitedApps.length >= 6){
currentUserVisitedApps.splice(0, 1);
}
visitedAppsObject[$rootScope.pageContext.userId].push($rootScope.pageContext.appId);
currentUserVisitedApps.push($rootScope.pageContext.appId);
localStorage.setItem(VISITED_APPS_STORAGE_KEY,
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