mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
Merge pull request #7621 from crookedneighbor/party_page
Fetch Party when going to party page
This commit is contained in:
commit
17b6999c81
7 changed files with 40 additions and 20 deletions
|
|
@ -36,7 +36,7 @@
|
|||
"invitedToNewParty": "You were invited to join a party! Do you want to leave this party and join <%= partyName %>?",
|
||||
"joinNewParty": "Join New Party",
|
||||
"declineInvitation": "Decline Invitation",
|
||||
"loadingNewParty": "Your new party is loading. Please wait...",
|
||||
"loadingNewParty": "Your party is loading. Please wait...",
|
||||
"newMsg": "New message in \"<%= name %>\"",
|
||||
"chat": "Chat",
|
||||
"sendChat": "Send Chat",
|
||||
|
|
|
|||
|
|
@ -48,12 +48,15 @@ describe("Party Controller", function() {
|
|||
inject(function(_$state_) {
|
||||
var state = _$state_;
|
||||
sandbox.stub(state, 'is').returns(true);
|
||||
|
||||
var syncParty = sinon.stub(groups.Group, 'syncParty')
|
||||
syncParty.returns(Promise.resolve(groupResponse));
|
||||
|
||||
var froceSyncParty = sinon.stub(groups, 'party')
|
||||
froceSyncParty.returns(Promise.resolve(groupResponse));
|
||||
|
||||
$controller('PartyCtrl', { $scope: scope, $state: state, User: User });
|
||||
// @TODO: I have update the party ctrl to sync the user whenever it is called rather than only on the party page
|
||||
// Since I have cached the promise, this should not be a performance issue, but let's keep this test here in case anything breaks.
|
||||
// expect(state.is).to.be.calledOnce; // ensure initialization worked as desired
|
||||
expect(state.is).to.be.calledOnce;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -48,14 +48,13 @@ habitrpg.controller('InviteToGroupCtrl', ['$scope', '$rootScope', 'User', 'Group
|
|||
.then(function() {
|
||||
Notification.text(window.env.t('invitationsSent'));
|
||||
_resetInvitees();
|
||||
var redirectTo = '/#/options/groups/'
|
||||
if ($scope.group.type === 'party') {
|
||||
redirectTo += 'party';
|
||||
} else {
|
||||
redirectTo += ('guilds/' + $scope.group._id);
|
||||
Groups.removePartyCache();
|
||||
$rootScope.$state.go('options.social.party');
|
||||
return;
|
||||
}
|
||||
|
||||
$rootScope.hardRedirect(redirectTo);
|
||||
$rootScope.hardRedirect('/#/options/groups/guilds/' + $scope.group._id);
|
||||
}, function(){
|
||||
_resetInvitees();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,17 +7,25 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
|||
|
||||
$scope.type = 'party';
|
||||
$scope.text = window.env.t('party');
|
||||
$scope.group = {loadingParty: true}
|
||||
|
||||
$scope.inviteOrStartParty = Groups.inviteOrStartParty;
|
||||
$scope.loadWidgets = Social.loadWidgets;
|
||||
|
||||
Groups.Group.syncParty()
|
||||
.then(function successCallback(group) {
|
||||
$rootScope.party = $scope.group = group;
|
||||
checkForNotifications();
|
||||
}, function errorCallback(response) {
|
||||
$rootScope.party = $scope.group = $scope.newGroup = { type: 'party' };
|
||||
});
|
||||
function handlePartyResponse (group) {
|
||||
$rootScope.party = $scope.group = group;
|
||||
checkForNotifications();
|
||||
}
|
||||
|
||||
function handlePartyError (response) {
|
||||
$rootScope.party = $scope.group = $scope.newGroup = { type: 'party' };
|
||||
}
|
||||
|
||||
if ($state.is('options.social.party') && $rootScope.party && $rootScope.party.id) {
|
||||
Groups.party(true).then(handlePartyResponse, handlePartyError);
|
||||
} else {
|
||||
Groups.Group.syncParty().then(handlePartyResponse, handlePartyError);
|
||||
}
|
||||
|
||||
function checkForNotifications () {
|
||||
// Checks if user's party has reached 2 players for the first time.
|
||||
|
|
@ -40,6 +48,8 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
|||
}
|
||||
|
||||
$scope.create = function(group) {
|
||||
group.loadingParty = true;
|
||||
|
||||
if (!group.name) group.name = env.t('possessiveParty', {name: User.user.profile.name});
|
||||
Groups.Group.create(group)
|
||||
.then(function(response) {
|
||||
|
|
@ -134,7 +144,7 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
|
|||
Groups.Group.leave(Groups.data.party._id, false)
|
||||
.then(function() {
|
||||
$rootScope.party = $scope.group = {
|
||||
loadingNewParty: true
|
||||
loadingParty: true
|
||||
};
|
||||
$scope.join({ id: newPartyId, name: newPartyName });
|
||||
});
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ angular.module('habitrpg')
|
|||
//On page load, multiple controller request the party.
|
||||
//So, we cache the promise until the first result is returned
|
||||
var _cachedPartyPromise;
|
||||
|
||||
function party (forceUpdate) {
|
||||
if (_cachedPartyPromise && !forceUpdate) return _cachedPartyPromise.promise;
|
||||
_cachedPartyPromise = $q.defer();
|
||||
|
|
@ -150,6 +151,10 @@ angular.module('habitrpg')
|
|||
return _cachedPartyPromise.promise;
|
||||
}
|
||||
|
||||
function removePartyCache () {
|
||||
_cachedPartyPromise = null;
|
||||
}
|
||||
|
||||
function publicGuilds () {
|
||||
var deferred = $q.defer();
|
||||
|
||||
|
|
@ -207,8 +212,10 @@ angular.module('habitrpg')
|
|||
|
||||
function inviteOrStartParty (group) {
|
||||
Analytics.track({'hitType':'event','eventCategory':'button','eventAction':'click','eventLabel':'Invite Friends'});
|
||||
|
||||
if (group.type === "party" || $location.$$path === "/options/groups/party") {
|
||||
group.type = 'party';
|
||||
|
||||
$rootScope.openModal('invite-party', {
|
||||
controller:'InviteToGroupCtrl',
|
||||
resolve: {
|
||||
|
|
@ -227,6 +234,7 @@ angular.module('habitrpg')
|
|||
myGuilds: myGuilds,
|
||||
tavern: tavern,
|
||||
inviteOrStartParty: inviteOrStartParty,
|
||||
removePartyCache: removePartyCache,
|
||||
|
||||
data: data,
|
||||
Group: Group,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
include ../../shared/avatar/generated_avatar
|
||||
|
||||
script(type='text/ng-template', id='partials/options.social.party.html')
|
||||
div(ng-if='group.loadingNewParty')
|
||||
div(ng-if='group.loadingParty')
|
||||
include ./party/loading-new-party
|
||||
|
||||
div(ng-if='group._id')
|
||||
include ./party/leave-party-and-join-another
|
||||
include ./group
|
||||
|
||||
div(ng-if='!group._id && !group.loadingNewParty')
|
||||
div(ng-if='!group._id && !group.loadingParty')
|
||||
include ./party/party-invitation
|
||||
include ./party/start-a-party
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@
|
|||
|
||||
.row.row-margin
|
||||
.btn.btn-primary(ng-click='inviteOrStartParty(group)')=env.t('inviteFriendsNow')
|
||||
.btn.btn-default(ng-click='create(newGroup); group.loadingNewParty = true')=env.t('inviteFriendsLater')
|
||||
.btn.btn-default(ng-click='create(newGroup)')=env.t('inviteFriendsLater')
|
||||
.btn.btn-default(ng-click='openModal("user-id",{track:"Join Existing Party"})')=env.t('joinExistingParty')
|
||||
|
|
|
|||
Loading…
Reference in a new issue