Skip to content

Commit

Permalink
support rendering notification badge without the value #175
Browse files Browse the repository at this point in the history
* so the badge doesn't change the size when the value gets bigger than 9 (1=>2 digits) and then bigger than 99 (2=>3 digits)
  • Loading branch information
vladimiry committed Feb 22, 2020
1 parent 148ae0f commit 5b2352c
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "electron-mail",
"description": "Unofficial ProtonMail Desktop App",
"version": "4.3.1",
"version": "4.4.0",
"author": "Vladimir Yakovlev <desktop-app@protonmail.ch>",
"license": "MIT",
"homepage": "https://github.com/vladimiry/ElectronMail",
Expand Down
2 changes: 2 additions & 0 deletions src/shared/model/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface Config extends BaseConfig, Partial<StoreModel.StoreEntity> {
localDbMailsListViewMode: "plain" | "conversation";
// base
checkUpdateAndNotify: boolean;
doNotRenderNotificationBadgeValue: boolean;
hideOnClose: boolean;
layoutMode: (typeof import("src/shared/constants").LAYOUT_MODES)[number]["value"];
customTrayIconColor: string;
Expand All @@ -58,6 +59,7 @@ export interface Config extends BaseConfig, Partial<StoreModel.StoreEntity> {
}

export type BaseConfig = Pick<Config,
| "doNotRenderNotificationBadgeValue"
| "checkUpdateAndNotify"
| "hideOnClose"
| "layoutMode"
Expand Down
3 changes: 3 additions & 0 deletions src/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function initialConfig(): Config {
],
localDbMailsListViewMode: "plain",
// base
doNotRenderNotificationBadgeValue: false,
checkUpdateAndNotify: false,
hideOnClose: true,
layoutMode: "top",
Expand All @@ -83,6 +84,7 @@ export function initialConfig(): Config {

export function pickBaseConfigProperties(
{
doNotRenderNotificationBadgeValue,
checkUpdateAndNotify,
hideOnClose,
layoutMode,
Expand All @@ -102,6 +104,7 @@ export function pickBaseConfigProperties(
}: Config,
): Required<BaseConfig> {
return {
doNotRenderNotificationBadgeValue,
checkUpdateAndNotify,
hideOnClose,
layoutMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<electron-mail-unread-badge
*ngIf="unreadSummary && accounts.length > 1"
[value]="unreadSummary"
[alwaysRenderTheValue]="true"
></electron-mail-unread-badge>
</div>
<electron-mail-account-title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</div>
<electron-mail-unread-badge
*ngIf="folder.unread"
[alwaysRenderTheValue]="true"
[value]="folder.unread"
class="flex-grow-0 ml-1"
></electron-mail-unread-badge>
11 changes: 11 additions & 0 deletions src/web/browser-window/app/_options/base-settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
<electron-mail-unread-badge
[value]="($unreadSummary | async) || 0"
></electron-mail-unread-badge>
<div class="custom-control custom-switch float-md-right">
<input
class="custom-control-input"
formControlName="doNotRenderNotificationBadgeValue"
id="doNotRenderNotificationBadgeValueCheckbox"
type="checkbox"
>
<label class="custom-control-label" for="doNotRenderNotificationBadgeValueCheckbox">
Don't render the value
</label>
</div>
</label>
<div class="row">
<div class="col-sm-6 pb-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class BaseSettingsComponent implements OnInit, OnDestroy {
readonly zoomFactors = ZOOM_FACTORS.map((zoomLevel) => ({value: zoomLevel, title: `${Math.round(zoomLevel * 100)}%`}));

readonly controls: Record<keyof BaseConfig, AbstractControl> = {
doNotRenderNotificationBadgeValue: new FormControl(),
checkUpdateAndNotify: new FormControl(),
hideOnClose: new FormControl(),
layoutMode: new FormControl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{{ value }}
<ng-container *ngIf="!alwaysRenderTheValue && (doNotRenderNotificationBadgeValue$ | async); else renderTheValueTpl">
<span style="visibility: hidden;">0</span>
</ng-container>

<ng-template #renderTheValueTpl><span>{{ value }}</span></ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
text-align: center;
white-space: nowrap;
vertical-align: baseline;

&.do-not-render-value {
visibility: hidden;
}
}
13 changes: 9 additions & 4 deletions src/web/browser-window/app/_shared/unread-badge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ export class UnreadBadgeComponent implements OnInit, OnDestroy {
@Input()
value!: number;

subscription = new Subscription();
@Input()
alwaysRenderTheValue: boolean = false;

readonly doNotRenderNotificationBadgeValue$ = this.store.pipe(select(OptionsSelectors.CONFIG.doNotRenderNotificationBadgeValue));

private readonly subscription = new Subscription();

constructor(
private store: Store<State>,
private elementRef: ElementRef,
private renderer: Renderer2,
private readonly store: Store<State>,
private readonly elementRef: ElementRef,
private readonly renderer: Renderer2,
) {}

ngOnInit() {
Expand Down
1 change: 1 addition & 0 deletions src/web/browser-window/app/store/selectors/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const CONFIG = {
hideControls: createSelector(FEATURED.config, (config) => config.hideControls),
timeouts: createSelector(FEATURED.config, (config) => config.timeouts),
localDbMailsListViewMode: createSelector(FEATURED.config, (config) => config.localDbMailsListViewMode),
doNotRenderNotificationBadgeValue: createSelector(FEATURED.config, (config) => config.doNotRenderNotificationBadgeValue),
};

export const SETTINGS = (() => {
Expand Down

0 comments on commit 5b2352c

Please sign in to comment.