Files
habitica/website/client/src/components/groups/group.vue
T
SabreCat e9e4265545 Squashed commit of the following:
commit 00affb306655a543f5d29b3af6361e686b577a97
Author: SabreCat <sabe@habitica.com>
Date:   Tue May 2 09:47:25 2023 -0500

    fix(tests): account for invite limit changes

commit 47661117f9fd661b8bc8f63b7cc7c8d5f8fa0fd7
Author: SabreCat <sabe@habitica.com>
Date:   Mon May 1 17:39:29 2023 -0500

    fix(lfp): final polish

commit 6a1e5af1db0dd90be3ced7e223f53c9183a206f5
Merge: 728ed2ddad 9e0777bb42
Author: SabreCat <sabe@habitica.com>
Date:   Mon May 1 16:54:12 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit 728ed2ddad7f0962d28f1ab0a271e3555b19296c
Author: SabreCat <sabe@habitica.com>
Date:   Thu Apr 27 16:51:06 2023 -0500

    fix(lfp): loading layout and page visit event

commit 8a56ab329bff922e05963e3ef78fbc26ff273924
Author: SabreCat <sabe@habitica.com>
Date:   Wed Apr 26 16:54:46 2023 -0500

    fix(faq): copy and style updates

commit 6fd00d7f30150a1802e5a37edbb914ef120caf9a
Author: SabreCat <sabe@habitica.com>
Date:   Fri Apr 21 17:12:52 2023 -0500

    feat(lfp): fixes, analytics, FAQ

commit 4b5d7304ad7cfc5f72320b23456ed2898e53caac
Author: SabreCat <sabe@habitica.com>
Date:   Mon Apr 17 15:13:03 2023 -0500

    fix(lfp): smol tweaks

commit 9a5476a2558eb17a603f4aae1b5b2d35773be8b4
Author: SabreCat <sabe@habitica.com>
Date:   Thu Apr 13 16:03:33 2023 -0500

    feat(lfp): refresh button

commit aa58f5018469f38a9a9d31c3bffa26bb88a8c672
Merge: bbb03d006e c8adf20804
Author: SabreCat <sabe@habitica.com>
Date:   Tue Apr 11 17:44:56 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit bbb03d006e8b122bb7206bdc778a31de422167bb
Author: SabreCat <sabe@habitica.com>
Date:   Tue Apr 4 18:30:50 2023 -0500

    fix(lint): whitespace and const

commit 23683ad29a4cce0b0da061ad6c030982034c0a9c
Author: SabreCat <sabe@habitica.com>
Date:   Tue Apr 4 17:02:57 2023 -0500

    chore(LFP): add analytics
    also re-fix loading state

commit 4477d84f5266c87f5583368029b72153f00f0568
Author: SabreCat <sabe@habitica.com>
Date:   Mon Apr 3 16:24:26 2023 -0500

    fix(LFP): address issues with loading

commit bdc5154f24bb5e50963376c3c0c9cc73c0b05ccc
Merge: 81923eef6f 229ed46425
Author: SabreCat <sabe@habitica.com>
Date:   Mon Apr 3 15:58:12 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit 81923eef6f0c627d079475a28f9d93d8e4628934
Author: SabreCat <sabe@habitica.com>
Date:   Thu Mar 30 16:44:49 2023 -0500

    feat(LFP): release candidate

commit fe1f8939fc6b09d36cfaf0b6e5838df04e41009d
Author: SabreCat <sabe@habitica.com>
Date:   Wed Mar 29 17:35:54 2023 -0500

    WIP(LFP): fixes

commit afc361f5a9f806cbd814ad910d1274e3a6609efd
Merge: d6b5cbdebc 7ede3acd01
Author: SabreCat <sabe@habitica.com>
Date:   Wed Mar 29 16:24:39 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit d6b5cbdebc2829e9325ea57fb5deeccc128c1635
Author: SabreCat <sabe@habitica.com>
Date:   Tue Mar 28 16:13:18 2023 -0500

    WIP(LFP): change copy, add close X, fix API response

commit 4274a4625862351ef0ecf33c8a3249ca5ebec7cb
Author: SabreCat <sabe@habitica.com>
Date:   Mon Mar 27 17:07:36 2023 -0500

    fix(LFP): layout, unset when stopping

commit 95abfcfa5f13c9cce6385206947a47f85b76d11d
Merge: 4a360eedd8 53c536b525
Author: SabreCat <sabe@habitica.com>
Date:   Mon Mar 27 16:32:46 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit 4a360eedd8b9cf41d3a0fe7a4cfaa72c5bd7bd26
Author: SabreCat <sabe@habitica.com>
Date:   Thu Mar 23 16:54:49 2023 -0500

    feat(LFP): completed style and infinite scroll

commit bbc439d9d03c9631a450236eb33af66f0428fa50
Author: SabreCat <sabe@habitica.com>
Date:   Tue Mar 21 10:40:26 2023 -0500

    WIP(LFP): nicer layout, buffs fix

commit 1658688597456663477ab19da61ae1b9bc85cf2a
Merge: 664507434f 027e61a93e
Author: SabreCat <sabe@habitica.com>
Date:   Tue Mar 21 09:29:02 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit 664507434f2f76e6bf3b61cdc9e3daddb81204af
Author: SabreCat <sabe@habitica.com>
Date:   Fri Mar 17 17:13:08 2023 -0500

    WIP(LFP): API and client adjustments

commit 2f0b6f2517f9e2d634cb23ee303cfb4542e998ce
Merge: 0db1704325 a16098ccda
Author: SabreCat <sabe@habitica.com>
Date:   Fri Mar 17 16:45:13 2023 -0500

    Merge branch 'release' into sabrecat/party-seeking

commit 0db1704325c3555f0b5d9c8d1dfc44177e90c093
Author: SabreCat <sabe@habitica.com>
Date:   Mon Mar 13 14:48:10 2023 -0500

    fix(modal): scrollbar for squashed viewports

commit 733c35192e0a4e31e1bebfdd7488cfc1f7587f36
Author: SabreCat <sabe@habitica.com>
Date:   Thu Mar 9 12:51:02 2023 -0600

    WIP(party): seekers functional rough

commit d4b854410b557db26eec6e6a26b6d174c02cee3a
Merge: 7fe919825a 0b6b967753
Author: SabreCat <sabe@habitica.com>
Date:   Thu Mar 9 10:07:28 2023 -0600

    Merge branch 'release' into sabrecat/party-seeking

commit 7fe919825abfb6d518cb93b91f5997d3831bd0b5
Author: SabreCat <sabe@habitica.com>
Date:   Thu Mar 2 14:40:09 2023 -0600

    feat(party): several adjustments to seeking feature

commit c93900efcf925f7aaa4c4cb56b4451f19adfb1b3
Author: SabreCat <sabe@habitica.com>
Date:   Wed Mar 1 20:37:11 2023 -0600

    feat(party): initial Seeking API

commit 8bb784daeceb14c23992a6f3af1054a900fc26c1
Merge: e19a661a21 f327795761
Author: SabreCat <sabe@habitica.com>
Date:   Wed Mar 1 18:58:20 2023 -0600

    Merge branch 'release' into sabrecat/party-seeking

commit e19a661a2163a50307a286379bffb44201ed392e
Author: SabreCat <sabe@habitica.com>
Date:   Fri Feb 24 15:51:42 2023 -0600

    WIP(parties): add seeking flag and modal toggle
2023-05-02 09:51:33 -05:00

562 lines
15 KiB
Vue

<template>
<div
v-if="group._id"
class="row"
>
<group-form-modal v-if="isParty" />
<quest-detail-modal :group="group" />
<participant-list-modal :group="group" />
<invitation-list-modal :group="group" />
<group-gems-modal />
<div class="col-12 col-sm-8 standard-page">
<div class="row">
<div class="col-12 col-md-6 title-details">
<h1>{{ group.name }}</h1>
<div>
<span class="mr-1 ml-0">
<strong v-once>{{ $t('groupLeader') }}:</strong>
<user-link
class="mx-1"
:user="group.leader"
/>
</span>
</div>
</div>
<div class="col-12 col-md-6">
<div class="row icon-row">
<div
class="item-with-icon"
tabindex="0"
role="button"
@keyup.enter="showMemberModal()"
@click="showMemberModal()"
>
<div
v-if="group.memberCount > 1000"
class="svg-icon shield"
v-html="icons.goldGuildBadgeIcon"
></div>
<div
v-if="group.memberCount > 100 && group.memberCount < 999"
class="svg-icon shield"
v-html="icons.silverGuildBadgeIcon"
></div>
<div
v-if="group.memberCount < 100"
class="svg-icon shield"
v-html="icons.bronzeGuildBadgeIcon"
></div>
<span class="number">{{ group.memberCount | abbrNum }}</span>
<div
v-once
class="member-list label"
>
{{ $t('memberList') }}
</div>
</div>
<div v-if="!isParty">
<div
class="item-with-icon"
tabindex="0"
role="button"
@keyup.enter="showGroupGems()"
@click="showGroupGems()"
>
<div
class="svg-icon gem"
v-html="icons.gem"
></div>
<span class="number">{{ group.balance * 4 }}</span>
<div
v-once
class="label"
>
{{ $t('guildBank') }}
</div>
</div>
</div>
</div>
</div>
</div>
<chat
:label="$t('chat')"
:group="group"
:placeholder="!isParty ? $t('chatPlaceholder') : $t('partyChatPlaceholder')"
@fetchRecentMessages="fetchRecentMessages()"
>
<template slot="additionRow">
<div
v-if="showNoNotificationsMessage"
class="row"
>
<div class="col-12 no-notifications">
{{ $t('groupNoNotifications') }}
</div>
</div>
</template>
</chat>
</div>
<right-sidebar
:is-admin="isAdmin"
:is-leader="isLeader"
:is-member="isMember"
:is-party="isParty"
:group="group"
:search-id="searchId"
class="col-12 col-sm-4"
@leave="clickLeave()"
@join="join()"
@messageLeader="messageLeader()"
@upgradeGroup="upgradeGroup"
@updateGuild="updateGuild"
@showInviteModal="showInviteModal()"
/>
</div>
</template>
<style lang="scss" scoped>
@import '~@/assets/scss/colors.scss';
@media (min-width: 1300px) {
.standard-page {
max-width: calc(100% - 430px);
}
}
h1 {
color: $purple-200;
}
.item-with-icon {
border-radius: 2px;
background-color: #ffffff;
box-shadow: 0 2px 2px 0 rgba(26, 24, 29, 0.16), 0 1px 4px 0 rgba(26, 24, 29, 0.12);
padding: 1em;
text-align: center;
min-width: 120px;
height: 76px;
margin-right: 1rem;
&:last-of-type {
margin-left: 0.5rem;
}
.svg-icon.shield, .svg-icon.gem {
width: 28px;
height: auto;
margin: 0 auto;
display: inline-block;
vertical-align: bottom;
margin-right: 0.5em;
}
.number {
font-size: 22px;
font-weight: bold;
}
.label {
margin-top: .5em;
}
}
.item-with-icon:hover {
cursor: pointer;
}
.buttons-wrapper {
padding: 2.8em 24px 0em 24px;
}
.card {
margin: 2em 0;
padding: 1em;
h3.leader {
color: $purple-200;
}
.text {
font-size: 16px;
line-height: 1.43;
color: $gray-50;
}
}
textarea {
height: 150px;
width: 100%;
background-color: $white;
border: solid 1px $gray-400;
font-size: 16px;
line-height: 1.43;
color: $gray-300;
padding: .5em;
}
textarea::-webkit-input-placeholder { /* Chrome/Opera/Safari */
font-style: italic;
}
textarea::-moz-placeholder { /* Firefox 19+ */
font-style: italic;
}
textarea:-ms-input-placeholder { /* IE 10+ */
font-style: italic;
}
textarea:-moz-placeholder { /* Firefox 18- */
font-style: italic;
}
.title-details {
padding-top: 1em;
padding-left: 1em;
}
.icon-row {
margin-top: 1em;
justify-content: flex-end;
.number {
font-size: 22px;
font-weight: bold;
}
}
.chat-row {
margin-top: 2em;
.new-message-row {
position: relative;
}
.chat-actions {
margin-top: 1em;
.chat-receive-actions {
padding-left: 0;
button {
margin-bottom: 1em;
&:not(:last-child) {
margin-right: 1em;
}
}
}
.chat-send-actions {
padding-right: 0;
}
}
}
span.action {
font-size: 14px;
line-height: 1.33;
color: $gray-200;
font-weight: 500;
margin-right: 1em;
}
span.action .icon {
margin-right: .3em;
}
.hr {
width: 100%;
height: 20px;
border-bottom: 1px solid $gray-500;
text-align: center;
margin: 2em 0;
}
.no-notifications {
border-radius: 4px;
border: solid 1px $orange-10;
padding: 1em;
margin-top: 3em;
text-align: center;
font-size: 14px;
font-weight: bold;
color: $orange-50;
}
</style>
<script>
// @TODO: Break this down into components
import extend from 'lodash/extend';
import groupUtilities from '@/mixins/groupsUtilities';
import styleHelper from '@/mixins/styleHelper';
import { mapGetters } from '@/libs/store';
import * as Analytics from '@/libs/analytics';
import participantListModal from './participantListModal';
import groupFormModal from './groupFormModal';
import groupGemsModal from '@/components/groups/groupGemsModal';
import markdownDirective from '@/directives/markdown';
import chat from './chat';
import userLink from '../userLink';
import deleteIcon from '@/assets/svg/delete.svg';
import copyIcon from '@/assets/svg/copy.svg';
import likeIcon from '@/assets/svg/like.svg';
import likedIcon from '@/assets/svg/liked.svg';
import reportIcon from '@/assets/svg/report.svg';
import gemIcon from '@/assets/svg/gem.svg';
import questIcon from '@/assets/svg/quest.svg';
import questBackground from '@/assets/svg/quest-background-border.svg';
import goldGuildBadgeIcon from '@/assets/svg/gold-guild-badge-small.svg';
import silverGuildBadgeIcon from '@/assets/svg/silver-guild-badge-small.svg';
import bronzeGuildBadgeIcon from '@/assets/svg/bronze-guild-badge-small.svg';
import QuestDetailModal from './questDetailModal';
import RightSidebar from '@/components/groups/rightSidebar';
import InvitationListModal from './invitationListModal';
import { PAGES } from '@/libs/consts';
import { userStateMixin } from '../../mixins/userState';
export default {
components: {
InvitationListModal,
QuestDetailModal,
RightSidebar,
groupFormModal,
participantListModal,
groupGemsModal,
userLink,
chat,
},
directives: {
markdown: markdownDirective,
},
mixins: [groupUtilities, styleHelper, userStateMixin],
props: ['groupId'],
data () {
return {
searchId: '',
group: {},
icons: Object.freeze({
like: likeIcon,
copy: copyIcon,
report: reportIcon,
delete: deleteIcon,
gem: gemIcon,
liked: likedIcon,
questIcon,
questBackground,
goldGuildBadgeIcon,
silverGuildBadgeIcon,
bronzeGuildBadgeIcon,
}),
members: [],
membersLoaded: false,
selectedQuest: {},
chat: {
submitDisable: false,
submitTimeout: null,
},
};
},
computed: {
...mapGetters({
partyMembers: 'party:members',
}),
partyStore () {
return this.$store.state.party;
},
isParty () {
return this.$route.path.startsWith('/party');
},
isLeader () {
return this.user._id === this.group.leader._id;
},
isAdmin () {
return Boolean(this.hasPermission(this.user, 'moderator'));
},
isMember () {
return this.isMemberOfGroup(this.user, this.group);
},
showNoNotificationsMessage () {
return this.group.memberCount > this.$store.state.constants.LARGE_GROUP_COUNT_MESSAGE_CUTOFF;
},
},
watch: {
// call again the method if the route changes (when this route is already active)
$route: 'fetchGuild',
partyStore () {
if (this.$store.state.party._id) {
this.group = this.$store.state.party;
} else {
this.group = null;
this.$router.push('/');
}
},
},
async mounted () {
if (this.isParty) this.searchId = 'party';
if (!this.searchId) this.searchId = this.groupId;
await this.fetchGuild();
const type = this.isParty ? 'party' : 'guilds';
this.$store.dispatch('common:setTitle', {
section: this.$route.path.startsWith('/group-plans') ? this.$t('groupPlans') : this.$t(type),
subSection: this.group.name,
});
this.$root.$on('updatedGroup', this.onGroupUpdate);
},
beforeDestroy () {
this.$root.$off('updatedGroup', this.onGroupUpdate);
},
beforeRouteUpdate (to, from, next) {
this.$set(this, 'searchId', to.params.groupId);
next();
},
methods: {
acceptCommunityGuidelines () {
this.$store.dispatch('user:set', { 'flags.communityGuidelinesAccepted': true });
},
onGroupUpdate (group) {
const updatedGroup = extend(this.group, group);
this.$set(this.group, updatedGroup);
const type = this.isParty ? 'party' : 'guilds';
this.$store.dispatch('common:setTitle', {
section: this.$route.path.startsWith('/group-plans') ? this.$t('groupPlans') : this.$t(type),
subSection: group.name,
});
},
/**
* Method for loading members of a group, with optional parameters for
* modifying requests.
*
* @param {Object} payload Used for modifying requests for members
*/
loadMembers (payload = null) {
// Remove unnecessary data
if (payload && payload.challengeId) {
delete payload.challengeId;
}
return this.$store.dispatch('members:getGroupMembers', payload);
},
showMemberModal () {
this.$store.state.memberModalOptions.loading = true;
if (this.isParty) {
this.membersLoaded = true;
this.members = this.partyMembers;
this.$store.state.memberModalOptions.loading = false;
} else if (!this.membersLoaded) {
this.membersLoaded = true;
this.loadMembers({
groupId: this.group._id,
includeAllPublicFields: true,
}).then(m => {
this.members.push(...m);
this.$store.state.memberModalOptions.loading = false;
});
} else {
this.$store.state.memberModalOptions.loading = false;
}
this.$root.$emit('habitica:show-member-modal', {
groupId: this.group._id,
group: this.group,
memberCount: this.group.memberCount,
viewingMembers: this.members,
fetchMoreMembers: this.loadMembers,
});
},
fetchRecentMessages () {
this.fetchGuild();
},
updateGuild () {
this.$store.state.editingGroup = this.group;
this.$root.$emit('bv::show::modal', 'guild-form');
},
showInviteModal () {
this.$root.$emit('inviteModal::inviteToGroup', this.group); // This event listener is initiated in ../header/index.vue
},
async fetchGuild () {
if (this.searchId === 'party' && !this.user.party._id) {
this.$root.$emit('bv::show::modal', 'create-party-modal');
return;
}
if (this.isParty) {
await this.$store.dispatch('party:getParty', true);
this.group = this.$store.state.party.data;
this.$store.dispatch('common:setTitle', {
section: this.$route.path.startsWith('/group-plans') ? this.$t('groupPlans') : this.$t('party'),
subSection: this.group.name,
});
} else {
const group = await this.$store.dispatch('guilds:getGroup', { groupId: this.searchId });
this.$set(this, 'group', group);
this.$store.dispatch('common:setTitle', {
section: this.$route.path.startsWith('/group-plans') ? this.$t('groupPlans') : this.$t('guilds'),
subSection: group.name,
});
}
const groupId = this.searchId === 'party' ? this.user.party._id : this.searchId;
if (this.hasUnreadMessages(groupId)) {
const notification = this.user
.notifications.find(n => n.type === 'NEW_CHAT_MESSAGE' && n.data.group.id === groupId);
const notificationId = notification && notification.id;
this.$store.dispatch('chat:markChatSeen', { groupId, notificationId });
}
},
// returns the notification id or false
hasUnreadMessages (groupId) {
if (this.user.newMessages[groupId]) return true;
return this.user.notifications.some(n => n.type === 'NEW_CHAT_MESSAGE' && n.data.group.id === groupId);
},
async join () {
if (this.group.cancelledPlan && !window.confirm(this.$t('aboutToJoinCancelledGroupPlan'))) { // eslint-disable-line no-alert
return;
}
await this.$store.dispatch('guilds:join', { groupId: this.group._id, type: 'guild' });
},
clickLeave () {
// @TODO: Get challenges and ask to keep or remove
if (!window.confirm('Are you sure you want to leave?')) return; // eslint-disable-line no-alert
const keep = true;
this.leave(keep);
},
async leave (keepTasks) {
const keepChallenges = 'remain-in-challenges';
const data = {
groupId: this.group._id,
keep: keepTasks,
keepChallenges,
};
if (this.isParty) {
data.type = 'party';
Analytics.updateUser({ partySize: null, partyID: null });
this.$store.state.partyMembers = [];
}
await this.$store.dispatch('guilds:leave', data);
if (this.isParty) {
await this.$router.push({ name: 'tasks' });
window.location.reload(true);
}
},
upgradeGroup () {
this.$store.state.upgradingGroup = this.group;
this.$router.push('/group-plans');
},
showGroupGems () {
this.$root.$emit('bv::show::modal', 'group-gems-modal');
},
messageLeader () {
window.open(`${PAGES.PRIVATE_MESSAGES}?uuid=${this.group.leader.id}`);
},
},
};
</script>