GroupFeed.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="groups-home-component w-100 h-100">
  3. <div v-if="initialLoad" class="row border-bottom m-0 p-0">
  4. <sidebar />
  5. <self-feed :profile="profile" v-on:switchtab="switchTab" />
  6. <!-- <self-discover v-if="tab == 'discover'" :profile="profile" />
  7. <self-notifications v-if="tab == 'notifications'" :profile="profile" />
  8. <self-invitations v-if="tab == 'invitations'" :profile="profile" />
  9. <self-remote-search v-if="tab == 'remotesearch'" :profile="profile" />
  10. <self-groups v-if="tab == 'mygroups'" :profile="profile" />
  11. <create-group v-if="tab == 'creategroup'" :profile="profile" />
  12. <div v-if="tab == 'gsearch'">
  13. <div class="col-12 px-5">
  14. <div class="my-4">
  15. <p class="h1 font-weight-bold mb-1">Group Search</p>
  16. <p class="lead text-muted mb-0">Search and explore groups.</p>
  17. </div>
  18. <div class="media align-items-center text-lighter">
  19. <i class="far fa-chevron-left fa-lg mr-3"></i>
  20. <div class="media-body">
  21. <p class="lead mb-0">Use the search bar on the side menu</p>
  22. </div>
  23. </div>
  24. </div>
  25. </div> -->
  26. </div>
  27. <div v-else class="row justify-content-center mt-5">
  28. <b-spinner />
  29. </div>
  30. </div>
  31. </template>
  32. <script type="text/javascript">
  33. import GroupStatus from '@/groups/partials/GroupStatus.vue';
  34. import SelfFeed from '@/groups/partials/SelfFeed.vue';
  35. import SelfDiscover from '@/groups/partials/SelfDiscover.vue';
  36. import SelfGroups from '@/groups/partials/SelfGroups.vue';
  37. import SelfNotifications from '@/groups/partials/SelfNotifications.vue';
  38. import SelfInvitations from '@/groups/partials/SelfInvitations.vue';
  39. import SelfRemoteSearch from '@/groups/partials/SelfRemoteSearch.vue';
  40. import CreateGroup from '@/groups/CreateGroup.vue';
  41. import SidebarComponent from '@/groups/sections/Sidebar.vue';
  42. import Autocomplete from '@trevoreyre/autocomplete-vue'
  43. import '@trevoreyre/autocomplete-vue/dist/style.css'
  44. export default {
  45. data() {
  46. return {
  47. initialLoad: false,
  48. config: {},
  49. groups: [],
  50. profile: {},
  51. tab: null,
  52. searchQuery: undefined,
  53. };
  54. },
  55. components: {
  56. 'autocomplete-input': Autocomplete,
  57. 'group-status': GroupStatus,
  58. 'self-discover': SelfDiscover,
  59. 'self-groups': SelfGroups,
  60. 'self-feed': SelfFeed,
  61. 'self-notifications': SelfNotifications,
  62. 'self-invitations': SelfInvitations,
  63. 'self-remote-search': SelfRemoteSearch,
  64. "create-group": CreateGroup,
  65. "sidebar": SidebarComponent
  66. },
  67. mounted() {
  68. this.fetchConfig();
  69. },
  70. methods: {
  71. init() {
  72. document.querySelectorAll("footer").forEach(e => e.parentNode.removeChild(e));
  73. document.querySelectorAll(".mobile-footer-spacer").forEach(e => e.parentNode.removeChild(e));
  74. document.querySelectorAll(".mobile-footer").forEach(e => e.parentNode.removeChild(e));
  75. // let u = new URLSearchParams(window.location.search);
  76. // if(u.has('ct')) {
  77. // if(['mygroups', 'notifications', 'discover', 'remotesearch', 'creategroup', 'gsearch'].includes(u.get('ct'))) {
  78. // if(u.get('ct') == 'creategroup' && this.config.limits.user.create.new == false) {
  79. // this.tab = 'feed';
  80. // history.pushState(null, null, '/groups/feed');
  81. // } else {
  82. // this.tab = u.get('ct');
  83. // }
  84. // } else {
  85. // this.tab = 'feed';
  86. // history.pushState(null, null, '/groups/feed');
  87. // }
  88. // } else {
  89. // this.tab = 'feed';
  90. // }
  91. this.initialLoad = true;
  92. },
  93. fetchConfig() {
  94. axios.get('/api/v0/groups/config')
  95. .then(res => {
  96. this.config = res.data;
  97. this.fetchProfile();
  98. });
  99. },
  100. fetchProfile() {
  101. axios.get('/api/pixelfed/v1/accounts/verify_credentials')
  102. .then(res => {
  103. this.profile = res.data;
  104. this.init();
  105. window._sharedData.curUser = res.data;
  106. window.App.util.navatar();
  107. })
  108. },
  109. fetchSelfGroups() {
  110. axios.get('/api/v0/groups/self/list')
  111. .then(res => {
  112. this.groups = res.data;
  113. });
  114. },
  115. switchTab(tab) {
  116. event.currentTarget.blur();
  117. window.scrollTo(0,0);
  118. this.tab = tab;
  119. if(tab != 'feed') {
  120. history.pushState(null, null, '/groups/home?ct=' + tab);
  121. } else {
  122. history.pushState(null, null, '/groups/home');
  123. }
  124. },
  125. autocompleteSearch(input) {
  126. if (!input || input.length < 2) {
  127. if(this.tab = 'searchresults') {
  128. this.tab = 'feed';
  129. }
  130. return [];
  131. };
  132. this.searchQuery = input;
  133. // this.tab = 'searchresults';
  134. if(input.startsWith('http')) {
  135. let url = new URL(input);
  136. if(url.hostname == location.hostname) {
  137. location.href = input;
  138. return [];
  139. }
  140. return [];
  141. }
  142. if(input.startsWith('#')) {
  143. this.$bvToast.toast(input, {
  144. title: 'Hashtag detected',
  145. variant: 'info',
  146. autoHideDelay: 5000
  147. });
  148. return [];
  149. }
  150. return axios.post('/api/v0/groups/search/global', {
  151. q: input,
  152. v: '0.2'
  153. })
  154. .then(res => {
  155. this.searchLoading = false;
  156. return res.data;
  157. }).catch(err => {
  158. if(err.response.status === 422) {
  159. this.$bvToast.toast(err.response.data.error.message, {
  160. title: 'Cannot display search results',
  161. variant: 'danger',
  162. autoHideDelay: 5000
  163. });
  164. }
  165. return [];
  166. })
  167. },
  168. getSearchResultValue(result) {
  169. return result.name;
  170. },
  171. onSearchSubmit(result) {
  172. if (result.length < 1) {
  173. return [];
  174. }
  175. location.href = result.url;
  176. },
  177. truncateName(val) {
  178. if(val.length < 24) {
  179. return val;
  180. }
  181. return val.substr(0, 23) + '...';
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. .groups-home-component {
  188. font-family: var(--font-family-sans-serif);
  189. .group-nav-btn {
  190. display: block;
  191. width: 100%;
  192. padding-left: 0;
  193. padding-top: 0.3rem;
  194. padding-bottom: 0.3rem;
  195. margin-bottom: 0.3rem;
  196. border-radius: 1.5rem;
  197. text-align: left;
  198. color: #6c757d;
  199. background-color: transparent;
  200. border-color: transparent;
  201. justify-content: flex-start;
  202. &.active {
  203. background-color: #EFF6FF !important;
  204. border:1px solid #DBEAFE !important;
  205. color: #212529;
  206. .group-nav-btn-icon {
  207. background-color: #2c78bf !important;
  208. color: #fff !important;
  209. }
  210. }
  211. &-icon {
  212. display: inline-flex;
  213. width: 35px;
  214. height: 35px;
  215. padding: 12px;
  216. background-color: #E5E7EB;
  217. border-radius: 17px;
  218. margin: auto 0.3rem;
  219. align-items: center;
  220. justify-content: center;
  221. }
  222. &-name {
  223. display: inline-block;
  224. margin-left: 0.3rem;
  225. font-weight: 700;
  226. }
  227. }
  228. .autocomplete-input {
  229. height: 2.375rem;
  230. background-color: #f8f9fa !important;
  231. font-size: 0.9rem;
  232. color: #495057;
  233. border-radius: 50rem;
  234. border-color: transparent;
  235. &:focus,
  236. &[aria-expanded=true] {
  237. box-shadow: none;
  238. }
  239. }
  240. .autocomplete-result {
  241. background: none;
  242. padding: 12px;
  243. &:hover,
  244. &:focus {
  245. background-color: #EFF6FF !important;
  246. }
  247. .media {
  248. img {
  249. object-fit: cover;
  250. border-radius: 4px;
  251. margin-right: 0.6rem;
  252. }
  253. .icon-placeholder {
  254. display: flex;
  255. width: 32px;
  256. height: 32px;
  257. background-color: #2c78bf;
  258. border-radius: 4px;
  259. justify-content: center;
  260. align-items: center;
  261. color: #fff;
  262. margin-right: 0.6rem;
  263. }
  264. }
  265. }
  266. .autocomplete-result-list {
  267. padding-bottom: 0;
  268. }
  269. .fade-enter-active, .fade-leave-active {
  270. transition: opacity 200ms;
  271. }
  272. .fade-enter, .fade-leave-to {
  273. opacity: 0;
  274. }
  275. }
  276. </style>