Skip to content

Commit

Permalink
fix: problems when renaming languages
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Aug 4, 2024
1 parent f4999ff commit a1c00cc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ fn main() {
setup_stanza,
check_stanza_installed,
get_export_variables,
rename_language,
])
.on_window_event(handle_window_event)
.run(tauri::generate_context!())
Expand Down Expand Up @@ -470,6 +471,26 @@ async fn set_language(state: State<'_, KalbaState>, language: String) -> Result<
Ok(())
}

#[tauri::command]
async fn rename_language(
state: State<'_, KalbaState>,
original_name: String,
new_name: String,
) -> Result<(), String> {
let mut state = state.0.lock().await;
if let Some(old) = state.to_save.language_specific.remove(&original_name) {
state
.to_save
.language_specific
.insert(new_name.clone(), old);
}
if let Some(old) = state.language_cached_data.remove(&original_name) {
state.language_cached_data.insert(new_name.clone(), old);
}
state.current_language = Some(new_name);
Ok(())
}

#[tauri::command]
async fn write_settings(
state: State<'_, KalbaState>,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub async fn get_words_known_at_levels(
) -> Result<Vec<NumWordsKnown>, String> {
let state = state.0.lock().await;
let current_language = state.current_language.as_ref().expect("language to be set");
log::info!("loading stats for profile {current_language}");
let words = &state
.to_save
.language_specific
Expand Down
5 changes: 5 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ onMounted(async () => {
<router-view
:currentLanguage="currentLanguage"
@settingsChanged="updateLanguages"
@newCurrentLanguage="
updateLanguages();
console.log($event);
currentLanguage = $event;
"
></router-view>
</Suspense>
</main>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/settings/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ const props = defineProps<{
</script>

<template>
<Suspense><Settings :current-language="props.currentLanguage" /></Suspense>
<Suspense
><Settings
:current-language="props.currentLanguage"
@newCurrentLanguage="$emit('newCurrentLanguage', $event)"
/></Suspense>
</template>
12 changes: 10 additions & 2 deletions src/pages/settings/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ watch(
},
);
const emit = defineEmits(["settingsChanged"]);
const emit = defineEmits(["settingsChanged", "newCurrentLanguage"]);
console.log(settings);
Expand Down Expand Up @@ -294,12 +294,20 @@ async function newLanguage(language: string) {
class="w-64"
id="language-name"
@change="
() => {
async () => {
if (selectedLang === null) return;
const newName = languageNameChanges[selectedLang];
settings.languages[newName] = settings.languages[selectedLang];
delete settings.languages[selectedLang];
languageNameChanges[newName] = newName;
if (selectedLang === props.currentLanguage) {
await invoke('rename_language', {
originalName: selectedLang,
newName,
});
}
$emit('newCurrentLanguage', newName);
selectedLang = newName;
}
"
/>
Expand Down

0 comments on commit a1c00cc

Please sign in to comment.