index.jsx (3485B)
1 /* 2 GoToSocial 3 Copyright (C) GoToSocial Authors admin@gotosocial.org 4 SPDX-License-Identifier: AGPL-3.0-or-later 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 "use strict"; 21 22 const React = require("react"); 23 const { Switch, Route, Link } = require("wouter"); 24 25 const query = require("../../lib/query"); 26 const { useTextInput } = require("../../lib/form"); 27 28 const AccountDetail = require("./detail"); 29 const { useBaseUrl } = require("../../lib/navigation/util"); 30 const { Error } = require("../../components/error"); 31 32 module.exports = function Accounts({ baseUrl }) { 33 return ( 34 <div className="accounts"> 35 <Switch> 36 <Route path={`${baseUrl}/:accountId`}> 37 <AccountDetail /> 38 </Route> 39 <AccountOverview /> 40 </Switch> 41 </div> 42 ); 43 }; 44 45 function AccountOverview({ }) { 46 return ( 47 <> 48 <h1>Accounts</h1> 49 <div> 50 Pending <a href="https://github.com/superseriousbusiness/gotosocial/issues/581">#581</a>, 51 there is currently no way to list accounts.<br /> 52 You can perform actions on reported accounts by clicking their name in the report, or searching for a username below. 53 </div> 54 55 <AccountSearchForm /> 56 </> 57 ); 58 } 59 60 function AccountSearchForm() { 61 const [searchAccount, result] = query.useSearchAccountMutation(); 62 63 const [onAccountChange, _resetAccount, { account }] = useTextInput("account"); 64 65 function submitSearch(e) { 66 e.preventDefault(); 67 if (account.trim().length != 0) { 68 searchAccount(account); 69 } 70 } 71 72 return ( 73 <div className="account-search"> 74 <form onSubmit={submitSearch}> 75 <div className="form-field text"> 76 <label htmlFor="url"> 77 Account: 78 </label> 79 <div className="row"> 80 <input 81 type="text" 82 id="account" 83 name="account" 84 onChange={onAccountChange} 85 value={account} 86 /> 87 <button disabled={result.isLoading}> 88 <i className={[ 89 "fa fa-fw", 90 (result.isLoading 91 ? "fa-refresh fa-spin" 92 : "fa-search") 93 ].join(" ")} aria-hidden="true" title="Search" /> 94 <span className="sr-only">Search</span> 95 </button> 96 </div> 97 </div> 98 </form> 99 <AccountList 100 isSuccess={result.isSuccess} 101 data={result.data} 102 isError={result.isError} 103 error={result.error} 104 /> 105 </div> 106 ); 107 } 108 109 function AccountList({ isSuccess, data, isError, error }) { 110 const baseUrl = useBaseUrl(); 111 112 if (!(isSuccess || isError)) { 113 return null; 114 } 115 116 if (error) { 117 return <Error error={error} />; 118 } 119 120 if (data.length == 0) { 121 return <b>No accounts found that match your query</b>; 122 } 123 124 return ( 125 <> 126 <h2>Results:</h2> 127 <div className="list"> 128 {data.map((acc) => ( 129 <Link key={acc.acct} className="account entry" to={`${baseUrl}/${acc.id}`}> 130 {acc.display_name?.length > 0 131 ? acc.display_name 132 : acc.username 133 } 134 <span id="username">(@{acc.acct})</span> 135 </Link> 136 ))} 137 </div> 138 </> 139 ); 140 }