Skip to content
Snippets Groups Projects
Commit 0e3a9aef authored by Titus Netland's avatar Titus Netland
Browse files

My communities

parent 25498281
No related branches found
No related tags found
No related merge requests found
Pipeline #180535 passed
<template> <template>
<div> <!-- My communities, with pagination -->
<div id="myGroups"> <div v-if="loggedIn">
<div>Mine grupper:</div> <div class="flex flex-row p-4 relative">
<group-list :groupList="myGroups" /> <div class="text-xl md:text-2xl text-gray-600 font-medium w-full">
Mine grupper
</div>
<UserAddIcon
class="cursor-pointer max-h-6 max-w-6 float-right grow text-primary-dark"
@click="$router.push('/newCommunity')"
alt="Opprett ny gruppe"
/>
</div>
<CommunityList :communities="visibleMyCommunities" :member="true"/>
<!-- pagination my communities -->
<div class="flex justify-center">
<PaginationTemplate
v-bind:items="myCommunities"
v-on:page:update="updatePageMyCommunities"
v-bind:currentPage="currentPageMyCommunities"
v-bind:pageSize="pageSizeMyCommunities"
class="mt-10 mb-5"
/>
</div> </div>
</div> </div>
<!-- Public communities, with search and pagination -->
<p class="text-xl md:text-2xl text-gray-600 font-medium w-full p-4">
Offentlige grupper
</p>
<!-- Search field -->
<div class="relative mt-1 mx-2" id="searchComponent">
<span class="absolute inset-y-0 left-0 flex items-center pl-3">
<div class="w-5 h-5 text-gray-400">
<SearchIcon/>
</div>
</span>
<input
type="text"
id="searchInput"
class="w-full py-3 pl-10 pr-4 text-gray-700 bg-white border rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-primary-medium dark:focus:border-primary-medium focus:outline-none focus:ring"
placeholder="Search"
v-model="search"
@change="searchWritten"
/>
</div>
<!-- Public communities list, two lists, one for when it's searched and one for pagination -->
<!-- pagination Public communities -->
</template> </template>
<script> <script>
import GroupList from "@/components/CommunityComponents/CommunityList.vue"; import CommunityList from "@/components/CommunityComponents/CommunityList.vue";
import { getMyGroups } from "@/utils/apiutil"; import {UserAddIcon, SearchIcon} from "@heroicons/vue/outline";
import PaginationTemplate from "@/components/BaseComponents/PaginationTemplate";
import CommunityService from "@/services/community.service";
export default { export default {
name: "HomeView",
data() { data() {
return { return {
myGroups: [], loggedIn: false,
myCommunities: [],
search: "",
showSearched: false,
showPaginated: true,
//Variables connected to pagination
currentPageMyCommunities: 0,
pageSizeMyCommunities: 5,
visibleMyCommunities: [],
}; };
}, },
components: { components: {
GroupList, CommunityList,
UserAddIcon,
PaginationTemplate,
SearchIcon,
}, },
methods: { methods: {
async getMyGroups() { //Pagination
this.myGroups = await getMyGroups(); updatePageMyCommunities(pageNumber) {
this.currentPageMyCommunities = pageNumber;
this.updateVisibleCommunities();
},
updateVisibleCommunities() {
this.visibleMyCommunities = this.myCommunities.slice(
this.currentPageMyCommunities * this.pageSizeMyCommunities,
this.currentPageMyCommunities * this.pageSizeMyCommunities +
this.pageSizeMyCommunities
);
// if we have 0 visible communities, go back a page
if (
this.visibleMyCommunities.length === 0 &&
this.currentPageMyCommunities > 0
) {
this.updatePageMyCommunities(this.currentPageMyCommunities - 1);
}
},
searchWritten() {
//This method triggers when search input field is changed
this.showPaginated = this.search.length < 1;
this.showSearched = this.search.length > 0;
},
async load() {
this.loggedIn = this.$store.state.user.token !== null;
if (!this.loggedIn) return;
this.myCommunities = await CommunityService.getUserCommunities();
}, },
},
beforeMount() {
this.getMyGroups();
}, },
}; };
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment