Skip to content

Commit

Permalink
Refactoring pickers, added sub menu "Window", added disableAnimation …
Browse files Browse the repository at this point in the history
…support during toggling of navigation
  • Loading branch information
ransome1 committed Jan 6, 2024
1 parent fbb3ce2 commit ec8667e
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 161 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"webpack-merge": "^5.9.0"
},
"build": {
"buildVersion": "34",
"buildVersion": "35",
"asar": true,
"asarUnpack": "**\\*.{node,dll}",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const handleWindowAllClosed = () => {
const tray = configStorage.get('tray');
if(process.platform !== 'darwin' && !tray) {
app.quit();
} else if(!process.mas && process.platform === 'darwin' && tray) {
} else if(process.platform === 'darwin' && tray) {
app.dock?.hide();
} else {
mainWindow?.hide();
Expand Down
125 changes: 70 additions & 55 deletions src/main/modules/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, Menu, dialog, shell } from 'electron';
import { setFile } from './File/File';
import { mainWindow } from '../main';
import { mainWindow, handleCreateWindow } from '../main';
import { openFile, createFile } from './File/Dialog';
import { handleRequestArchive } from './File/Archive';
import { configStorage, filterStorage } from '../config';
Expand Down Expand Up @@ -88,13 +88,7 @@ function createMenu(files: FileObject[]) {
setFile(index);
},
}))
: []),
{ type: 'separator' },
{
label: 'Close window',
accelerator: 'CmdOrCtrl+W',
role: 'close',
},
: [])
],
},
{
Expand All @@ -112,14 +106,23 @@ function createMenu(files: FileObject[]) {
{
label: 'View',
submenu: [
{
...(files?.length > 0
? [{
label: 'Toggle drawer',
accelerator: 'CmdOrCtrl+B',
click: () => {
const isDrawerOpen = configStorage.get('isDrawerOpen');
configStorage.set('isDrawerOpen', !isDrawerOpen);
},
},
{
label: 'Toggle file tabs',
click: () => {
const showFileTabs = configStorage.get('showFileTabs');
configStorage.set('showFileTabs', !showFileTabs);
},
}]
: []),
{
label: 'Toggle navigation',
accelerator: 'Ctrl+Alt+H',
Expand All @@ -128,13 +131,6 @@ function createMenu(files: FileObject[]) {
configStorage.set('isNavigationOpen', !isNavigationOpen);
},
},
{
label: 'Toggle file tabs',
click: () => {
const showFileTabs = configStorage.get('showFileTabs');
configStorage.set('showFileTabs', !showFileTabs);
},
},
{
label: 'Toggle theme',
accelerator: 'Ctrl+Alt+D',
Expand All @@ -145,51 +141,70 @@ function createMenu(files: FileObject[]) {
},
],
},
...(files?.length > 0
? [{
label: 'Todos',
submenu: [
{
label: 'Add new todo',
accelerator: 'CmdOrCtrl+N',
click: () => {
mainWindow?.webContents.send('isDialogOpen');
},
},
{
label: 'Find',
accelerator: 'CmdOrCtrl+F',
click: () => {
const isSearchOpen = configStorage.get('isSearchOpen');
configStorage.set('isSearchOpen', !isSearchOpen);
},
},
{
label: 'Toggle completed',
accelerator: 'Ctrl+H',
click: async () => {
const showCompleted = configStorage.get('showCompleted');
configStorage.set('showCompleted', !showCompleted);
},
},
{
label: 'Reset filters',
accelerator: 'CmdOrCtrl+0',
click: async () => {
filterStorage.set('filters', {});
},
},
{
label: 'Archive completed todos',
accelerator: 'Ctrl+Alt+A',
click: () => {
handleRequestArchive();
},
},
{
role: 'reload',
visible: false,
},
],
}]
: []),
{
label: 'Todos',
label: 'Window',
submenu: [
{
label: 'Add new todo',
accelerator: 'CmdOrCtrl+N',
click: () => {
mainWindow!.webContents.send('isDialogOpen');
},
},
{
label: 'Find',
accelerator: 'CmdOrCtrl+F',
click: () => {
const isSearchOpen = configStorage.get('isSearchOpen');
configStorage.set('isSearchOpen', !isSearchOpen);
},
},
{
label: 'Toggle completed',
accelerator: 'Ctrl+H',
click: async () => {
const showCompleted = configStorage.get('showCompleted');
configStorage.set('showCompleted', !showCompleted);
},
},
{
label: 'Reset filters',
accelerator: 'CmdOrCtrl+0',
click: async () => {
filterStorage.set('filters', {});
},
label: 'Close window',
accelerator: 'CmdOrCtrl+W',
role: 'close',
},
{ type: 'separator' },
{
label: 'Archive completed todos',
accelerator: 'Ctrl+Alt+A',
label: 'sleek',
click: () => {
handleRequestArchive();
},
},
{
role: 'reload',
visible: false,
},
],
handleCreateWindow();
}
}
]
},
{
label: 'Help',
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ body {
display: flex;
flex-direction: row;
margin-left: 5em;
transition: margin-left 0.3s ease;
header {
height: 2.5em;
display: flex;
Expand All @@ -45,6 +44,9 @@ body {
left: -5em;
}
}
&.hideNavigation.disableAnimations {
transition: none;
}
&.darkTheme {
button.showNavigation {
background: $darker-grey;
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/Dialog/AutoSuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ const AutoSuggest: React.FC<Props> = ({
onKeyDown: handleKeyDown,
'test-id': 'dialog-autosuggest-textfield',
};

const containerStyle = {
width: textFieldRef.current?.offsetWidth + 28 || 'auto',
};

useEffect(() => {
textFieldRef.current?.focus();
}, [textFieldRef]);
Expand All @@ -140,7 +135,7 @@ const AutoSuggest: React.FC<Props> = ({
<TextField {...inputProps} multiline className="input" />
)}
renderSuggestionsContainer={({ containerProps, children }) => (
<Box {...containerProps} style={containerStyle}>
<Box {...containerProps} style={{ width: textFieldRef.current?.offsetWidth ? textFieldRef.current.offsetWidth + 28 : 'auto' }}>
{children}
</Box>
)}
Expand Down
20 changes: 3 additions & 17 deletions src/renderer/Dialog/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,29 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import dayjs from 'dayjs';
import './DatePicker.scss';

const { ipcRenderer } = window.api;

interface Props extends WithTranslation {
date: string | null;
type: string;
settings: Settings;
textFieldValue: string;
todoObject: TodoObject | null;
handleChange: function;
t: typeof i18n.t;
}

const DatePickerComponent: React.FC<Props> = ({
date,
type,
settings,
textFieldValue,
todoObject,
handleChange,
t,
}) => {

const handleChange = (date: dayjs.Dayjs | null) => {
try {
const dateString = (date) ? dayjs(date).format('YYYY-MM-DD') : null;
ipcRenderer.send('updateTodoObject', todoObject?.id, textFieldValue, type, dateString);
} catch(error: any) {
console.error(error);
}
};

return (
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={settings.language}>
<DatePicker
className="datePicker"
format="YYYY-MM-DD"
label={t(`todoDialog.datePicker.${type}`)}
value={date ? dayjs(date) : null}
onChange={(date) => handleChange(date)}
onChange={(date) => handleChange(type, date)}
// data-testid={`dialog-picker-date-${type}`}
// InputProps={{ 'data-testid': `dialog-picker-date-${type}` }}
slotProps={{
Expand Down
34 changes: 23 additions & 11 deletions src/renderer/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect, memo } from 'react';
import { Button, Dialog, DialogContent, DialogActions, AlertColor } from '@mui/material';
import { withTranslation, WithTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import AutoSuggest from './AutoSuggest';
import PriorityPicker from './PriorityPicker';
import DatePicker from './DatePicker';
Expand Down Expand Up @@ -87,7 +88,23 @@ const DialogComponent: React.FC<Props> = memo(({
setRecurrence(todoObject?.rec || null);
setPomodoro(todoObject?.pm || 0);
}
}
};

const handleChange = (type: string, value: string) => {
try {
let updatedValue;
if(type === 'due' || type === 't') {
updatedValue = (value) ? dayjs(value).format('YYYY-MM-DD') : null;
} else if(type === 'pm') {
updatedValue = (value === '0') ? null : value;
} else {
updatedValue = value;
}
ipcRenderer.send('updateTodoObject', todoObject?.id, textFieldValue, type, updatedValue);
} catch(error: any) {
console.error(error);
}
};

useEffect(() => {
if(todoObject) {
Expand Down Expand Up @@ -129,32 +146,27 @@ const DialogComponent: React.FC<Props> = memo(({
/>
<PriorityPicker
priority={priority}
textFieldValue={textFieldValue}
todoObject={todoObject}
handleChange={handleChange}
/>
<DatePicker
date={dueDate}
type="due"
settings={settings}
textFieldValue={textFieldValue}
todoObject={todoObject}
handleChange={handleChange}
/>
<DatePicker
date={thresholdDate}
type="t"
settings={settings}
textFieldValue={textFieldValue}
todoObject={todoObject}
handleChange={handleChange}
/>
<RecurrencePicker
recurrence={recurrence}
textFieldValue={textFieldValue}
todoObject={todoObject}
handleChange={handleChange}
/>
<PomodoroPicker
pomodoro={pomodoro}
textFieldValue={textFieldValue}
todoObject={todoObject}
handleChange={handleChange}
/>
</DialogContent>
<DialogActions>
Expand Down
24 changes: 5 additions & 19 deletions src/renderer/Dialog/PomodoroPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,22 @@ import { FormControl, TextField } from '@mui/material';
import { ReactComponent as TomatoIconDuo } from '../../../assets/icons/tomato-duo.svg'
import './PomodoroPicker.scss';

const { ipcRenderer } = window.api;

interface Props {
interface PomodoroPickerProps {
pomodoro: number | string;
textFieldValue: string;
todoObject: TodoObject | null;
handleChange: function;
}

const PomodoroPicker: React.FC<Props> = ({
const PomodoroPicker: React.FC<PomodoroPickerProps> = ({
pomodoro,
textFieldValue,
todoObject,
handleChange,
}) => {

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
try {
const value = (event.target.value === '0') ? null : event.target.value;
ipcRenderer.send('updateTodoObject', todoObject?.id, textFieldValue, 'pm', value);
} catch(error: any) {
console.error(error);
}
};

return (
<FormControl id="pomodoroPicker">
<TextField
id="pomodoroPicker"
label={<TomatoIconDuo />}
type="number"
onChange={handleChange}
onChange={(event) => handleChange('pm', event.target.value)}
value={pomodoro}
data-testid="dialog-picker-pomodoro"
inputProps={{
Expand Down
Loading

0 comments on commit ec8667e

Please sign in to comment.