mirror of
				https://github.com/Alamantus/Lexiconga.git
				synced 2025-10-31 16:36:45 +01:00 
			
		
		
		
	Add word deletion with SweetAlert2 confirmation
This commit is contained in:
		
							parent
							
								
									3f7444de62
								
							
						
					
					
						commit
						5bd4582719
					
				
					 7 changed files with 77 additions and 31 deletions
				
			
		|  | @ -53,6 +53,7 @@ | ||||||
|     "marked": "^0.3.6", |     "marked": "^0.3.6", | ||||||
|     "papaparse": "^4.3.3", |     "papaparse": "^4.3.3", | ||||||
|     "sanitize-html": "^1.14.1", |     "sanitize-html": "^1.14.1", | ||||||
|     "store": "^2.0.12" |     "store": "^2.0.12", | ||||||
|  |     "sweetalert2": "^6.11.5" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -33,7 +33,8 @@ export const MainDisplay = ({ dictionaryInfo, wordsToDisplay, updateDisplay, upd | ||||||
|             <WordsList |             <WordsList | ||||||
|               lastRender={ lastRender } |               lastRender={ lastRender } | ||||||
|               words={ wordsToDisplay } |               words={ wordsToDisplay } | ||||||
|               adsEveryXWords={ 10 } /> |               adsEveryXWords={ 10 } | ||||||
|  |               updateDisplay={ updateDisplay } /> | ||||||
|           </RightColumn> |           </RightColumn> | ||||||
|            |            | ||||||
|         </div> |         </div> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| import Inferno from 'inferno'; | import Inferno from 'inferno'; | ||||||
| import Component from 'inferno-component'; | import Component from 'inferno-component'; | ||||||
| import marked from 'marked'; | import marked from 'marked'; | ||||||
|  | import swal from 'sweetalert2'; | ||||||
| 
 | 
 | ||||||
| import './WordDisplay.scss'; | import './WordDisplay.scss'; | ||||||
| 
 | 
 | ||||||
|  | @ -34,17 +35,48 @@ export class WordDisplay extends Component { | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   delete () { | ||||||
|  |     const { word } = this.props; | ||||||
|  |     swal({ | ||||||
|  |       title: `Delete "${ word.name }"?`, | ||||||
|  |       text: `It will be gone forever and cannot be restored!`, | ||||||
|  |       type: 'warning', | ||||||
|  |       showCancelButton: true, | ||||||
|  |       confirmButtonText: 'Yes, delete it!', | ||||||
|  |       cancelButtonText: 'No, cancel!', | ||||||
|  |       confirmButtonClass: 'button is-danger', | ||||||
|  |       cancelButtonClass: 'button', | ||||||
|  |       buttonsStyling: false | ||||||
|  |     }).then(() => { | ||||||
|  |       word.delete(word.id) | ||||||
|  |       .then(() => { | ||||||
|  |         this.props.updateDisplay(); | ||||||
|  |       }).then(() => { | ||||||
|  |         this.setState({ menuIsOpen: false }, () => { | ||||||
|  |           swal( | ||||||
|  |             'Deleted!', | ||||||
|  |             `"${ word.name }" has been deleted.`, | ||||||
|  |             'success' | ||||||
|  |           ); | ||||||
|  |         }); | ||||||
|  |       }); | ||||||
|  |     }, dismiss => { | ||||||
|  |       console.log('Word not deleted'); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   render () { |   render () { | ||||||
|     const { menuIsOpen, isEditing } = this.state; |     const { menuIsOpen, isEditing } = this.state; | ||||||
|  |     const { word } = this.props; | ||||||
| 
 | 
 | ||||||
|     if (isEditing) { |     if (isEditing) { | ||||||
|       return ( |       return ( | ||||||
|         <WordForm |         <WordForm | ||||||
|           name={this.props.word.name} |           name={word.name} | ||||||
|           pronunciation={this.props.word.pronunciation} |           pronunciation={word.pronunciation} | ||||||
|           partOfSpeech={this.props.word.partOfSpeech} |           partOfSpeech={word.partOfSpeech} | ||||||
|           definition={this.props.word.definition} |           definition={word.definition} | ||||||
|           details={this.props.word.details} |           details={word.details} | ||||||
|         /> |         /> | ||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|  | @ -54,26 +86,26 @@ export class WordDisplay extends Component { | ||||||
|         <header className='card-header'> |         <header className='card-header'> | ||||||
|           <div className='word-card-header-title'> |           <div className='word-card-header-title'> | ||||||
|             <span className='word-name'> |             <span className='word-name'> | ||||||
|               { this.props.word.name } |               { word.name } | ||||||
|             </span> |             </span> | ||||||
|             { |             { | ||||||
|               (this.props.word.pronunciation || this.props.word.partOfSpeech) |               (word.pronunciation || word.partOfSpeech) | ||||||
|               && ( |               && ( | ||||||
|                 <span className='word-classification'> |                 <span className='word-classification'> | ||||||
|                   { |                   { | ||||||
|                     (this.props.word.pronunciation) |                     (word.pronunciation) | ||||||
|                     && ( |                     && ( | ||||||
|                       <span className='word-pronunciation'> |                       <span className='word-pronunciation'> | ||||||
|                       { this.props.word.pronunciation } |                       { word.pronunciation } | ||||||
|                       </span> |                       </span> | ||||||
|                     ) |                     ) | ||||||
|                   } |                   } | ||||||
| 
 | 
 | ||||||
|                   { |                   { | ||||||
|                     (this.props.word.partOfSpeech) |                     (word.partOfSpeech) | ||||||
|                     && ( |                     && ( | ||||||
|                       <span className='word-part-of-speech'> |                       <span className='word-part-of-speech'> | ||||||
|                       { this.props.word.partOfSpeech } |                       { word.partOfSpeech } | ||||||
|                       </span> |                       </span> | ||||||
|                     ) |                     ) | ||||||
|                   } |                   } | ||||||
|  | @ -94,7 +126,7 @@ export class WordDisplay extends Component { | ||||||
|                 <a className='dropdown-item' onClick={ this.edit.bind(this) }> |                 <a className='dropdown-item' onClick={ this.edit.bind(this) }> | ||||||
|                   Edit |                   Edit | ||||||
|                 </a> |                 </a> | ||||||
|                 <a className='dropdown-item is-danger'> |                 <a onClick={ this.delete.bind(this) } className='dropdown-item is-danger'> | ||||||
|                   Delete |                   Delete | ||||||
|                 </a> |                 </a> | ||||||
|               </div> |               </div> | ||||||
|  | @ -105,16 +137,16 @@ export class WordDisplay extends Component { | ||||||
|         <section className='card-content'> |         <section className='card-content'> | ||||||
|           <div className='content'> |           <div className='content'> | ||||||
|             { |             { | ||||||
|               (this.props.word.definition) |               (word.definition) | ||||||
|               && ( |               && ( | ||||||
|                 <p className='word-definition'> |                 <p className='word-definition'> | ||||||
|                   { this.props.word.definition } |                   { word.definition } | ||||||
|                 </p> |                 </p> | ||||||
|               ) |               ) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             { |             { | ||||||
|               (this.props.word.details) |               (word.details) | ||||||
|               && ( |               && ( | ||||||
|                 <p className='word-details' |                 <p className='word-details' | ||||||
|                   dangerouslySetInnerHTML={{__html: this.wordDetailsHTML}} /> |                   dangerouslySetInnerHTML={{__html: this.wordDetailsHTML}} /> | ||||||
|  |  | ||||||
|  | @ -29,20 +29,16 @@ export class WordsList extends Component { | ||||||
| 
 | 
 | ||||||
|         {this.props.words |         {this.props.words | ||||||
|           && this.props.words.map((word, index) => { |           && this.props.words.map((word, index) => { | ||||||
|             if (index % adsEveryXWords == 0) { |  | ||||||
|             return ( |             return ( | ||||||
|               <div> |               <div> | ||||||
|                   <LazyLoader lazyLoad={ loadAd } /> |                 {index % adsEveryXWords == 0 | ||||||
|                    |                   && <LazyLoader lazyLoad={ loadAd } /> | ||||||
|                   <WordDisplay key={ `word_${word.id}` } |  | ||||||
|                     word={ word } /> |  | ||||||
|                 </div> |  | ||||||
|               ); |  | ||||||
|                 } |                 } | ||||||
|                  |                  | ||||||
|             return ( |  | ||||||
|                 <WordDisplay key={ `word_${word.id}` } |                 <WordDisplay key={ `word_${word.id}` } | ||||||
|                 word={ word } /> |                   word={ word } | ||||||
|  |                   updateDisplay={ this.props.updateDisplay } /> | ||||||
|  |               </div> | ||||||
|             ); |             ); | ||||||
|           }) |           }) | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -38,4 +38,14 @@ export class Word { | ||||||
|       console.error(error); |       console.error(error); | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   delete (wordId) { | ||||||
|  |     return wordDb.words.delete(wordId) | ||||||
|  |     .then(() => { | ||||||
|  |       console.log('Word deleted successfully'); | ||||||
|  |     }) | ||||||
|  |     .catch(error => { | ||||||
|  |       console.error(error); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,4 +6,6 @@ $fa-font-path: "~font-awesome/fonts/"; | ||||||
| @import 'bulma-overrides'; | @import 'bulma-overrides'; | ||||||
| @import '../../node_modules/bulma/bulma'; | @import '../../node_modules/bulma/bulma'; | ||||||
| 
 | 
 | ||||||
|  | @import '../../node_modules/sweetalert2/dist/sweetalert2'; | ||||||
|  | 
 | ||||||
| @import 'styles'; | @import 'styles'; | ||||||
|  |  | ||||||
|  | @ -4104,6 +4104,10 @@ svgo@^0.7.0: | ||||||
|     sax "~1.2.1" |     sax "~1.2.1" | ||||||
|     whet.extend "~0.9.9" |     whet.extend "~0.9.9" | ||||||
| 
 | 
 | ||||||
|  | sweetalert2@^6.11.5: | ||||||
|  |   version "6.11.5" | ||||||
|  |   resolved "https://registry.yarnpkg.com/sweetalert2/-/sweetalert2-6.11.5.tgz#a1ede34089225eb864898f4b613db4fec5dbe334" | ||||||
|  | 
 | ||||||
| tapable@^0.2.7: | tapable@^0.2.7: | ||||||
|   version "0.2.8" |   version "0.2.8" | ||||||
|   resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22" |   resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue