feat: close #2141 danger zone

This commit is contained in:
Yidadaa 2023-06-29 01:09:51 +08:00
parent 98afd5516b
commit 6c3d4a11cc
19 changed files with 106 additions and 139 deletions

View File

@ -28,6 +28,21 @@
} }
} }
&.danger {
color: rgba($color: red, $alpha: 0.8);
border-color: rgba($color: red, $alpha: 0.5);
background-color: rgba($color: red, $alpha: 0.05);
&:hover {
border-color: red;
background-color: rgba($color: red, $alpha: 0.1);
}
path {
fill: red !important;
}
}
&:hover, &:hover,
&:focus { &:focus {
border-color: var(--primary); border-color: var(--primary);
@ -57,9 +72,12 @@
} }
.icon-button-text { .icon-button-text {
margin-left: 5px;
font-size: 12px; font-size: 12px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
&:not(:first-child) {
margin-left: 5px;
}
} }

View File

@ -2,10 +2,12 @@ import * as React from "react";
import styles from "./button.module.scss"; import styles from "./button.module.scss";
export type ButtonType = "primary" | "danger" | null;
export function IconButton(props: { export function IconButton(props: {
onClick?: () => void; onClick?: () => void;
icon?: JSX.Element; icon?: JSX.Element;
type?: "primary" | "danger"; type?: ButtonType;
text?: string; text?: string;
bordered?: boolean; bordered?: boolean;
shadow?: boolean; shadow?: boolean;

View File

@ -59,9 +59,7 @@ export class ErrorBoundary extends React.Component<any, IErrorBoundaryState> {
icon={<ResetIcon />} icon={<ResetIcon />}
text="Clear All Data" text="Clear All Data"
onClick={async () => { onClick={async () => {
if ( if (await showConfirm(Locale.Settings.Danger.Reset.Confirm)) {
await showConfirm(Locale.Settings.Actions.ConfirmClearAll)
) {
this.clearAndSaveData(); this.clearAndSaveData();
} }
}} }}

View File

@ -200,6 +200,44 @@ function UserPromptModal(props: { onClose?: () => void }) {
); );
} }
function DangerItems() {
const chatStore = useChatStore();
const appConfig = useAppConfig();
return (
<List>
<ListItem
title={Locale.Settings.Danger.Reset.Title}
subTitle={Locale.Settings.Danger.Reset.SubTitle}
>
<IconButton
text={Locale.Settings.Danger.Reset.Action}
onClick={async () => {
if (await showConfirm(Locale.Settings.Danger.Reset.Confirm)) {
appConfig.reset();
}
}}
type="danger"
/>
</ListItem>
<ListItem
title={Locale.Settings.Danger.Clear.Title}
subTitle={Locale.Settings.Danger.Clear.SubTitle}
>
<IconButton
text={Locale.Settings.Danger.Clear.Action}
onClick={async () => {
if (await showConfirm(Locale.Settings.Danger.Clear.Confirm)) {
chatStore.clearAllData();
}
}}
type="danger"
/>
</ListItem>
</List>
);
}
function SyncItems() { function SyncItems() {
const syncStore = useSyncStore(); const syncStore = useSyncStore();
const webdav = syncStore.webDavConfig; const webdav = syncStore.webDavConfig;
@ -290,7 +328,6 @@ export function Settings() {
const [showEmojiPicker, setShowEmojiPicker] = useState(false); const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const config = useAppConfig(); const config = useAppConfig();
const updateConfig = config.update; const updateConfig = config.update;
const resetConfig = config.reset;
const chatStore = useChatStore(); const chatStore = useChatStore();
const updateStore = useUpdateStore(); const updateStore = useUpdateStore();
@ -375,40 +412,13 @@ export function Settings() {
</div> </div>
</div> </div>
<div className="window-actions"> <div className="window-actions">
<div className="window-action-button"> <div className="window-action-button"></div>
<IconButton <div className="window-action-button"></div>
icon={<ClearIcon />}
onClick={async () => {
if (
await showConfirm(Locale.Settings.Actions.ConfirmClearAll)
) {
chatStore.clearAllData();
}
}}
bordered
title={Locale.Settings.Actions.ClearAll}
/>
</div>
<div className="window-action-button">
<IconButton
icon={<ResetIcon />}
onClick={async () => {
if (
await showConfirm(Locale.Settings.Actions.ConfirmResetAll)
) {
resetConfig();
}
}}
bordered
title={Locale.Settings.Actions.ResetAll}
/>
</div>
<div className="window-action-button"> <div className="window-action-button">
<IconButton <IconButton
icon={<CloseIcon />} icon={<CloseIcon />}
onClick={() => navigate(Path.Home)} onClick={() => navigate(Path.Home)}
bordered bordered
title={Locale.Settings.Actions.Close}
/> />
</div> </div>
</div> </div>
@ -691,6 +701,8 @@ export function Settings() {
{shouldShowPromptModal && ( {shouldShowPromptModal && (
<UserPromptModal onClose={() => setShowPromptModal(false)} /> <UserPromptModal onClose={() => setShowPromptModal(false)} />
)} )}
<DangerItems />
</div> </div>
</ErrorBoundary> </ErrorBoundary>
); );

View File

@ -100,13 +100,7 @@ const ar: PartialLocaleType = {
Settings: { Settings: {
Title: "الإعدادات", Title: "الإعدادات",
SubTitle: "جميع الإعدادات", SubTitle: "جميع الإعدادات",
Actions: {
ClearAll: "مسح جميع البيانات",
ResetAll: "إعادة تعيين جميع الإعدادات",
Close: "إغلاق",
ConfirmResetAll: "هل أنت متأكد من رغبتك في إعادة تعيين جميع الإعدادات؟",
ConfirmClearAll: "هل أنت متأكد من رغبتك في مسح جميع البيانات؟",
},
Lang: { Lang: {
Name: "Language", // تنبيه: إذا كنت ترغب في إضافة ترجمة جديدة، يرجى عدم ترجمة هذه القيمة وتركها "Language" Name: "Language", // تنبيه: إذا كنت ترغب في إضافة ترجمة جديدة، يرجى عدم ترجمة هذه القيمة وتركها "Language"
All: "كل اللغات", All: "كل اللغات",

View File

@ -108,13 +108,21 @@ const cn = {
}, },
Settings: { Settings: {
Title: "设置", Title: "设置",
SubTitle: "设置选项", SubTitle: "所有设置选项",
Actions: {
ClearAll: "清除所有数据", Danger: {
ResetAll: "重置所有选项", Reset: {
Close: "关闭", Title: "重置所有设置",
ConfirmResetAll: "确认重置所有配置?", SubTitle: "重置所有设置项回默认值",
ConfirmClearAll: "确认清除所有数据?", Action: "立即重置",
Confirm: "确认重置所有设置?",
},
Clear: {
Title: "清除所有数据",
SubTitle: "清除所有聊天、设置数据",
Action: "立即清除",
Confirm: "确认清除所有聊天、设置数据?",
},
}, },
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`

View File

@ -61,13 +61,7 @@ const cs: PartialLocaleType = {
Settings: { Settings: {
Title: "Nastavení", Title: "Nastavení",
SubTitle: "Všechna nastavení", SubTitle: "Všechna nastavení",
Actions: {
ClearAll: "Vymazat všechna data",
ResetAll: "Obnovit veškeré nastavení",
Close: "Zavřít",
ConfirmResetAll: "Jste si jisti, že chcete obnovit všechna nastavení?",
ConfirmClearAll: "Jste si jisti, že chcete smazat všechna data?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Všechny jazyky", All: "Všechny jazyky",

View File

@ -61,14 +61,7 @@ const de: PartialLocaleType = {
Settings: { Settings: {
Title: "Einstellungen", Title: "Einstellungen",
SubTitle: "Alle Einstellungen", SubTitle: "Alle Einstellungen",
Actions: {
ClearAll: "Alle Daten löschen",
ResetAll: "Alle Einstellungen zurücksetzen",
Close: "Schließen",
ConfirmResetAll:
"Möchten Sie wirklich alle Konfigurationen zurücksetzen?",
ConfirmClearAll: "Möchten Sie wirklich alle Chats zurücksetzen?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Alle Sprachen", All: "Alle Sprachen",

View File

@ -111,12 +111,19 @@ const en: LocaleType = {
Settings: { Settings: {
Title: "Settings", Title: "Settings",
SubTitle: "All Settings", SubTitle: "All Settings",
Actions: { Danger: {
ClearAll: "Clear All Data", Reset: {
ResetAll: "Reset All Settings", Title: "Reset All Settings",
Close: "Close", SubTitle: "Reset all setting items to default",
ConfirmResetAll: "Are you sure you want to reset all configurations?", Action: "Reset",
ConfirmClearAll: "Are you sure you want to reset all data?", Confirm: "Confirm to reset all settings to default?",
},
Clear: {
Title: "Clear All Data",
SubTitle: "Clear all messages and settings",
Action: "Clear",
Confirm: "Confirm to clear all messages and settings?",
},
}, },
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`

View File

@ -61,13 +61,7 @@ const es: PartialLocaleType = {
Settings: { Settings: {
Title: "Configuración", Title: "Configuración",
SubTitle: "Todas las configuraciones", SubTitle: "Todas las configuraciones",
Actions: {
ClearAll: "Borrar todos los datos",
ResetAll: "Restablecer todas las configuraciones",
Close: "Cerrar",
ConfirmResetAll: "Are you sure you want to reset all configurations?",
ConfirmClearAll: "Are you sure you want to reset all chat?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Todos los idiomas", All: "Todos los idiomas",

View File

@ -61,14 +61,7 @@ const fr: PartialLocaleType = {
Settings: { Settings: {
Title: "Paramètres", Title: "Paramètres",
SubTitle: "Toutes les configurations", SubTitle: "Toutes les configurations",
Actions: {
ClearAll: "Effacer toutes les données",
ResetAll: "Réinitialiser les configurations",
Close: "Fermer",
ConfirmResetAll:
"Êtes-vous sûr de vouloir réinitialiser toutes les configurations?",
ConfirmClearAll: "Êtes-vous sûr de vouloir supprimer toutes les données?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION : si vous souhaitez ajouter une nouvelle traduction, ne traduisez pas cette valeur, laissez-la sous forme de `Language` Name: "Language", // ATTENTION : si vous souhaitez ajouter une nouvelle traduction, ne traduisez pas cette valeur, laissez-la sous forme de `Language`
All: "Toutes les langues", All: "Toutes les langues",

View File

@ -61,13 +61,7 @@ const it: PartialLocaleType = {
Settings: { Settings: {
Title: "Impostazioni", Title: "Impostazioni",
SubTitle: "Tutte le impostazioni", SubTitle: "Tutte le impostazioni",
Actions: {
ClearAll: "Cancella tutti i dati",
ResetAll: "Resetta tutte le impostazioni",
Close: "Chiudi",
ConfirmResetAll: "Sei sicuro vuoi cancellare tutte le impostazioni?",
ConfirmClearAll: "Sei sicuro vuoi cancellare tutte le chat?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Tutte le lingue", All: "Tutte le lingue",

View File

@ -61,13 +61,7 @@ const jp: PartialLocaleType = {
Settings: { Settings: {
Title: "設定", Title: "設定",
SubTitle: "設定オプション", SubTitle: "設定オプション",
Actions: {
ClearAll: "すべてのデータをクリア",
ResetAll: "すべてのオプションをリセット",
Close: "閉じる",
ConfirmResetAll: "すべての設定をリセットしてもよろしいですか?",
ConfirmClearAll: "すべてのチャットをリセットしてもよろしいですか?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "全ての言語", All: "全ての言語",

View File

@ -61,13 +61,7 @@ const ko: PartialLocaleType = {
Settings: { Settings: {
Title: "설정", Title: "설정",
SubTitle: "모든 설정", SubTitle: "모든 설정",
Actions: {
ClearAll: "모든 데이터 지우기",
ResetAll: "모든 설정 초기화",
Close: "닫기",
ConfirmResetAll: "모든 설정을 초기화하시겠습니까?",
ConfirmClearAll: "모든 데이터를 지우시겠습니까?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "All Languages", All: "All Languages",

View File

@ -56,11 +56,7 @@ const no: PartialLocaleType = {
Settings: { Settings: {
Title: "Innstillinger", Title: "Innstillinger",
SubTitle: "Alle innstillinger", SubTitle: "Alle innstillinger",
Actions: {
ClearAll: "Fjern alle data",
ResetAll: "Nullstill innstillinger",
Close: "Lukk",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
}, },

View File

@ -61,13 +61,7 @@ const ru: PartialLocaleType = {
Settings: { Settings: {
Title: "Настройки", Title: "Настройки",
SubTitle: "Все настройки", SubTitle: "Все настройки",
Actions: {
ClearAll: "Очистить все данные",
ResetAll: "Сбросить все настройки",
Close: "Закрыть",
ConfirmResetAll: "Вы уверены, что хотите сбросить все настройки?",
ConfirmClearAll: "Вы уверены, что хотите очистить все данные?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Все языки", All: "Все языки",

View File

@ -61,13 +61,7 @@ const tr: PartialLocaleType = {
Settings: { Settings: {
Title: "Ayarlar", Title: "Ayarlar",
SubTitle: "Tüm Ayarlar", SubTitle: "Tüm Ayarlar",
Actions: {
ClearAll: "Tüm Verileri Temizle",
ResetAll: "Tüm Ayarları Sıfırla",
Close: "Kapat",
ConfirmResetAll: "Tüm ayarları sıfırlamak istediğinizden emin misiniz?",
ConfirmClearAll: "Tüm sohbeti sıfırlamak istediğinizden emin misiniz?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Tüm Diller", All: "Tüm Diller",

View File

@ -59,13 +59,7 @@ const tw: PartialLocaleType = {
Settings: { Settings: {
Title: "設定", Title: "設定",
SubTitle: "設定選項", SubTitle: "設定選項",
Actions: {
ClearAll: "清除所有資料",
ResetAll: "重設所有設定",
Close: "關閉",
ConfirmResetAll: "您確定要重設所有設定嗎?",
ConfirmClearAll: "您確定要清除所有数据嗎?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "所有语言", All: "所有语言",

View File

@ -61,13 +61,7 @@ const vi: PartialLocaleType = {
Settings: { Settings: {
Title: "Cài đặt", Title: "Cài đặt",
SubTitle: "Tất cả cài đặt", SubTitle: "Tất cả cài đặt",
Actions: {
ClearAll: "Xóa toàn bộ dữ liệu",
ResetAll: "Khôi phục cài đặt gốc",
Close: "Đóng",
ConfirmResetAll: "Bạn chắc chắn muốn thiết lập lại tất cả cài đặt?",
ConfirmClearAll: "Bạn chắc chắn muốn thiết lập lại tất cả dữ liệu?",
},
Lang: { Lang: {
Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
All: "Tất cả ngôn ngữ", All: "Tất cả ngôn ngữ",