pixelfed/public/js/search.js

1 line
22 KiB
JavaScript
Raw Normal View History

2023-10-23 07:58:16 +00:00
(self.webpackChunkpixelfed=self.webpackChunkpixelfed||[]).push([[4683],{24533:(t,s,e)=>{"use strict";e.r(s),e.d(s,{default:()=>l});var a=e(19755);function r(t){return function(t){if(Array.isArray(t))return i(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,s){if(!t)return;if("string"==typeof t)return i(t,s);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return i(t,s)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,s){(null==s||s>t.length)&&(s=t.length);for(var e=0,a=new Array(s);e<s;e++)a[e]=t[e];return a}const l={props:["query","profileId"],data:function(){return{loading:!0,networkError:!1,results:{hashtags:[],profiles:[],statuses:[],places:[]},filters:{hashtags:!0,profiles:!0,statuses:!0},analysis:"profile",showPlaces:!1,placesCursor:1,placesCache:[],placesSearchEnabled:!1,searchVersion:2}},beforeMount:function(){this.bootSearch()},mounted:function(){a(".search-bar input").val(this.query)},updated:function(){a('[data-toggle="tooltip"]').tooltip()},methods:{bootSearch:function(){var t=this.searchLexer();this.analysis=t,this.fetchSearchResults(),axios.get("/api/pixelfed/v1/accounts/verify_credentials").then((function(t){window._sharedData.curUser=t.data,window.App.util.navatar()}))},fetchSearchResults:function(){if("remote"==this.analysis){var t=this.query;if(new URL(t).host===window.location.host)return void(window.location.href=t)}this.searchContext(this.analysis)},searchLexer:function(){var t=this.query;return t.startsWith("#")?"hashtag":2==(t.match(/@/g)||[]).length?"webfinger":t.startsWith("@")?"profile":t.startsWith("https://")?"remote":"all"},buildUrl:function(){var t=arguments.length>1?arguments[1]:void 0;switch(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"hashtag"){case"hashtag":default:return t.url+"?src=search";case"profile":return 1==t.entity.local?t.url:"/i/web/profile/_/"+t.entity.id}},searchContext:function(t){var s=this;switch(t){case"all":axios.get("/api/search",{params:{q:this.query,src:"metro",v:this.searchVersion,scope:"all"}}).then((function(t){var e=t.data;s.results.hashtags=e.hashtags?e.hashtags:[],s.results.profiles=e.profiles?e.profiles:[],s.results.statuses=e.posts?e.posts:[],s.results.places=e.places?e.places:[],s.placesCache=e.places,s.results.placesPagination=e.placesPagination?e.placesPagination:[],s.loading=!1})).catch((function(t){s.loading=!1,s.networkError=!0}));break;case"remote":axios.get("/api/search",{params:{q:this.query,src:"metro",v:this.searchVersion,scope:"remote"}}).then((function(t){var e=t.data;s.results.hashtags=e.hashtags?e.hashtags:[],s.results.profiles=e.profiles?e.profiles:[],s.results.statuses=e.posts?e.posts:[],s.results.profiles.length&&(s.analysis="profile"),s.results.statuses.length&&(s.analysis="remotePost"),s.loading=!1})).catch((function(t){s.loading=!1,s.networkError=!0}));break;case"hashtag":axios.get("/api/search",{params:{q:this.query.slice(1),src:"metro",v:this.searchVersion,scope:"hashtag"}}).then((function(t){var e=t.data;s.results.hashtags=e.hashtags?e.hashtags:[],s.results.profiles=e.profiles?e.profiles:[],s.results.statuses=e.posts?e.posts:[],s.loading=!1})).catch((function(t){s.loading=!1,s.networkError=!0}));break;case"profile":axios.get("/api/search",{params:{q:this.query,src:"metro",v:this.searchVersion,scope:"profile"}}).then((function(t){var e=t.data;s.results.hashtags=e.hashtags?e.hashtags:[],s.results.profiles=e.profiles?e.profiles:[],s.results.statuses=e.posts?e.posts:[],s.loading=!1})).catch((function(t){s.loading=!1,s.networkError=!0}));break;case"webfinger":axios.get("/api/search",{params:{q:this.query,src:"metro",v:this.searchVersion,scope:"webfinger"}}).then((function(t){var e=t.data;s.results.hashtags=[],s.results.profiles=e.profiles,