Skip to content

Commit

Permalink
[frontend] Custom Emoji Deletion (#994)
Browse files Browse the repository at this point in the history
* re-add eslint

* fix oauth url getting too long

* actually attach single emoji get and delete routes

* basic emoji details + deletion using rtk query

* refactor emoji upload to rtk query

* clean up old redux api+reducers for custom emoji

* fix validation order

* refactor custom emoji form fields

* remove unused requires

* cleanup, fix most eslint errors

* more small eslint fixes

* fix max emoji size

* tiny bit of function documentation
  • Loading branch information
f0x52 committed Nov 8, 2022
1 parent be011b1 commit eb25739
Show file tree
Hide file tree
Showing 32 changed files with 1,467 additions and 506 deletions.
2 changes: 2 additions & 0 deletions internal/api/client/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func New(processor processing.Processor) api.ClientModule {
func (m *Module) Route(r router.Router) error {
r.AttachHandler(http.MethodPost, EmojiPath, m.EmojiCreatePOSTHandler)
r.AttachHandler(http.MethodGet, EmojiPath, m.EmojisGETHandler)
r.AttachHandler(http.MethodDelete, EmojiPathWithID, m.EmojiDELETEHandler)
r.AttachHandler(http.MethodGet, EmojiPathWithID, m.EmojiGETHandler)
r.AttachHandler(http.MethodPost, DomainBlocksPath, m.DomainBlocksPOSTHandler)
r.AttachHandler(http.MethodGet, DomainBlocksPath, m.DomainBlocksGETHandler)
r.AttachHandler(http.MethodGet, DomainBlocksPathWithID, m.DomainBlockGETHandler)
Expand Down
5 changes: 1 addition & 4 deletions web/source/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"use strict";

module.exports = {
"extends": ["@f0x52/eslint-config-react"],
"rules": {
"react/prop-types": "off"
}
"extends": ["@joepie91/eslint-config/react"]
};
4 changes: 4 additions & 0 deletions web/source/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,16 @@ section.login {
}

section.error {
word-break: break-word;
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 0.5rem;

span {
font-size: 2em;
}

pre {
border: 1px solid #ff000080;
margin-left: 1em;
Expand Down
1 change: 1 addition & 0 deletions web/source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ skulk({
],
},
settings: {
debug: false,
entryFile: "settings",
outputFile: "settings.js",
prodCfg: prodCfg,
Expand Down
4 changes: 4 additions & 0 deletions web/source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6",
"@browserify/envify": "^6.0.0",
"@joepie91/eslint-config": "^1.1.1",
"autoprefixer": "^10.4.13",
"babelify": "^10.0.0",
"css-extract": "^2.0.0",
"eslint": "^8.26.0",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"factor-bundle": "^2.5.0",
"icssify": "^2.0.0",
"postcss": "^8.4.18",
Expand Down
1 change: 0 additions & 1 deletion web/source/settings/admin/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

"use strict";

const Promise = require("bluebird");
const React = require("react");
const Redux = require("react-redux");

Expand Down
229 changes: 0 additions & 229 deletions web/source/settings/admin/emoji.js

This file was deleted.

86 changes: 86 additions & 0 deletions web/source/settings/admin/emoji/detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
GoToSocial
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

"use strict";

const React = require("react");

const { useRoute, Link, Redirect } = require("wouter");

const BackButton = require("../../components/back-button");

const query = require("../../lib/query");

const base = "/settings/admin/custom-emoji";

/* We wrap the component to generate formFields with a setter depending on the domain
if formFields() is used inside the same component that is re-rendered with their state,
inputs get re-created on every change, causing them to lose focus, and bad performance
*/
module.exports = function EmojiDetailWrapped() {
let [_match, {emojiId}] = useRoute(`${base}/:emojiId`);
const {currentData: emoji, isLoading, error} = query.useGetEmojiQuery(emojiId);

return (<>
{error && <div className="error accent">{error.status}: {error.data.error}</div>}
{isLoading
? "Loading..."
: <EmojiDetail emoji={emoji}/>
}
</>);
};

function EmojiDetail({emoji}) {
if (emoji == undefined) {
return (<>
<Link to={base}>
<a className="button">go back</a>
</Link>
</>);
}

return (
<div>
<h1><BackButton to={base}/> Custom Emoji: {emoji.shortcode}</h1>
<DeleteButton id={emoji.id}/>
<p>
Editing custom emoji isn&apos;t implemented yet.<br/>
<a target="_blank" rel="noreferrer" href="https://github.com/superseriousbusiness/gotosocial/issues/797">View implementation progress.</a>
</p>
<img src={emoji.url} alt={emoji.shortcode} title={`:${emoji.shortcode}:`}/>
</div>
);
}

function DeleteButton({id}) {
// TODO: confirmation dialog?
const [deleteEmoji, deleteResult] = query.useDeleteEmojiMutation();

let text = "Delete this emoji";
if (deleteResult.isLoading) {
text = "processing...";
}

if (deleteResult.isSuccess) {
return <Redirect to={base}/>;
}

return (
<button onClick={() => deleteEmoji(id)} disabled={deleteResult.isLoading}>{text}</button>
);
}

0 comments on commit eb25739

Please sign in to comment.