Skip to content

Commit 3eb94fe

Browse files
committed
Cache initialization fix
1 parent 1e28214 commit 3eb94fe

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

api/db/schema.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@
9696
t.datetime "created_at", null: false
9797
t.datetime "updated_at", null: false
9898
t.string "jti", null: false
99-
t.string "provider"
100-
t.string "uid"
10199
t.index ["email"], name: "index_users_on_email", unique: true
102100
t.index ["jti"], name: "index_users_on_jti", unique: true
103101
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

extension/src/entrypoints/popup/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { MicIcon, MicOffIcon, VideoIcon, VideoOffIcon } from "../../icons";
2626
import fuzzysort from "fuzzysort";
2727

2828
function App() {
29-
const [currentlyPlaying, setCurrentlyPlaying] = useState("");
29+
const [currentlyPlaying, setCurrentlyPlaying] = useState(-1);
3030
const [searchInput, setSearchInput] = useState("");
3131
const [isMeet, setIsMeet] = useState<boolean>(false);
3232
const [soundButtons, setSoundButtons] = useState<any[]>([]);
@@ -130,7 +130,7 @@ function App() {
130130
}
131131
const success = await playLocalAudio(base64, fxVolume);
132132
if (success) {
133-
setCurrentlyPlaying(id.toString());
133+
setCurrentlyPlaying(id);
134134
}
135135
}
136136

@@ -139,7 +139,7 @@ function App() {
139139
postMessage(CrossFunctions.STOP_AUDIO);
140140
}
141141
stopLocalAudio();
142-
setCurrentlyPlaying("");
142+
setCurrentlyPlaying(-1);
143143
}
144144

145145
async function handleMicMute(muteMic: boolean) {
@@ -178,7 +178,7 @@ function App() {
178178
// TODO: Make it check if the audio is still playing on reopen
179179
const listener = (msg: any) => {
180180
if (msg.type === CrossFunctions.AUDIO_ENDED) {
181-
setCurrentlyPlaying("");
181+
setCurrentlyPlaying(-1);
182182
}
183183
};
184184

@@ -394,7 +394,7 @@ function App() {
394394
<button
395395
className="iconButton stopButton"
396396
onClick={stopSound}
397-
disabled={currentlyPlaying === ""}
397+
disabled={currentlyPlaying === -1}
398398
>
399399
<BoxIcon className="buttonIcon stopButtonIcon" />
400400
</button>
@@ -506,7 +506,7 @@ function App() {
506506
color={button.color}
507507
emoji={button.emoji}
508508
onClick={() => playSound(button.id)}
509-
isPlaying={currentlyPlaying === button.name}
509+
isPlaying={currentlyPlaying === button.id}
510510
/>
511511
))}
512512
</div>

extension/src/utils/api.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
export async function login(email: string, password: string) {
2-
const res = await fetch('http://localhost:3001/login', {
3-
method: 'POST',
4-
headers: { 'Content-Type': 'application/json' },
2+
const res = await fetch("http://localhost:3001/login", {
3+
method: "POST",
4+
headers: { "Content-Type": "application/json" },
55
body: JSON.stringify({ user: { email, password } }),
66
});
77
const data = await res.json();
8-
if (res.ok && res.headers.get('Authorization')) {
9-
const jwt = res.headers.get('Authorization').replace('Bearer ', '');
8+
if (res.ok && res.headers.get("Authorization")) {
9+
const jwt = res.headers.get("Authorization")?.replace("Bearer ", "") ?? "";
1010
await browser.storage.local.set({ jwt });
1111
return jwt;
1212
}
13-
throw new Error(data.status?.message || 'Login failed');
13+
throw new Error(data.status?.message || "Login failed");
1414
}
1515

1616
export async function getMySounds() {
17-
const { jwt } = await browser.storage.local.get('jwt');
18-
if (!jwt) throw new Error('Not logged in');
19-
const res = await fetch('http://localhost:3001/my_sounds', {
20-
headers: { Authorization: `Bearer ${jwt}` }
17+
const { jwt } = await browser.storage.local.get("jwt");
18+
if (!jwt) throw new Error("Not logged in");
19+
const res = await fetch("http://localhost:3001/my_sounds", {
20+
headers: { Authorization: `Bearer ${jwt}` },
2121
});
22-
if (!res.ok) throw new Error('Failed to fetch sounds');
22+
if (!res.ok) throw new Error("Failed to fetch sounds");
2323
return res.json();
2424
}
2525

2626
export async function getDefaultSounds() {
27-
const res = await fetch('http://localhost:3001/sounds')
28-
if (!res.ok) throw new Error('Failed to fetch default sounds');
27+
const res = await fetch("http://localhost:3001/sounds");
28+
if (!res.ok) throw new Error("Failed to fetch default sounds");
2929
return res.json();
30-
}
30+
}

extension/src/utils/db.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
import { openDB } from 'idb';
1+
import { openDB } from "idb";
22
export async function storeSound(id: string, blob: Blob) {
3-
const db = await openDB('SoundCacheDB', 1, {
3+
const db = await openDB("SoundCacheDB", 1, {
44
upgrade(db) {
5-
if (!db.objectStoreNames.contains('sounds')) {
6-
db.createObjectStore('sounds');
7-
}
5+
if (!db.objectStoreNames.contains("sounds")) {
6+
db.createObjectStore("sounds");
7+
}
88
},
99
});
10-
const existing = await db.get('sounds', id);
10+
const existing = await db.get("sounds", id);
1111
if (!existing) {
1212
console.log("Storing sound in IndexedDB:", id);
13-
await db.put('sounds', blob, id);
13+
await db.put("sounds", blob, id);
1414
} else {
1515
console.log("Sound already cached:", id);
1616
}
1717
}
1818

1919
export async function retrieveSound(id: number): Promise<Blob> {
20-
const db = await openDB('SoundCacheDB', 1);
21-
const blob = await db.get('sounds', id);
20+
const db = await openDB("SoundCacheDB", 1);
21+
const blob = await db.get("sounds", id);
2222
return blob;
2323
}
2424

2525
export async function isSoundCached(id: string): Promise<boolean> {
26-
const db = await openDB('SoundCacheDB', 1);
27-
const sound = await db.get('sounds', id);
26+
console.log("checking if sound is cached");
27+
const db = await openDB("SoundCacheDB", 1, {
28+
upgrade(db) {
29+
console.log("in upgrade");
30+
if (!db.objectStoreNames.contains("sounds")) {
31+
db.createObjectStore("sounds");
32+
}
33+
},
34+
});
35+
const sound = await db.get("sounds", id);
2836
return !!sound;
2937
}

0 commit comments

Comments
 (0)