11<script setup>
2+ import { ref , reactive , computed , onMounted , onBeforeUnmount } from ' vue' ;
23import { logos } from ' ./logos/logos.js'
3- import { NIcon , NButton , NDropdown } from ' naive-ui' ;
4+ import { NIcon , NButton , NDropdown , NPagination , NSpin } from ' naive-ui' ;
45import { ChevronDown } from ' @vicons/ionicons5' ;
56import { showBusinessProfile , showEduProfile } from " ../utils.js"
67
7- const props = defineProps ([' list' , ' options' , ' connection' , ' type' ])
8- const emit = defineEmits ([' change' ])
8+ const props = defineProps ([' list' , ' loading' , ' options' , ' connection' , ' connectionKey' , ' pageSizes' ])
9+ const emit = defineEmits ([' change' , ' page' ])
10+
11+ const windowWidth = ref (window .innerWidth );
12+
13+ onMounted (() => {
14+ window .addEventListener (' resize' , updateWindowWidth)
15+ })
16+
17+ onBeforeUnmount (() => {
18+ window .removeEventListener (' resize' , updateWindowWidth)
19+ })
20+
21+ const updateWindowWidth = () => {
22+ windowWidth .value = window .innerWidth
23+ }
24+
25+ const constants = {
26+ business: {
27+ title: ' Businesses on other platforms:' ,
28+ type: ' Business' ,
29+ profileLink: ' business'
30+ },
31+ edu: {
32+ title: ' Institutions on other platforms:' ,
33+ type: ' Institution' ,
34+ profileLink: ' edu'
35+ },
36+ people: {
37+ title: ' People on other platforms:' ,
38+ type: ' Username' ,
39+ profileLink: ' personal'
40+ }
41+ }
942
1043function handleClick (item )
1144{
@@ -19,33 +52,94 @@ function handleClick(item)
1952 }
2053}
2154
55+ const profileLink = computed (()=> ` /edit-profile/?p=${ constants[props .connectionKey ].profileLink } ` )
56+
57+ const page = ref (1 );
58+ const pageSize = ref (props .pageSizes [0 ].value );
59+
60+ function setPage (p )
61+ {
62+ page .value = p
63+ emit (' page' , { page: p, size: pageSize .value });
64+ }
65+
66+ function setSize (s )
67+ {
68+ pageSize .value = s;
69+ emit (' page' , { page: 1 , size: s});
70+ }
71+
72+ const isSimple = computed (() => (windowWidth .value < 480 ? true : false ));
73+ const showSizePicker = computed (() => windowWidth .value > 600 );
74+
2275 </script >
2376
2477<template >
25- <div >
26- <table class =" table table-borderless" >
27- <thead class =" border-bottom" >
28- <tr >
29- <th scope =" col" class =" col-4" >{{ type}}</th >
30- <th scope =" col" class =" col" >
31- <NDropdown trigger="click" :options =" options " @select =" (key ) => emit (' change' , key ) " >
32- <NButton secondary>{{ connection.label }}<NIcon class="ml-4"><ChevronDown /></NIcon ></NButton >
33- </NDropdown ></th >
34- </tr >
35- </thead >
36- <tbody v-if =" list" >
37- <tr v-for =" item in list.items" class =" border-bottom" >
38- <td >
39- <a :href =" item.profileLink" @click.prevent =" handleClick(item)" >{{ item.name }}</a >
40- </td >
41- <td >
42- <a :href =" item.connectionLink" target =" _blank" >
43- <NIcon class="mr-3"><component :is =" logos[connection.key]" /></NIcon >{{ item.label }}
44- </a >
45- </td >
46- </tr >
47- </tbody >
48- </table >
49- </div >
78+ <p >{{ constants[props.connectionKey].title }}</p >
79+ <NSpin :show =" loading " >
80+ <div class =" connectionsView" v-if =" list" >
81+ <table class =" table table-borderless" >
82+ <thead class =" border-bottom" >
83+ <tr >
84+ <th scope =" col" class =" col-4" >{{ constants[props.connectionKey].type }}</th >
85+ <th scope =" col" class =" col pr-0" >
86+ <div class =" row align-items-center" >
87+ <div class =" col mb-3 mb-md-0" >
88+ <NDropdown trigger="click" :options =" options " @select =" (key ) => emit (' change' , key ) " >
89+ <NButton secondary>{{ connection.label }}<NIcon class="ml-4"><ChevronDown /></NIcon ></NButton >
90+ </NDropdown >
91+ </div >
92+ <div class =" col-auto" v-if =" list.total > pageSizes[0].value" >
93+ <NPagination
94+ v-model :page =" page "
95+ v-model :page-size =" pageSize "
96+ :simple =" isSimple "
97+ :item-count =" list .total "
98+ :page-sizes =" pageSizes "
99+ :page-slot =" 4 "
100+ :show-size-picker =" showSizePicker "
101+ @update :page =" setPage "
102+ @update :page-size =" setSize "
103+ class="pagination"
104+ />
105+ </div >
106+ </div >
107+ </th >
108+ </tr >
109+ </thead >
110+ <tbody v-if =" list" >
111+ <tr v-for =" item in list.items" class =" border-bottom" >
112+ <td >
113+ <a :href =" item.profileLink" @click.prevent =" handleClick(item)" >{{ item.name }}</a >
114+ </td >
115+ <td >
116+ <a :href =" item.connectionLink" target =" _blank" >
117+ <NIcon class="mr-3"><component :is =" logos[connection.key]" /></NIcon >{{ item.label }}
118+ </a >
119+ </td >
120+ </tr >
121+ </tbody >
122+ </table >
123+
124+ <div class =" row mt-4" >
125+ <div class =" col" >
126+ <p class =" profileLink" >Add this platform to <a :href =" profileLink" >your profile.</a ></p >
127+ </div >
128+ <div class =" col-auto ml-auto" v-if =" list.total > pageSizes[0].value" >
129+ <NPagination
130+ v-model :page =" page "
131+ v-model :page-size =" pageSize "
132+ :simple =" isSimple "
133+ :item-count =" list .total "
134+ :page-sizes =" pageSizes "
135+ :page-slot =" 4 "
136+ :show-size-picker =" showSizePicker "
137+ @update :page =" setPage "
138+ @update :page-size =" setSize "
139+ />
140+ </div >
141+ </div >
142+ </div >
143+ </NSpin >
50144</template >
51145
0 commit comments