PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / reviews / assets / src / hooks / use-settings.js

use-settings.js in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at modules/reviews/assets/src/hooks/use-settings.js

72 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useState, createContext, useContext } from '@wordpress/element';
2
3 /**
4 * Context Component.
5 */
6 const SettingsContext = createContext( null );
7
8 export function useSettings() {
9 return useContext( SettingsContext );
10 }
11
12 const SettingsProvider = ( { children } ) => {
13 const [ rating, setRating ] = useState( 0 );
14 const [ feedback, setFeedback ] = useState( '' );
15 const [ currentPage, setCurrentPage ] = useState( 'ratings' );
16 const [ nextButtonDisabled, setNextButtonDisabled ] = useState( true );
17 const [ isOpened, setIsOpened ] = useState( true );
18
19 // Notification
20 const [ showNotification, setShowNotification ] = useState( false );
21 const [ notificationMessage, setNotificationMessage ] = useState( '' );
22 const [ notificationType, setNotificationType ] = useState( '' );
23
24 return (
25 <SettingsContext.Provider
26 value={ {
27 rating,
28 setRating,
29 feedback,
30 setFeedback,
31 currentPage,
32 setCurrentPage,
33 nextButtonDisabled,
34 setNextButtonDisabled,
35 showNotification,
36 setShowNotification,
37 notificationMessage,
38 setNotificationMessage,
39 notificationType,
40 setNotificationType,
41 isOpened,
42 setIsOpened,
43 } }
44 >
45 { children }
46 </SettingsContext.Provider>
47 );
48 };
49
50 export const useNotifications = () => {
51 const { setNotificationMessage, setNotificationType, setShowNotification } = useContext( SettingsContext );
52
53 const error = ( message ) => {
54 setNotificationMessage( message );
55 setNotificationType( 'error' );
56 setShowNotification( true );
57 };
58
59 const success = ( message ) => {
60 setNotificationMessage( message );
61 setNotificationType( 'success' );
62 setShowNotification( true );
63 };
64
65 return {
66 success,
67 error,
68 };
69 };
70
71 export default SettingsProvider;
72