Skip to content

Commit

Permalink
User dialog group edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Nov 11, 2024
1 parent 435a2e3 commit e903b27
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 75 deletions.
126 changes: 103 additions & 23 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9362,6 +9362,7 @@ speechSynthesis.getVoices();
D.dateFriended = '';
D.unFriended = false;
D.dateFriendedInfo = [];
this.userDialogGroupEditMode = false;
if (userId === API.currentUser.id) {
this.getWorldName(API.currentUser.homeLocation).then(
(worldName) => {
Expand Down Expand Up @@ -16981,9 +16982,37 @@ speechSynthesis.getVoices();
this.saveCurrentUserGroups();
};

$app.data.inGameGroupOrder = [];

$app.methods.updateInGameGroupOrder = async function () {
this.inGameGroupOrder = [];
try {
var json = await AppApi.GetVRChatRegistryKey(
`VRC_GROUP_ORDER_${API.currentUser.id}`
);
this.inGameGroupOrder = JSON.parse(json);
} catch (err) {
console.error(err);
}
};

$app.methods.sortGroupsByInGame = function (a, b) {
var aIndex = this.inGameGroupOrder.indexOf(a?.id);
var bIndex = this.inGameGroupOrder.indexOf(b?.id);
if (aIndex === -1 && bIndex === -1) {
return 0;
}
if (aIndex === -1) {
return 1;
}
if (bIndex === -1) {
return -1;
}
return aIndex - bIndex;
};

$app.methods.sortCurrentUserGroups = async function () {
var D = this.userDialog;
var inGameGroupList = [];
var sortMethod = function () {};

switch (D.groupSorting.value) {
Expand All @@ -16994,28 +17023,8 @@ speechSynthesis.getVoices();
sortMethod = compareByMemberCount;
break;
case 'inGame':
sortMethod = function (a, b) {
var aIndex = inGameGroupList.indexOf(a?.id);
var bIndex = inGameGroupList.indexOf(b?.id);
if (aIndex === -1 && bIndex === -1) {
return 0;
}
if (aIndex === -1) {
return 1;
}
if (bIndex === -1) {
return -1;
}
return aIndex - bIndex;
};
try {
var json = await AppApi.GetVRChatRegistryKey(
`VRC_GROUP_ORDER_${API.currentUser.id}`
);
inGameGroupList = JSON.parse(json);
} catch (err) {
console.error(err);
}
sortMethod = this.sortGroupsByInGame;
await this.updateInGameGroupOrder();
break;
}

Expand All @@ -17024,6 +17033,77 @@ speechSynthesis.getVoices();
this.userGroups.remainingGroups.sort(sortMethod);
};

$app.data.userDialogGroupEditMode = false;
$app.data.userDialogGroupEditGroups = [];

$app.methods.editModeCurrentUserGroups = async function () {
await this.updateInGameGroupOrder();
this.userDialogGroupEditGroups = Array.from(
API.currentUserGroups.values()
);
this.userDialogGroupEditGroups.sort(this.sortGroupsByInGame);
this.userDialogGroupEditMode = true;
};

$app.methods.exitEditModeCurrentUserGroups = async function () {
this.userDialogGroupEditMode = false;
this.userDialogGroupEditGroups = [];
await this.sortCurrentUserGroups();
};

$app.methods.moveGroupUp = function (groupId) {
var index = this.inGameGroupOrder.indexOf(groupId);
if (index > 0) {
this.inGameGroupOrder.splice(index, 1);
this.inGameGroupOrder.splice(index - 1, 0, groupId);
this.saveInGameGroupOrder();
}
};

$app.methods.moveGroupDown = function (groupId) {
var index = this.inGameGroupOrder.indexOf(groupId);
if (index < this.inGameGroupOrder.length - 1) {
this.inGameGroupOrder.splice(index, 1);
this.inGameGroupOrder.splice(index + 1, 0, groupId);
this.saveInGameGroupOrder();
}
};

$app.methods.moveGroupTop = function (groupId) {
var index = this.inGameGroupOrder.indexOf(groupId);
if (index > 0) {
this.inGameGroupOrder.splice(index, 1);
this.inGameGroupOrder.unshift(groupId);
this.saveInGameGroupOrder();
}
};

$app.methods.moveGroupBottom = function (groupId) {
var index = this.inGameGroupOrder.indexOf(groupId);
if (index < this.inGameGroupOrder.length - 1) {
this.inGameGroupOrder.splice(index, 1);
this.inGameGroupOrder.push(groupId);
this.saveInGameGroupOrder();
}
};

$app.methods.saveInGameGroupOrder = async function () {
this.userDialogGroupEditGroups.sort(this.sortGroupsByInGame);
try {
await AppApi.SetVRChatRegistryKey(
`VRC_GROUP_ORDER_${API.currentUser.id}`,
JSON.stringify(this.inGameGroupOrder),
3
);
} catch (err) {
console.error(err);
this.$message({
message: 'Failed to save in-game group order',
type: 'error'
});
}
};

// #endregion
// #region | Gallery

Expand Down
17 changes: 17 additions & 0 deletions html/src/classes/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,23 @@ export default class extends baseClass {
});
},

leaveGroupPrompt(groupId) {
this.$confirm(
'Are you sure you want to leave this group?',
'Confirm',
{
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
this.leaveGroup(groupId);
}
}
}
);
},

cancelGroupRequest(groupId) {
return API.cancelGroupRequest({
groupId
Expand Down
5 changes: 4 additions & 1 deletion html/src/localization/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,17 @@
"header": "Groups",
"total_count": "Total {count}",
"sort_by": "Sort by:",
"edit_mode": "Edit Mode",
"exit_edit_mode": "Exit Edit Mode",
"own_groups": "Own Groups",
"mutual_groups": "Mutual Groups",
"groups": "Groups",
"sorting": {
"alphabetical": "Alphabetical",
"members": "Members",
"in_game": "In-Game Order"
}
},
"leave_group_tooltip": "Leave Group"
},
"worlds": {
"header": "Worlds",
Expand Down
Loading

0 comments on commit e903b27

Please sign in to comment.