mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cleanup formatting and change model to presenter
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ac92299778
commit
fc42120549
@ -7,11 +7,11 @@ import { SubTitle } from "../../../../../../renderer/components/layout/sub-title
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { observer } from "mobx-react";
|
||||
import { Select } from "../../../../../../renderer/components/select";
|
||||
import type { TerminalFontPreferenceModel } from "./terminal-font-options.injectable";
|
||||
import terminalFontPreferenceModelInjectable from "./terminal-font-options.injectable";
|
||||
import type { TerminalFontPreferencePresenter } from "./terminal-font-options.injectable";
|
||||
import terminalFontPreferencePresenterInjectable from "./terminal-font-options.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
model: TerminalFontPreferenceModel;
|
||||
model: TerminalFontPreferencePresenter;
|
||||
}
|
||||
|
||||
const NonInjectedTerminalFontFamily = observer(({ model }: Dependencies) => (
|
||||
@ -22,14 +22,13 @@ const NonInjectedTerminalFontFamily = observer(({ model }: Dependencies) => (
|
||||
controlShouldRenderValue
|
||||
value={model.current.get()}
|
||||
options={model.options.get()}
|
||||
onChange={model.set}
|
||||
onChange={model.onSelection}
|
||||
/>
|
||||
</section>
|
||||
),
|
||||
);
|
||||
));
|
||||
|
||||
export const TerminalFontFamily = withInjectables<Dependencies>(NonInjectedTerminalFontFamily, {
|
||||
getProps: (di) => ({
|
||||
model: di.inject(terminalFontPreferenceModelInjectable),
|
||||
model: di.inject(terminalFontPreferencePresenterInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -12,22 +12,27 @@ import { defaultTerminalFontFamily } from "../../../../../../common/vars";
|
||||
import type { SelectOption } from "../../../../../../renderer/components/select";
|
||||
import { terminalFontInjectionToken } from "../../../../../terminal/renderer/fonts/token";
|
||||
|
||||
export interface TerminalFontPreferenceModel {
|
||||
export interface TerminalFontPreferencePresenter {
|
||||
readonly options: IComputedValue<SelectOption<string>[]>;
|
||||
readonly current: IComputedValue<string>;
|
||||
set: (selection: SingleValue<SelectOption<string>>) => void;
|
||||
onSelection: (selection: SingleValue<SelectOption<string>>) => void;
|
||||
}
|
||||
|
||||
const terminalFontPreferenceModelInjectable = getInjectable({
|
||||
id: "terminal-font-preference-model",
|
||||
instantiate: (di): TerminalFontPreferenceModel => {
|
||||
const terminalFontPreferencePresenterInjectable = getInjectable({
|
||||
id: "terminal-font-preference-presenter",
|
||||
instantiate: (di): TerminalFontPreferencePresenter => {
|
||||
const userStore = di.inject(userStoreInjectable);
|
||||
const terminalFonts = di.injectMany(terminalFontInjectionToken);
|
||||
|
||||
return {
|
||||
options: computed(() => terminalFonts.map(font => ({
|
||||
label: (
|
||||
<span style={{ fontFamily: `${font.name}, var(--font-terminal)`, fontSize: userStore.terminalConfig.fontSize }}>
|
||||
<span
|
||||
style={{
|
||||
fontFamily: `${font.name}, var(--font-terminal)`,
|
||||
fontSize: userStore.terminalConfig.fontSize,
|
||||
}}
|
||||
>
|
||||
{font.name}
|
||||
</span>
|
||||
),
|
||||
@ -35,11 +40,11 @@ const terminalFontPreferenceModelInjectable = getInjectable({
|
||||
isSelected: userStore.terminalConfig.fontFamily === font.name,
|
||||
}))),
|
||||
current: computed(() => userStore.terminalConfig.fontFamily),
|
||||
set: action(selection => {
|
||||
onSelection: action(selection => {
|
||||
userStore.terminalConfig.fontFamily = selection?.value ?? defaultTerminalFontFamily;
|
||||
}),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default terminalFontPreferenceModelInjectable;
|
||||
export default terminalFontPreferencePresenterInjectable;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user