Skip to content

Commit 4e2c06b

Browse files
committed
Add activeTaskCategoryState to App component and save active category value to settings
1 parent 343bd20 commit 4e2c06b

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/App.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import { getAccessToken, saveAuthCode, handleInitialLogin, handleLoadFrom, handl
44
import { loadContextmenu } from "./helpers/windowhelper";
55
import TaskPage from "./components/TaskPage";
66
import { useRecoilRefresher_UNSTABLE, useRecoilState, useRecoilValue, useSetRecoilState } from "recoil";
7-
import { attemptLoginState, attemptLogoutState, authLoadingState, isOnlineSelector, loggedInSelector, messageState } from "./config/states";
7+
import { activeTaskCategoryState, attemptLoginState, attemptLogoutState, authLoadingState, isOnlineSelector, loggedInSelector, messageState } from "./config/states";
88
import Header from "./components/ui/Header";
99
import { listen_for_auth_code } from "./helpers/eventlistner";
10+
import { SettingsStore } from "./helpers/DBStores";
11+
import settings from "./config/settings";
1012

1113
// disable default context menu on build
1214
loadContextmenu();
1315

1416
function App() {
1517
const [loading, setLoading] = useRecoilState<boolean>(authLoadingState);
18+
const activeCategoryValue = useRecoilValue(activeTaskCategoryState)
1619
const loggedIn = useRecoilValue(loggedInSelector);
1720
const [attemptedLogin, setAttemptedLogin] = useRecoilState<boolean>(attemptLoginState);
1821
const [attemptedLogout, setAttemptedLogout] = useRecoilState<boolean>(attemptLogoutState);
@@ -54,6 +57,10 @@ function App() {
5457
setAttemptedLogout(false);
5558
}
5659
}, [attemptedLogout])
60+
61+
useEffect(() => {
62+
SettingsStore.set(settings.storage.constants.last_active_category, activeCategoryValue).then(() => {console.log("Setting active category")})
63+
}, [activeCategoryValue])
5764

5865

5966

src/config/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default {
2424
tasks: "tasks",
2525
authcode: "auth_code",
2626
user_profile: "user_profile",
27+
last_active_category: "last_active_category"
2728
}
2829
},
2930
api: {

src/config/states.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { atom, selector } from 'recoil';
22
import { UserProfile } from '../types/googleapis';
33
import { Task } from '../helpers/task';
44
import { task, taskCategory } from '../types/taskapi';
5+
import { SettingsStore } from '../helpers/DBStores';
6+
import settings from './settings';
7+
58

69
// const loggedInState = atom({
710
// key: 'loggedInState',
@@ -35,7 +38,7 @@ const taskObjectState = atom<Task>({
3538

3639
const activeTaskCategoryState = atom<number>({
3740
key: 'activeTaskCategoryState',
38-
default: -1,
41+
default: await SettingsStore.get<number>(settings.storage.constants.last_active_category) ?? -1
3942
});
4043

4144
const activeCategoryTasksState = atom<task[]>({

src/helpers/AuthStore.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/helpers/DBStores.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {Store} from 'tauri-plugin-store-api';
2+
3+
4+
export const SettingsStore = new Store('.settings.dat');
5+
export const AuthStore = new Store('.auth.dat');
6+
export const TaskStore = new Store('.task.dat');

src/helpers/invoker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import { invoke } from '@tauri-apps/api/tauri';
22
import * as commands from './commands';
33
import { AccessToken, SaveAccessTokenResponse, SaveTokenResponse } from './commands';
4-
import StoreDb from './AuthStore';
4+
import {AuthStore} from './DBStores';
55
import settings from '../config/settings';
66

77

88
const storeConstant = settings.storage.constants;
99

1010
export async function save_auth_code(code: string) : Promise<SaveTokenResponse> {
1111
// return await commands.saveCode(code);
12-
await StoreDb.set(storeConstant.authcode, code);
12+
await AuthStore.set(storeConstant.authcode, code);
1313
return { message: "Code saved", token: code, success: true };
1414

1515

1616
}
1717

1818
export async function get_auth_code() : Promise<string> {
1919
// return await commands.loadCode();
20-
return await StoreDb.get<string>(storeConstant.authcode) ?? "";
20+
return await AuthStore.get<string>(storeConstant.authcode) ?? "";
2121

2222
}
2323

2424
export async function save_access_token(token: string|AccessToken) : Promise<SaveAccessTokenResponse> {
2525
const accessTokenText: AccessToken = typeof token === "string" ? JSON.parse(token) : token;
2626
// return await commands.saveAccessToken(accessTokenText);
27-
await StoreDb.set(storeConstant.access_token, accessTokenText);
27+
await AuthStore.set(storeConstant.access_token, accessTokenText);
2828
return { message: "Token saved", success: true, token: token as AccessToken };
2929
}
3030

3131
export async function get_access_token() : Promise<AccessToken> {
3232
// return await commands.loadAccessToken();
33-
return await StoreDb.get<AccessToken>(storeConstant.access_token) ?? {} as AccessToken;
33+
return await AuthStore.get<AccessToken>(storeConstant.access_token) ?? {} as AccessToken;
3434
}
3535

3636
export async function test_command() {

0 commit comments

Comments
 (0)