1- import React , { Component } from "react" ;
2- import connect from "react-redux/es/connect/connect" ;
3-
4- import { Container , Header , Button , Divider , Menu , Icon } from 'semantic-ui-react' ;
5-
6- import '../../../semantic/src/definitions/elements/container.less' ;
7- import '../../../semantic/src/definitions/elements/header.less' ;
8- import '../../../semantic/src/definitions/elements/button.less' ;
9- import '../../../semantic/src/definitions/elements/divider.less' ;
10- import '../../../semantic/src/definitions/collections/menu.less' ;
11- import '../../../semantic/src/definitions/elements/icon.less' ;
12-
13- import EmotePreview from "./emotes/preview" ;
14- import { postGuildEmotes } from "../../../actions/guild"
15- import { receiveGuildEmotes } from "../../../actions/user"
16-
17- import { withRouter } from "react-router-dom" ;
18-
19-
20- class EmoteSettings extends Component {
21- constructor ( props ) {
22- super ( props ) ;
23- const emotes = this . props . emotes [ this . props . guildID ] || [ ] ;
24- this . state = { emotes} ;
25- }
26-
27- componentDidUpdate ( prevProps ) {
28- if ( ( prevProps . guildID !== this . props . guildID ) ||
29- ( prevProps . emotes [ prevProps . guildID ] !== this . props . emotes [ this . props . guildID ] ) ) {
30- const emotes = this . props . emotes [ this . props . guildID ] || [ ] ;
31- this . setState ( { emotes} ) ;
32- }
33- }
34-
35- unsetNames ( emotes ) {
36- this . setState ( { emotes : this . state . emotes . filter ( ( { id} ) => ! emotes . some ( e => e . id === id ) ) } ) ;
37- }
38-
39- updateEmotes ( emotes ) {
40- const guild = this . props . guilds [ this . props . guildID ] ;
41- let totals = [
42- this . state . emotes . filter ( e => ! e . animated ) . length ,
43- this . state . emotes . filter ( e => e . animated ) . length
44- ] ;
45- const concat = emotes . filter ( emote => totals [ emote . animated ? 1 : 0 ] ++ < guild . emote_limit ) ;
46- const filteredEmotes = this . state . emotes . filter ( ( { id} ) => ! concat . some ( e => e . id === id ) ) . concat ( concat ) ;
47- this . setState ( { emotes : filteredEmotes } ) ;
48- }
49-
50- save ( ) {
51- this . props . postGuildEmotes ( this . props . guildID , this . state . emotes , ( ids ) => {
52- const emotes = this . state . emotes . map ( emote => {
53- if ( Object . keys ( ids ) . includes ( emote . id ) ) {
54- emote . id = ids [ emote . id ] ;
55- }
56- return emote ;
57- } ) ;
58- console . log ( emotes ) ;
59- this . props . receiveGuildEmotes ( this . props . guildID , emotes ) ;
60- } ) ;
61- }
62-
63- render ( ) {
64- const guild = this . props . guilds [ this . props . guildID ] ;
65-
66- if ( ! guild . bot_permissions . includes ( "manage_emojis" ) ) {
67- return (
68- < Container >
69- < Header as = "b" >
70- This server does not allow the bot to manage emotes, so you cannot change them here.
71- </ Header >
72- < Divider hidden = { true } />
73- < EmotePreview emotes = { this . state . emotes } modifiable = { false } />
74- </ Container >
75- ) ;
76- }
77- return (
78- < Container >
79- < Menu >
80- < Menu . Item
81- position = 'right'
82- >
83- { this . state . emotes . filter ( e => ! e . animated ) . length } / { guild . emote_limit } Static
84- </ Menu . Item >
85- < Menu . Item
86- position = 'right'
87- >
88- { this . state . emotes . filter ( e => e . animated ) . length } / { guild . emote_limit } Animated
89- </ Menu . Item >
90- < Menu . Item
91- position = 'right'
92- >
93- < Button
94- primary
95- icon
96- labelPosition = "right"
97- onClick = { ( ) => this . save ( ) }
98- >
99- Save
100- < Icon name = 'save' />
101- </ Button >
102- </ Menu . Item >
103- </ Menu >
104- < EmotePreview
105- emotes = { this . state . emotes }
106- setAliases = { ( emotes ) => this . updateEmotes ( emotes ) }
107- changeAliases = { ( emotes ) => this . updateEmotes ( emotes ) }
108- unsetAliases = { ( emotes ) => this . unsetNames ( emotes ) }
109- modifiable = { true }
110- />
111- </ Container >
112- ) ;
113- }
1+ import React , { useState } from "react" ;
2+
3+ import { Container , Menu } from 'semantic-ui-react' ;
4+
5+ import EmoteGroup from "../../../components/emoteGroup" ;
6+
7+ function EmoteSettings ( props ) {
8+ const [ emotePopup , setEmotePopup ] = useState ( null ) ;
9+
10+ return (
11+ < Container >
12+ < Menu >
13+ < Menu . Item
14+ position = 'right'
15+ >
16+ { props . emotes . filter ( e => ! e . animated ) . length } / { props . guild . emote_limit } Static
17+ </ Menu . Item >
18+ < Menu . Item
19+ position = 'right'
20+ >
21+ { props . emotes . filter ( e => e . animated ) . length } / { props . guild . emote_limit } Animated
22+ </ Menu . Item >
23+ </ Menu >
24+
25+ < EmoteGroup
26+ packName = { null }
27+ emotes = { props . emotes }
28+ title = { `"${ props . guild . name } " Emojis` }
29+ downloadAll = "Download all emojis as zip"
30+ fileName = { `${ props . guild . name } .zip` }
31+ emotePopup = { emotePopup }
32+ setEmotePopup = { setEmotePopup }
33+ />
34+ </ Container >
35+ ) ;
11436}
11537
116- const mapStateToProps = ( state ) => {
117- return {
118- guilds : state . user . guilds ,
119- emotes : state . user . guild_emotes ,
120- }
121- } ;
122-
123- const mapDispatchToProps = dispatch => {
124- return {
125- postGuildEmotes : ( guildID , emotes , cb ) => dispatch ( postGuildEmotes ( guildID , emotes , cb ) ) ,
126- receiveGuildEmotes : ( guildID , emotes ) => dispatch ( receiveGuildEmotes ( guildID , emotes ) )
127- }
128- } ;
12938
130- export default withRouter ( connect (
131- mapStateToProps ,
132- mapDispatchToProps
133- ) ( EmoteSettings ) ) ;
39+ export default EmoteSettings ;
0 commit comments