Skip to content

Commit 28beafe

Browse files
committed
[Update] Add new cat ui and file paths err
1 parent e4d7d5c commit 28beafe

File tree

8 files changed

+95
-24
lines changed

8 files changed

+95
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "google-task",
33
"private": true,
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/src/libs/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::filehelper::{ACCESS_TOKEN_FILE, AUTH_CODE_FILE};
1+
use super::filehelper::{ACCESS_TOKEN_FILE, AUTH_CODE_FILE, ENV_FILE};
22
use super::response::{SaveAccessTokenResponse, SaveTokenResponse};
33

44

src-tauri/src/libs/filehelper.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,31 @@ pub fn get_app_local_data_dir(file_name: &str) -> String {
1818
file_name,
1919
Some(BaseDirectory::AppLocalData),
2020
).expect("failed to resolve path");
21-
path.to_str().unwrap().to_string()
22-
}
23-
24-
pub fn resolve_access_token_file() -> String {
25-
let access_token_file: String = get_app_local_data_dir("access_token.db");
26-
println!("access token path: {}", access_token_file);
21+
let path = path.to_str().unwrap().to_string();
2722
// check if file exists
28-
if !std::path::Path::new(&access_token_file).exists() {
23+
if !std::path::Path::new(file_name).exists() {
24+
println!("File does not exist, creating file {} for {}", file_name, path);
2925
// create file
30-
let mut file = std::fs::File::create(&access_token_file).unwrap();
26+
let mut file = std::fs::File::create(file_name).unwrap();
3127
// write empty array to file
3228
file.write_all("".as_bytes()).unwrap();
3329
}
30+
path
31+
}
32+
33+
pub fn resolve_access_token_file() -> String {
34+
let access_token_file: String = get_app_local_data_dir("access_token.db");
35+
println!("access token path: {}", access_token_file);
3436
access_token_file
3537
}
3638

3739
pub fn resolve_auth_code_file() -> String {
3840
let auth_code_file: String = get_app_local_data_dir("auth_code.db");
3941
println!("auth code path: {}", auth_code_file);
40-
// check if file exists
41-
if !std::path::Path::new(&auth_code_file).exists() {
42-
// create file
43-
let mut file = std::fs::File::create(&auth_code_file).unwrap();
44-
// write empty array to file
45-
file.write_all("".as_bytes()).unwrap();
46-
}
4742
auth_code_file
4843
}
4944

45+
5046
lazy_static! {
5147
pub static ref ACCESS_TOKEN_FILE: String = resolve_access_token_file();
5248
pub static ref AUTH_CODE_FILE: String = resolve_auth_code_file();

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function App() {
5050
useEffect(() => {
5151
listen_for_auth_code({
5252
onSucess: (code) => {
53-
console.log(code);
53+
console.log(code, "code generated");
5454
if (code) {
5555
saveAuthCode(code).then(() => {
5656
console.log("code saved");

src/components/ui/AddCategory.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { IconButton, Button, FormControl, FormLabel, Input, ButtonGroup, Box, Popover, useDisclosure, PopoverTrigger, PopoverContent, FocusLock, PopoverArrow, PopoverCloseButton, Stack} from '@chakra-ui/react'
2+
import { CheckIcon } from '@chakra-ui/icons'
3+
import React, { useRef } from 'react'
4+
5+
6+
7+
const Form = ({categoryNameRef, onCancel}: {categoryNameRef: React.RefObject<HTMLInputElement>, onCancel: () => void}) => {
8+
const addNewCategory = () => {
9+
console.log('adding new category', categoryNameRef.current?.value)
10+
}
11+
12+
return (
13+
<Stack spacing={4}>
14+
<FormControl>
15+
<FormLabel htmlFor={"categoryName"}>Category Name</FormLabel>
16+
<Input ref={categoryNameRef} id={"categoryName"} placeholder={"Category Name"} />
17+
</FormControl>
18+
<ButtonGroup display='flex' justifyContent='flex-end'>
19+
<Button variant='outline' onClick={onCancel}>
20+
Cancel
21+
</Button>
22+
<Button colorScheme='teal' onClick={addNewCategory}>
23+
Save
24+
</Button>
25+
</ButtonGroup>
26+
</Stack>
27+
)
28+
}
29+
30+
export default function AddCategoryComponent() {
31+
const { onOpen, onClose, isOpen } = useDisclosure()
32+
const categoryNameRef = useRef<HTMLInputElement>(null)
33+
return (
34+
<>
35+
<Box>
36+
<Popover
37+
isOpen={isOpen}
38+
initialFocusRef={categoryNameRef}
39+
onOpen={onOpen}
40+
onClose={onClose}
41+
placement='right'
42+
closeOnBlur={false}
43+
>
44+
<PopoverTrigger>
45+
<IconButton
46+
isRound={true}
47+
variant='solid'
48+
colorScheme='teal'
49+
aria-label='Done'
50+
size='sm'
51+
icon={<CheckIcon />}
52+
/>
53+
</PopoverTrigger>
54+
<PopoverContent p={5}>
55+
<FocusLock persistentFocus={false}>
56+
<PopoverArrow />
57+
<PopoverCloseButton />
58+
<Form categoryNameRef={categoryNameRef} onCancel={onClose} />
59+
</FocusLock>
60+
</PopoverContent>
61+
62+
</Popover>
63+
</Box>
64+
</>
65+
)
66+
}

src/components/ui/LoggedInHeader.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Popover, PopoverTrigger, Avatar, Portal, PopoverContent, PopoverArrow, PopoverHeader, PopoverCloseButton, PopoverBody, Button, PopoverFooter } from "@chakra-ui/react";
1+
import { Popover, PopoverTrigger, Avatar, Spacer, Portal, Box, PopoverContent, PopoverArrow, PopoverHeader, PopoverCloseButton, PopoverBody, Button, PopoverFooter } from "@chakra-ui/react";
22
import { useRecoilValue, useSetRecoilState } from "recoil";
33
import { attemptLogoutState, userProfileSelector } from "../../config/states";
4+
import AddCategoryComponent from "./AddCategory";
45

56
export default function LoggedInHeader() {
67
const profile = useRecoilValue(userProfileSelector);
@@ -11,6 +12,11 @@ export default function LoggedInHeader() {
1112

1213

1314
return (
15+
<>
16+
<Box pr={4}>
17+
<AddCategoryComponent />
18+
</Box>
19+
<Spacer />
1420
<Popover>
1521
<PopoverTrigger>
1622
<Avatar size="sm" name={profile?.name ?? "default"} src={profile?.picture ?? ""} />
@@ -26,6 +32,7 @@ export default function LoggedInHeader() {
2632
<PopoverFooter> Date {new Date().getFullYear()}</PopoverFooter>
2733
</PopoverContent>
2834
</Portal>
29-
</Popover>
35+
</Popover>
36+
</>
3037
)
3138
}

src/helpers/eventlistner.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ type listnerCallback<T = any> = {
55
onError ?: (err: Error) => any
66
}
77

8-
export async function listen_for_auth_code(callback: listnerCallback<string|null>) {
8+
export async function listen_for_auth_code(callback: listnerCallback<string | null>) {
99
const unlisten = await listen("oauth://url", async (data) => {
1010
try {
11+
console.log("gotten data")
1112
if (!data.payload) return;
1213
const url = new URL(data.payload as string);
1314
const code = new URLSearchParams(url.search).get("code");
1415
return callback.onSucess(code);
1516
} catch (err) {
17+
unlisten();
1618
return callback.onError ? callback.onError(err as Error) : null;
1719
}
1820
});
19-
return unlisten();
21+
return;
2022
}
2123

src/helpers/invoker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {invoke} from '@tauri-apps/api/tauri';
22
import { AccessToken } from '../types/googleapis';
33

44
export async function save_auth_code(code: string) {
5-
return await invoke('save_auth_code', {code});
5+
return await invoke('save_code', {code});
66
}
77

88
export async function get_auth_code() {
9-
return await invoke('get_auth_code');
9+
return await invoke('load_code');
1010
}
1111

1212
export async function save_access_token(token: string|AccessToken) {

0 commit comments

Comments
 (0)