2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 20:18:26 +00:00

refactor: use inject for languageDirection

- remove unnecessary spacer in pageheader when rtl
This commit is contained in:
18alantom 2023-01-27 14:13:36 +05:30
parent 3e1d3cee54
commit 1ca26a5c41
5 changed files with 20 additions and 29 deletions

View File

@ -54,7 +54,7 @@ import { initializeInstance } from './utils/initialization';
import { checkForUpdates } from './utils/ipcCalls'; import { checkForUpdates } from './utils/ipcCalls';
import { updateConfigFiles } from './utils/misc'; import { updateConfigFiles } from './utils/misc';
import { Search } from './utils/search'; import { Search } from './utils/search';
import { routeTo } from './utils/ui'; import { routeTo, systemLanguage } from './utils/ui';
import { Shortcuts, useKeys } from './utils/vueUtils'; import { Shortcuts, useKeys } from './utils/vueUtils';
export default { export default {
@ -69,8 +69,6 @@ export default {
companyName: '', companyName: '',
searcher: null, searcher: null,
shortcuts: null, shortcuts: null,
languageDirection: 'ltr',
language: '',
}; };
}, },
provide() { provide() {
@ -88,10 +86,6 @@ export default {
WindowsTitleBar, WindowsTitleBar,
}, },
async mounted() { async mounted() {
this.language = fyo.config.get('language');
this.languageDirection = RTL_LANGUAGES.includes(this.language)
? 'rtl'
: 'ltr';
this.shortcuts = new Shortcuts(this.keys); this.shortcuts = new Shortcuts(this.keys);
const lastSelectedFilePath = fyo.config.get( const lastSelectedFilePath = fyo.config.get(
ConfigKeys.LastSelectedFilePath, ConfigKeys.LastSelectedFilePath,
@ -109,6 +103,14 @@ export default {
await this.showDbSelector(); await this.showDbSelector();
} }
}, },
computed: {
language() {
return systemLanguage.value;
},
languageDirection() {
return RTL_LANGUAGES.includes(this.language) ? 'rtl' : 'ltr';
},
},
methods: { methods: {
async setDesk(filePath) { async setDesk(filePath) {
this.activeScreen = 'Desk'; this.activeScreen = 'Desk';

View File

@ -8,7 +8,7 @@
> >
<Transition name="spacer"> <Transition name="spacer">
<div <div
v-if="!sidebar && platform === 'Mac'" v-if="!sidebar && platform === 'Mac' && languageDirection !== 'rtl'"
class="h-full" class="h-full"
:class="sidebar ? '' : 'w-tl me-4 border-e'" :class="sidebar ? '' : 'w-tl me-4 border-e'"
/> />
@ -18,7 +18,8 @@
</h1> </h1>
<div <div
class="flex items-stretch window-no-drag gap-2 ms-auto" class="flex items-stretch window-no-drag gap-2 ms-auto"
:class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-20' : ''"> :class="platform === 'Mac' && languageDirection === 'rtl' ? 'me-18' : ''"
>
<slot /> <slot />
<div class="border-e" v-if="showBorder" /> <div class="border-e" v-if="showBorder" />
<BackLink v-if="backLink" class="window-no-drag rtl-rotate-180" /> <BackLink v-if="backLink" class="window-no-drag rtl-rotate-180" />
@ -30,11 +31,9 @@
import { Transition } from 'vue'; import { Transition } from 'vue';
import BackLink from './BackLink.vue'; import BackLink from './BackLink.vue';
import SearchBar from './SearchBar.vue'; import SearchBar from './SearchBar.vue';
import { fyo } from 'src/initFyo';
import { RTL_LANGUAGES } from 'fyo/utils/consts';
export default { export default {
inject: ['sidebar'], inject: ['sidebar', 'languageDirection'],
props: { props: {
title: { type: String, default: '' }, title: { type: String, default: '' },
backLink: { type: Boolean, default: true }, backLink: { type: Boolean, default: true },
@ -47,13 +46,6 @@ export default {
showBorder() { showBorder() {
return !!this.$slots.default && this.searchborder; return !!this.$slots.default && this.searchborder;
}, },
languageDirection(){
const language = fyo.config.get('language');
const languageDirection = RTL_LANGUAGES.includes(language)
? 'rtl'
: 'ltr';
return languageDirection;
}
}, },
}; };
</script> </script>

View File

@ -9,7 +9,9 @@
<!-- Company name and DB Switcher --> <!-- Company name and DB Switcher -->
<div <div
class="px-4 flex flex-row items-center justify-between mb-4" class="px-4 flex flex-row items-center justify-between mb-4"
:class="platform === 'Mac' && languageDirection === 'ltr' ? 'mt-10' : 'mt-2'" :class="
platform === 'Mac' && languageDirection === 'ltr' ? 'mt-10' : 'mt-2'
"
> >
<h6 <h6
class=" class="
@ -164,10 +166,10 @@ import { getSidebarConfig } from 'src/utils/sidebarConfig';
import { docsPath, routeTo } from 'src/utils/ui'; import { docsPath, routeTo } from 'src/utils/ui';
import router from '../router'; import router from '../router';
import Icon from './Icon.vue'; import Icon from './Icon.vue';
import { RTL_LANGUAGES } from 'fyo/utils/consts';
export default { export default {
components: [Button], components: [Button],
inject: ['languageDirection'],
emits: ['change-db-file', 'toggle-sidebar'], emits: ['change-db-file', 'toggle-sidebar'],
data() { data() {
return { return {
@ -180,13 +182,6 @@ export default {
appVersion() { appVersion() {
return fyo.store.appVersion; return fyo.store.appVersion;
}, },
languageDirection(){
const language = fyo.config.get('language');
const languageDirection = RTL_LANGUAGES.includes(language)
? 'rtl'
: 'ltr';
return languageDirection;
}
}, },
components: { components: {
Icon, Icon,

View File

@ -3,7 +3,7 @@ import { DEFAULT_LANGUAGE } from 'fyo/utils/consts';
import { setLanguageMapOnTranslationString } from 'fyo/utils/translation'; import { setLanguageMapOnTranslationString } from 'fyo/utils/translation';
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages'; import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
import { showToast } from './ui'; import { showToast, systemLanguage } from './ui';
// Language: Language Code in books/translations // Language: Language Code in books/translations
export const languageCodeMap: Record<string, string> = { export const languageCodeMap: Record<string, string> = {
@ -42,6 +42,7 @@ export async function setLanguageMap(
if (success && !usingDefault) { if (success && !usingDefault) {
fyo.config.set('language', language); fyo.config.set('language', language);
systemLanguage.value = language;
} }
if (!dontReload && success && initLanguage !== oldLanguage) { if (!dontReload && success && initLanguage !== oldLanguage) {

View File

@ -24,6 +24,7 @@ import {
} from './types'; } from './types';
export const docsPath = ref(''); export const docsPath = ref('');
export const systemLanguage = ref('');
export async function openQuickEdit({ export async function openQuickEdit({
doc, doc,