From 9e293b67574bc292f0ff22013686f4741bda30ff Mon Sep 17 00:00:00 2001 From: CodeDead Date: Fri, 17 Jan 2025 16:05:32 +0100 Subject: [PATCH 1/2] feat: added a setting to sort by password strength by default (default = true) --- src/contexts/MainContextProvider/index.jsx | 2 ++ src/languages/de_de.json | 3 ++- src/languages/en_us.json | 3 ++- src/languages/es_es.json | 3 ++- src/languages/fr_fr.json | 3 ++- src/languages/jp_jp.json | 3 ++- src/languages/nl_nl.json | 3 ++- src/languages/ru_ru.json | 3 ++- src/languages/tr_tr.json | 3 ++- src/languages/zh_cn.json | 3 ++- src/reducers/MainReducer/Actions/actionTypes.js | 1 + src/reducers/MainReducer/Actions/index.js | 6 ++++++ src/reducers/MainReducer/index.js | 9 ++++++++- src/routes/Generate/index.jsx | 10 ++++++++-- src/routes/Settings/index.jsx | 13 ++++++++++++- yarn.lock | 16 ++++++++-------- 16 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/contexts/MainContextProvider/index.jsx b/src/contexts/MainContextProvider/index.jsx index de63e2b..0394898 100644 --- a/src/contexts/MainContextProvider/index.jsx +++ b/src/contexts/MainContextProvider/index.jsx @@ -19,6 +19,7 @@ const languageSelector = localStorage.languageSelector ? (localStorage.languageSelector === 'true') : false; const tips = localStorage.tips ? (localStorage.tips === 'true') : true; +const sortByStrength = localStorage.sortByStrength ? (localStorage.sortByStrength === 'true') : true; let hasSetCookies = false; let allowCookies = true; @@ -53,6 +54,7 @@ const initState = { tips, allowCookies, hasSetCookies, + sortByStrength, }; export const MainContext = createContext(initState); diff --git a/src/languages/de_de.json b/src/languages/de_de.json index 4b2976e..5235246 100644 --- a/src/languages/de_de.json +++ b/src/languages/de_de.json @@ -134,5 +134,6 @@ "exportSuccessful": "Export erfolgreich", "cookieNoticeText": "Diese Website verwendet Cookies, um sicherzustellen, dass Sie die bestmögliche Erfahrung auf unserer Website haben.", "accept": "Akzeptieren", - "reject": "Ablehnen" + "reject": "Ablehnen", + "sortByStrength": "Standardmäßig nach Stärke sortieren" } diff --git a/src/languages/en_us.json b/src/languages/en_us.json index 17c3d48..79693b8 100644 --- a/src/languages/en_us.json +++ b/src/languages/en_us.json @@ -136,5 +136,6 @@ "exportSuccessful": "Export successful", "cookieNoticeText": "This website uses cookies to ensure you get the best experience on our website.", "accept": "Accept", - "reject": "Reject" + "reject": "Reject", + "sortByStrength": "Sort by strength by default" } diff --git a/src/languages/es_es.json b/src/languages/es_es.json index 19e2212..931d57d 100644 --- a/src/languages/es_es.json +++ b/src/languages/es_es.json @@ -136,5 +136,6 @@ "exportSuccessful": "Exportación exitosa", "cookieNoticeText": "Este sitio web utiliza cookies para garantizar que obtenga la mejor experiencia en nuestro sitio web.", "accept": "Aceptar", - "reject": "Rechazar" + "reject": "Rechazar", + "sortByStrength": "Ordenar por fuerza de forma predeterminada" } diff --git a/src/languages/fr_fr.json b/src/languages/fr_fr.json index 847e6b5..1d703fd 100644 --- a/src/languages/fr_fr.json +++ b/src/languages/fr_fr.json @@ -133,5 +133,6 @@ "exportSuccessful": "Exportation réussie", "cookieNoticeText": "Ce site utilise des cookies pour vous garantir la meilleure expérience sur notre site.", "accept": "Accepter", - "reject": "Rejeter" + "reject": "Rejeter", + "sortByStrength": "Trier par force par défaut" } diff --git a/src/languages/jp_jp.json b/src/languages/jp_jp.json index 199b8c3..6307fd9 100644 --- a/src/languages/jp_jp.json +++ b/src/languages/jp_jp.json @@ -133,5 +133,6 @@ "exportSuccessful": "エクスポートに成功しました", "cookieNoticeText": "このサイトはクッキーを使用しています。 クッキーを使用することに同意する場合は、この通知を閉じてください。", "accept": "受け入れる", - "reject": "拒否する" + "reject": "拒否する", + "sortByStrength": "デフォルトで強さ順に並べ替え" } diff --git a/src/languages/nl_nl.json b/src/languages/nl_nl.json index 2531695..51187c2 100644 --- a/src/languages/nl_nl.json +++ b/src/languages/nl_nl.json @@ -135,5 +135,6 @@ "exportSuccessful": "Export aangemaakt", "cookieNoticeText": "Deze website maakt gebruik van cookies om ervoor te zorgen dat je de beste ervaring op onze website krijgt.", "accept": "Accepteren", - "reject": "Afwijzen" + "reject": "Afwijzen", + "sortByStrength": "Standaard sorteren op sterkte" } diff --git a/src/languages/ru_ru.json b/src/languages/ru_ru.json index ae51870..3c5181e 100644 --- a/src/languages/ru_ru.json +++ b/src/languages/ru_ru.json @@ -134,5 +134,6 @@ "exportSuccessful": "Экспорт успешно завершен!", "cookieNoticeText": "Этот сайт использует файлы cookie, чтобы обеспечить вам лучший опыт на нашем сайте.", "accept": "Принять", - "reject": "Отклонить" + "reject": "Отклонить", + "sortByStrength": "Сортировать по силе по умолчанию" } diff --git a/src/languages/tr_tr.json b/src/languages/tr_tr.json index c0d8e43..773099f 100644 --- a/src/languages/tr_tr.json +++ b/src/languages/tr_tr.json @@ -136,5 +136,6 @@ "exportSuccessful": "Başarıyla dışa aktarıldı", "cookieNoticeText": "Bu site, size sitemizde en iyi deneyimi sunmak için çerezler kullanır. Çerez kullanımını kabul ediyorsanız, bu bildirimi kapatın.", "accept": "Kabul etmek", - "reject": "Reddetmek" + "reject": "Reddetmek", + "sortByStrength": "Varsayılan olarak güce göre sırala" } diff --git a/src/languages/zh_cn.json b/src/languages/zh_cn.json index 49f1375..0d2572e 100644 --- a/src/languages/zh_cn.json +++ b/src/languages/zh_cn.json @@ -134,5 +134,6 @@ "exportSuccessful": "导出成功", "cookieNoticeText": "本网站使用 Cookie。如果您同意使用 Cookie,请关闭此通知。", "accept": "接受", - "reject": "拒绝" + "reject": "拒绝", + "sortByStrength": "默认按强度排序" } diff --git a/src/reducers/MainReducer/Actions/actionTypes.js b/src/reducers/MainReducer/Actions/actionTypes.js index 94feabc..7989de3 100644 --- a/src/reducers/MainReducer/Actions/actionTypes.js +++ b/src/reducers/MainReducer/Actions/actionTypes.js @@ -12,3 +12,4 @@ export const SET_CHECKED_FOR_UPDATES = 'SET_CHECKED_FOR_UPDATES'; export const SET_COLOR_ON_DARK = 'SET_COLOR_ON_DARK'; export const SET_TIPS = 'SET_TIPS'; export const SET_ALLOW_COOKIES = 'SET_ALLOW_COOKIES'; +export const SET_DEFAULT_SORT_BY_STRENGTH = 'SET_DEFAULT_SORT_BY_STRENGTH'; diff --git a/src/reducers/MainReducer/Actions/index.js b/src/reducers/MainReducer/Actions/index.js index cb80d99..5866314 100644 --- a/src/reducers/MainReducer/Actions/index.js +++ b/src/reducers/MainReducer/Actions/index.js @@ -5,6 +5,7 @@ import { SET_AUTO_UPDATE, SET_CHECKED_FOR_UPDATES, SET_COLOR_ON_DARK, + SET_DEFAULT_SORT_BY_STRENGTH, SET_ERROR, SET_LANGUAGE_INDEX, SET_LANGUAGE_SELECTOR, @@ -97,3 +98,8 @@ export const setAllowCookies = (allow) => ({ type: SET_ALLOW_COOKIES, payload: allow, }); + +export const setDefaultSortByStrength = (value) => ({ + type: SET_DEFAULT_SORT_BY_STRENGTH, + payload: value, +}); diff --git a/src/reducers/MainReducer/index.js b/src/reducers/MainReducer/index.js index d111cad..d19d720 100644 --- a/src/reducers/MainReducer/index.js +++ b/src/reducers/MainReducer/index.js @@ -3,7 +3,7 @@ import { SET_ALLOW_COOKIES, SET_AUTO_UPDATE, SET_CHECKED_FOR_UPDATES, - SET_COLOR_ON_DARK, + SET_COLOR_ON_DARK, SET_DEFAULT_SORT_BY_STRENGTH, SET_ERROR, SET_LANGUAGE_INDEX, SET_LANGUAGE_SELECTOR, @@ -54,6 +54,7 @@ const MainReducer = (state, action) => { languageSelector: false, colorOnDark: false, tips: true, + sortByStrength: true, }; case SET_AUTO_UPDATE: localStorage.autoUpdate = action.payload; @@ -105,6 +106,12 @@ const MainReducer = (state, action) => { ...state, allowCookies: action.payload, }; + case SET_DEFAULT_SORT_BY_STRENGTH: + localStorage.sortByStrength = action.payload; + return { + ...state, + sortByStrength: action.payload, + }; default: return state; } diff --git a/src/routes/Generate/index.jsx b/src/routes/Generate/index.jsx index c6ecaa1..fd14309 100644 --- a/src/routes/Generate/index.jsx +++ b/src/routes/Generate/index.jsx @@ -31,7 +31,9 @@ const Generate = () => { const [state1, d1] = useContext(MainContext); const [state2, d2] = useContext(PasswordContext); - const { languageIndex, loading, allowCookies } = state1; + const { + languageIndex, loading, allowCookies, sortByStrength, + } = state1; const language = state1.languages[languageIndex]; const [exportType, setExportType] = useState('application/json'); @@ -228,12 +230,16 @@ const Generate = () => { } }, []); - const passwordRows = []; + let passwordRows = []; if (passwords && passwords.length > 0) { const splitter = new Graphemer(); passwords.forEach((e, i) => { passwordRows.push(createData(`${e}${i}`, e, splitter.countGraphemes(e), PasswordStrength(e))); }); + + if (sortByStrength) { + passwordRows = passwordRows.sort((a, b) => parseFloat(b.strength) - parseFloat(a.strength)); + } } if (loading) { diff --git a/src/routes/Settings/index.jsx b/src/routes/Settings/index.jsx index ced8867..90ed1da 100644 --- a/src/routes/Settings/index.jsx +++ b/src/routes/Settings/index.jsx @@ -42,7 +42,7 @@ import { resetState, setAutoUpdate, setCheckedForUpdates, - setColorOnDark, + setColorOnDark, setDefaultSortByStrength, setError, setLanguageIndex, setLanguageSelector, @@ -69,6 +69,7 @@ const Settings = () => { colorOnDark, tips, allowCookies, + sortByStrength, } = state; const language = state.languages[languageIndex]; @@ -210,6 +211,16 @@ const Settings = () => { )} label={language.languageSelector} /> + d1(setDefaultSortByStrength(e.target.checked))} + value="strengthSortSelector" + /> + )} + label={language.sortByStrength} + /> {language.language}