Skip to content

Commit ce6a2de

Browse files
committed
WIP
1 parent 751c7a9 commit ce6a2de

File tree

13 files changed

+190
-147
lines changed

13 files changed

+190
-147
lines changed

knip.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"$schema": "https://unpkg.com/knip@5/schema.json",
3-
"entry": ["src/index.tsx"],
4-
"project": ["src/**/*.tsx", "src/**/*.ts"]
3+
"entry": ["src/index.tsx!"],
4+
"project": ["src/**/*.tsx!", "src/**/*.ts!"]
55
}

src/App/index.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,23 @@ function App() {
111111
const [userAuth, setUserAuth] = useState<UserAuth>();
112112
const [size, setSize] = useState<SizeContextProps>(getWindowSize);
113113
const [ready, setReady] = useState(false);
114+
115+
// Local Storage
116+
114117
const [storageState, setStorageState] = useState<LocalStorageContextProps['storageState']>({
115118
'timur-config': {
116119
defaultValue: defaultConfigValue,
117120
},
118121
});
119122

120-
const debouncedSize = useThrottledValue(size);
123+
const storageContextValue = useMemo<LocalStorageContextProps>(() => ({
124+
storageState,
125+
setStorageState,
126+
}), [storageState]);
121127

128+
// Device Size
129+
130+
const throttledSize = useThrottledValue(size);
122131
useEffect(() => {
123132
function handleResize() {
124133
setSize(getWindowSize());
@@ -131,6 +140,8 @@ function App() {
131140
};
132141
}, []);
133142

143+
// Authentication
144+
134145
const [meResult] = useQuery<MeQuery, MeQueryVariables>(
135146
{ query: ME_QUERY },
136147
);
@@ -143,10 +154,6 @@ function App() {
143154
setReady(true);
144155
}, [meResult.data, meResult.fetching]);
145156

146-
const [enumsResult] = useQuery<EnumsQuery, EnumsQueryVariables>(
147-
{ query: ENUMS_QUERY },
148-
);
149-
150157
const removeUserAuth = useCallback(
151158
() => {
152159
setUserAuth(undefined);
@@ -163,6 +170,12 @@ function App() {
163170
[userAuth, removeUserAuth],
164171
);
165172

173+
// Enums
174+
175+
const [enumsResult] = useQuery<EnumsQuery, EnumsQueryVariables>(
176+
{ query: ENUMS_QUERY },
177+
);
178+
166179
const enumsContextValue = useMemo<EnumsContextProps>(
167180
() => ({
168181
enums: enumsResult.data,
@@ -182,10 +195,7 @@ function App() {
182195
[enumsResult],
183196
);
184197

185-
const storageContextValue = useMemo<LocalStorageContextProps>(() => ({
186-
storageState,
187-
setStorageState,
188-
}), [storageState]);
198+
// Page layouts
189199

190200
const navbarStartActionRef = useRef<HTMLDivElement>(null);
191201
const navbarMidActionRef = useRef<HTMLDivElement>(null);
@@ -197,6 +207,8 @@ function App() {
197207
endActionsRef: navbarEndActionRef,
198208
}), []);
199209

210+
// Route
211+
200212
const fallbackElement = (
201213
<div className={styles.fallbackElement}>
202214
<img
@@ -207,13 +219,15 @@ function App() {
207219
</div>
208220
);
209221

222+
// NOTE: We should block page for authentication before we mount routes
223+
// TODO: Handle error with authentication
210224
if (!ready) {
211225
return fallbackElement;
212226
}
213227

214228
return (
215229
<NavbarContext.Provider value={navbarContextValue}>
216-
<SizeContext.Provider value={debouncedSize}>
230+
<SizeContext.Provider value={throttledSize}>
217231
<LocalStorageContext.Provider value={storageContextValue}>
218232
<RouteContext.Provider value={wrappedRoutes}>
219233
<UserContext.Provider value={userContextValue}>

src/App/routes/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ const settings = customWrapRoute({
8484
parent: rootLayout,
8585
path: 'settings',
8686
component: {
87-
render: () => import('#components/TemplateView'),
88-
props: {
89-
title: 'Settings',
90-
description: 'No settings to configure',
91-
},
87+
render: () => import('#views/Settings'),
88+
props: {},
9289
},
9390
wrapperComponent: Auth,
9491
context: {

src/App/styles.module.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33
align-items: center;
44
flex-direction: column;
55
justify-content: center;
6-
/*
7-
background-color: var(--go-ui-color-background);
8-
*/
96
width: 100vw;
107
height: 100vh;
118
gap: 1rem;
129

1310
.app-logo {
1411
margin-top: -4rem;
1512
height: 6rem;
16-
/*
17-
animation: slide-up var(--go-ui-duration-animation-slow) ease-in-out forwards;
18-
*/
1913
}
2014
}

src/PwaPrompt/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import styles from './styles.module.css';
1010
// eslint-disable-next-line no-console
1111
console.info('PWA information:', pwaInfo);
1212

13-
function ReloadPrompt() {
13+
function PwaPrompt() {
1414
const {
1515
offlineReady: [offlineReady, setOfflineReady],
1616
needRefresh: [needRefresh, setNeedRefresh],
@@ -38,6 +38,7 @@ function ReloadPrompt() {
3838
console.info('SW registration error', error);
3939
},
4040
});
41+
4142
const reload = useCallback(
4243
() => {
4344
updateServiceWorker(true);
@@ -96,4 +97,4 @@ function ReloadPrompt() {
9697
);
9798
}
9899

99-
export default ReloadPrompt;
100+
export default PwaPrompt;

src/components/Link/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function resolvePath(
5656
}
5757

5858
// eslint-disable-next-line react-refresh/only-export-components
59-
export function useLink(props: {
59+
function useLink(props: {
6060
external: true,
6161
href: string | undefined | null,
6262
to?: never,

src/utils/localStorage.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ export function getFromStorage<T>(key: string) {
55
return val === null || val === undefined ? undefined : JSON.parse(val) as T;
66
}
77

8-
export function removeFromStorage(key: string) {
9-
localStorage.removeItem(key);
10-
}
11-
128
export function setToStorage(key: string, value: unknown) {
139
if (isNotDefined(value)) {
14-
localStorage.clearItem(key);
10+
localStorage.removeItem(key);
1511
}
1612
localStorage.setItem(key, JSON.stringify(value));
1713
}

src/views/DailyJournal/DayView/WorkItemRow/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import { useFocusClient } from '#hooks/useFocus';
3939
import useLocalStorage from '#hooks/useLocalStorage';
4040
import { colorscheme } from '#utils/constants';
4141
import {
42-
Contract,
4342
EntriesAsList,
4443
Task,
4544
WorkItem,
@@ -86,7 +85,7 @@ function defaultColorSelector<T>(_: T, i: number): [string, string] {
8685
export interface Props {
8786
className?: string;
8887
workItem: WorkItem;
89-
contract: Contract;
88+
contractId: string;
9089

9190
onClone: (clientId: string, override?: Partial<WorkItem>) => void;
9291
onChange: (clientId: string, ...entries: EntriesAsList<WorkItem>) => void;
@@ -97,14 +96,15 @@ function WorkItemRow(props: Props) {
9796
const {
9897
className,
9998
workItem,
100-
contract,
99+
contractId,
101100
onClone,
102101
onDelete,
103102
onChange,
104103
} = props;
105104

106105
const { enums } = useContext(EnumsContext);
107106
const { width: windowWidth } = useContext(SizeContext);
107+
108108
const inputRef = useFocusClient<HTMLTextAreaElement>(workItem.clientId);
109109
const [config] = useLocalStorage('timur-config');
110110

@@ -116,8 +116,8 @@ function WorkItemRow(props: Props) {
116116
);
117117

118118
const filteredTaskList = useMemo(
119-
() => enums?.private?.allActiveTasks?.filter((task) => task.contract.id === contract.id),
120-
[contract.id, enums],
119+
() => enums?.private?.allActiveTasks?.filter((task) => task.contract.id === contractId),
120+
[contractId, enums],
121121
);
122122

123123
const handleStatusCheck = useCallback(() => {

src/views/DailyJournal/DayView/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function DayView(props: Props) {
266266
onClone={onWorkItemClone}
267267
onChange={onWorkItemChange}
268268
onDelete={onWorkItemDelete}
269-
contract={taskDetails?.contract}
269+
contractId={taskDetails.contract.id}
270270
/>
271271
</div>
272272
);

src/views/DailyJournal/StartSidebar/index.tsx

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
useCallback,
3-
useContext,
43
useMemo,
54
} from 'react';
65
import { MdDragIndicator } from 'react-icons/md';
@@ -25,16 +24,11 @@ import {
2524
isNotDefined,
2625
} from '@togglecorp/fujs';
2726

28-
import Checkbox from '#components/Checkbox';
2927
import MonthlyCalendar from '#components/MonthlyCalendar';
3028
import RadioInput from '#components/RadioInput';
31-
import SelectInput from '#components/SelectInput';
32-
import EnumsContext from '#contexts/enums';
33-
import { EnumsQuery } from '#generated/types/graphql';
3429
import useLocalStorage from '#hooks/useLocalStorage';
3530
import useSetFieldValue from '#hooks/useSetFieldValue';
3631
import {
37-
colorscheme,
3832
defaultConfigValue,
3933
numericOptionKeySelector,
4034
numericOptionLabelSelector,
@@ -44,7 +38,6 @@ import {
4438
DailyJournalAttributeKeys,
4539
DailyJournalAttributeOrder,
4640
DailyJournalGrouping,
47-
EditingMode,
4841
} from '#utils/types';
4942

5043
import styles from './styles.module.css';
@@ -155,47 +148,6 @@ function SortableItem(props: SortableItemProps) {
155148
);
156149
}
157150

158-
type EditingOption = { key: EditingMode, label: string };
159-
function editingOptionKeySelector(item: EditingOption) {
160-
return item.key;
161-
}
162-
function editingOptionLabelSelector(item: EditingOption) {
163-
return item.label;
164-
}
165-
const editingOptions: EditingOption[] = [
166-
{ key: 'normal', label: 'Normies' },
167-
{ key: 'vim', label: 'Vim Masterace' },
168-
];
169-
170-
type WorkItemTypeOption = EnumsQuery['enums']['TimeEntryType'][number];
171-
function workItemTypeKeySelector(item: WorkItemTypeOption) {
172-
return item.key;
173-
}
174-
function workItemTypeLabelSelector(item: WorkItemTypeOption) {
175-
return item.label;
176-
}
177-
178-
type WorkItemStatusOption = EnumsQuery['enums']['TimeEntryStatus'][number];
179-
function workItemStatusKeySelector(item: WorkItemStatusOption) {
180-
return item.key;
181-
}
182-
function workItemStatusLabelSelector(item: WorkItemStatusOption) {
183-
return item.label;
184-
}
185-
function workItemStatusColorSelector(item: WorkItemStatusOption): [string, string] {
186-
if (item.key === 'DOING') {
187-
return colorscheme[1];
188-
}
189-
if (item.key === 'DONE') {
190-
return colorscheme[5];
191-
}
192-
return colorscheme[7];
193-
}
194-
195-
function defaultColorSelector<T>(_: T, i: number): [string, string] {
196-
return colorscheme[i % colorscheme.length];
197-
}
198-
199151
interface Props {
200152
selectedDate: string;
201153
setSelectedDate: (newDate: string) => void;
@@ -211,8 +163,6 @@ function StartSidebar(props: Props) {
211163
setSelectedDate,
212164
} = props;
213165

214-
const { enums } = useContext(EnumsContext);
215-
216166
const [storedConfig, setStoredConfig] = useLocalStorage('timur-config');
217167

218168
const setConfigFieldValue = useSetFieldValue(setStoredConfig);
@@ -327,65 +277,6 @@ function StartSidebar(props: Props) {
327277
labelSelector={numericOptionLabelSelector}
328278
/>
329279
</div>
330-
<div className={styles.quickSettings}>
331-
<h4>
332-
Quick Settings
333-
</h4>
334-
<Checkbox
335-
name="compactTextArea"
336-
label="Collapse text area on blur"
337-
value={storedConfig.compactTextArea}
338-
onChange={setConfigFieldValue}
339-
/>
340-
<Checkbox
341-
name="showInputIcons"
342-
label="Show input icons"
343-
value={storedConfig.showInputIcons}
344-
onChange={setConfigFieldValue}
345-
/>
346-
<Checkbox
347-
name="checkboxForStatus"
348-
label="Use checkbox for status"
349-
tooltip="Use checkbox instead of select input for the status. i.e. to toggle TODO, Doing and Done"
350-
value={storedConfig.checkboxForStatus}
351-
onChange={setConfigFieldValue}
352-
/>
353-
<SelectInput
354-
name="defaultTaskStatus"
355-
variant="general"
356-
label="Default Entry Status"
357-
options={enums?.enums.TimeEntryStatus}
358-
keySelector={workItemStatusKeySelector}
359-
labelSelector={workItemStatusLabelSelector}
360-
colorSelector={workItemStatusColorSelector}
361-
onChange={setConfigFieldValue}
362-
value={storedConfig.defaultTaskStatus}
363-
nonClearable
364-
/>
365-
<SelectInput
366-
name="defaultTaskType"
367-
label="Default Entry Type"
368-
variant="general"
369-
options={enums?.enums.TimeEntryType}
370-
keySelector={workItemTypeKeySelector}
371-
labelSelector={workItemTypeLabelSelector}
372-
colorSelector={defaultColorSelector}
373-
onChange={setConfigFieldValue}
374-
value={storedConfig.defaultTaskType}
375-
/>
376-
<SelectInput
377-
name="editingMode"
378-
label="Note Editing Mode"
379-
variant="general"
380-
options={editingOptions}
381-
keySelector={editingOptionKeySelector}
382-
labelSelector={editingOptionLabelSelector}
383-
// colorSelector={defaultColorSelector}
384-
onChange={setConfigFieldValue}
385-
value={storedConfig.editingMode}
386-
nonClearable
387-
/>
388-
</div>
389280
</div>
390281
);
391282
}

0 commit comments

Comments
 (0)