PortfolioProfile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <div class="w-100 h-100">
  3. <div v-if="loading" class="container">
  4. <div class="d-flex justify-content-center align-items-center" style="height: 100vh;">
  5. <b-spinner />
  6. </div>
  7. </div>
  8. <div v-else class="container">
  9. <div class="row py-5">
  10. <div class="col-12">
  11. <div class="d-flex align-items-center flex-column">
  12. <img
  13. v-if="settings.show_avatar"
  14. :src="profile.avatar"
  15. width="60"
  16. height="60"
  17. class="rounded-circle shadow"
  18. onerror="this.src='/storage/avatars/default.png?v=0';this.onerror=null;">
  19. <div class="py-3 text-center" style="max-width: 60%">
  20. <h1 class="font-weight-bold">{{ profile.username }}</h1>
  21. <p v-if="settings.show_bio" class="font-weight-light mb-0 text-break">{{ profile.note_text }}</p>
  22. </div>
  23. <div v-if="settings.show_profile_button || (settings.rss_enabled && settings.show_rss_button)" class="pb-3 text-center d-flex flex-column flex-sm-row" style="max-width: 60%;gap: 1rem;">
  24. <a
  25. v-if="settings.show_profile_button"
  26. class="btn btn-outline-primary btn-custom-color"
  27. :href="profile.url"
  28. target="_blank">
  29. View Profile
  30. </a>
  31. <a
  32. v-if="settings.rss_enabled && settings.show_rss_button"
  33. class="btn btn-outline-primary btn-custom-color"
  34. :href="settings.rss_feed_url"
  35. target="_blank">
  36. <i class="far fa-rss"></i> &nbsp; RSS
  37. </a>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="container mb-5 pb-5">
  43. <div :class="[ settings.profile_layout === 'masonry' ? 'card-columns' : 'row']" id="portContainer">
  44. <template v-if="settings.profile_layout ==='grid'">
  45. <div v-for="(res, index) in feed" class="col-12 col-md-4 mb-1 p-1">
  46. <div class="square">
  47. <a :href="postUrl(res)">
  48. <div class="lazy-img">
  49. <blur-hash-canvas
  50. width="32"
  51. height="32"
  52. :hash="res.media_attachments[0].blurhash"
  53. class="square-content pr-1"
  54. />
  55. <img
  56. src=""
  57. :data-src="res.media_attachments[0].url"
  58. width="100%"
  59. height="300"
  60. style="overflow: hidden;object-fit: cover;z-index: -1;"
  61. class="square-content pr-1 img-placeholder"
  62. loading="lazy" />
  63. </div>
  64. </a>
  65. </div>
  66. </div>
  67. </template>
  68. <div v-else-if="settings.profile_layout ==='album'" class="col-12 mb-1 p-1">
  69. <div class="d-flex justify-content-center">
  70. <p class="text-color font-weight-bold">{{ albumIndex + 1 }} <span class="font-weight-light">/</span> {{ feed.length }}</p>
  71. </div>
  72. <div class="d-flex justify-content-between align-items-center">
  73. <span v-if="albumIndex === 0">
  74. <i class="fa fa-arrow-circle-left fa-3x text-color-lighter" />
  75. </span>
  76. <a v-else @click.prevent="albumPrev()" href="#">
  77. <i class="fa fa-arrow-circle-left fa-3x text-color"/>
  78. </a>
  79. <transition name="slide-fade">
  80. <a :href="postUrl(feed[albumIndex])" class="mx-4" :key="albumIndex">
  81. <img
  82. :src="feed[albumIndex].media_attachments[0].url"
  83. width="100%"
  84. class="user-select-none"
  85. style="height: 60vh; overflow: hidden;object-fit: contain;"
  86. :draggable="false"
  87. >
  88. </a>
  89. </transition>
  90. <span v-if="albumIndex === feed.length - 1">
  91. <i class="fa fa-arrow-circle-right fa-3x text-color-lighter" />
  92. </span>
  93. <a v-else @click.prevent="albumNext()" href="#">
  94. <i class="fa fa-arrow-circle-right fa-3x text-color"/>
  95. </a>
  96. </div>
  97. </div>
  98. <div v-else-if="settings.profile_layout ==='masonry'" class="col-12 p-0 m-0">
  99. <div v-for="(res, index) in feed" class="p-1">
  100. <a :href="postUrl(res)" data-fancybox="recent" :data-src="res.media_attachments[0].url" :data-width="res.media_attachments[0].width" :data-height="res.media_attachments[0].height">
  101. <img
  102. :src="res.media_attachments[0].url"
  103. width="100%"
  104. class="user-select-none"
  105. style="overflow: hidden;object-fit: contain;"
  106. :draggable="false"
  107. >
  108. </a>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="d-flex fixed-bottom p-3 justify-content-between align-items-center">
  114. <a v-if="user" class="logo-mark logo-mark-sm mb-0 p-1" href="/">
  115. <span class="text-gradient-primary">portfolio</span>
  116. </a>
  117. <span v-else class="logo-mark logo-mark-sm mb-0 p-1">
  118. <span class="text-gradient-primary">portfolio</span>
  119. </span>
  120. <p v-if="user && user.id == profile.id" class="text-center mb-0">
  121. <a :href="settingsUrl" class="link-color"><i class="far fa-cog fa-lg"></i></a>
  122. </p>
  123. </div>
  124. </div>
  125. </div>
  126. </template>
  127. <script type="text/javascript">
  128. import '@fancyapps/fancybox/dist/jquery.fancybox.js';
  129. import '@fancyapps/fancybox/dist/jquery.fancybox.css';
  130. export default {
  131. props: [ 'initialData' ],
  132. data() {
  133. return {
  134. loading: true,
  135. user: undefined,
  136. profile: undefined,
  137. settings: undefined,
  138. feed: [],
  139. albumIndex: 0,
  140. settingsUrl: window._portfolio.path + '/settings',
  141. }
  142. },
  143. mounted() {
  144. const initialData = JSON.parse(this.initialData);
  145. this.profile = initialData.profile;
  146. this.fetchUser();
  147. },
  148. methods: {
  149. async fetchUser() {
  150. axios.get('/api/v1/accounts/verify_credentials')
  151. .then(res => {
  152. this.user = res.data;
  153. })
  154. .catch(err => {
  155. });
  156. await axios.get('/api/portfolio/account/settings.json', {
  157. params: {
  158. id: this.profile.id
  159. }
  160. })
  161. .then(res => {
  162. this.settings = res.data;
  163. if(res.data.hasOwnProperty('background_color')) {
  164. this.updateCssVariable('--body-bg', res.data.background_color);
  165. }
  166. if(res.data.hasOwnProperty('text_color')) {
  167. this.updateCssVariable('--text-color', res.data.text_color);
  168. this.updateCssVariable('--link-color', res.data.text_color);
  169. }
  170. })
  171. .then(() => {
  172. this.fetchFeed();
  173. })
  174. },
  175. async fetchFeed() {
  176. axios.get('/api/portfolio/' + this.profile.id + '/feed')
  177. .then(res => {
  178. this.feed = res.data.filter(p => ['photo', 'photo:album'].includes(p.pf_type));
  179. })
  180. .then(() => {
  181. this.setAlbumSlide();
  182. })
  183. .then(() => {
  184. setTimeout(() => {
  185. this.loading = false;
  186. }, 500);
  187. })
  188. .then(() => {
  189. if(this.settings.profile_layout === 'masonry') {
  190. setTimeout(() => {
  191. this.initMasonry();
  192. }, 500);
  193. }
  194. })
  195. .then(() => {
  196. setTimeout(() => {
  197. this.bootIntersectors()
  198. }, 500);
  199. })
  200. .catch(err => {
  201. this.loading = false;
  202. })
  203. },
  204. postUrl(res) {
  205. return `${window._portfolio.path}/${this.profile.username}/${res.id}`;
  206. },
  207. albumPrev() {
  208. if(this.albumIndex === 0) {
  209. return;
  210. }
  211. if(this.albumIndex === 1) {
  212. this.albumIndex--;
  213. const url = new URL(window.location);
  214. url.searchParams.delete('slide');
  215. window.history.pushState({}, '', url);
  216. return;
  217. }
  218. this.albumIndex--;
  219. const url = new URL(window.location);
  220. url.searchParams.set('slide', this.albumIndex + 1);
  221. window.history.pushState({}, '', url);
  222. },
  223. albumNext() {
  224. if(this.albumIndex === this.feed.length - 1) {
  225. return;
  226. }
  227. this.albumIndex++;
  228. const url = new URL(window.location);
  229. url.searchParams.set('slide', this.albumIndex + 1);
  230. window.history.pushState({}, '', url);
  231. },
  232. setAlbumSlide() {
  233. const url = new URL(window.location);
  234. if(url.searchParams.has('slide')) {
  235. const slide = Number.parseInt(url.searchParams.get('slide'));
  236. if(Number.isNaN(slide)) {
  237. return;
  238. }
  239. if(slide <= 0) {
  240. return;
  241. }
  242. if(slide > this.feed.length) {
  243. return;
  244. }
  245. this.albumIndex = url.searchParams.get('slide') - 1;
  246. }
  247. },
  248. initMasonry() {
  249. $('[data-fancybox="recent"]').fancybox({
  250. gutter: 20,
  251. modal: false,
  252. });
  253. },
  254. updateCssVariable(k, v) {
  255. let rs = document.querySelector(':root');
  256. rs.style.setProperty(k, v);
  257. },
  258. bootIntersectors() {
  259. var lazyImages = [].slice.call(document.querySelectorAll("img.img-placeholder"));
  260. if ("IntersectionObserver" in window) {
  261. let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
  262. entries.forEach(function(entry) {
  263. if (entry.isIntersecting) {
  264. let lazyImage = entry.target;
  265. lazyImage.src = lazyImage.dataset.src;
  266. lazyImage.style.zIndex = 2;
  267. lazyImage.classList.remove("img-placeholder");
  268. lazyImageObserver.unobserve(lazyImage);
  269. }
  270. });
  271. });
  272. lazyImages.forEach(function(lazyImage) {
  273. lazyImageObserver.observe(lazyImage);
  274. });
  275. } else {
  276. lazyImages.forEach(function(img) {
  277. img.src = img.dataset.src;
  278. img.style.zIndex = 2;
  279. })
  280. }
  281. }
  282. }
  283. }
  284. </script>