Using pouchdb instead of redux to store tracks.

This commit is contained in:
vdv committed 2022-09-24 17:08:53 +02:00
1 parent d82d972ff2
commit eae6296c2a
10 files changed
+341 -88

No files matched your search

+1 -2
View File
@@ -1,10 +1,9 @@
import { configureStore } from '@reduxjs/toolkit';
import mapReducer from './map';
import tracksReducer from './tracks';
const store = configureStore({
reducer: { map: mapReducer, tracks: tracksReducer },
reducer: { map: mapReducer },
});
export default store;
-52
View File
@@ -1,52 +0,0 @@
import { createSlice } from '@reduxjs/toolkit';
import {
Sha256,
Sha512,
string_to_bytes,
bytes_to_base64,
} from '@openpgp/asmcrypto.js';
interface TracksState {
tracks: { [index: string]: any };
}
const initialTracks: TracksState = {
tracks: {},
};
const tracksSlice = createSlice({
name: 'tracks',
initialState: initialTracks,
reducers: {
add: (state, action) => {
const { id, ...data } = action.payload;
state.tracks[action.payload.id] = data;
},
push: (state, action) => {
const sha = new Sha512();
const result = sha
.process(string_to_bytes(JSON.stringify(action.payload.track)))
.finish().result;
var id;
if (result === null) {
console.log(`Can't hash`);
id = crypto.randomUUID();
} else {
id = bytes_to_base64(result);
console.log(`Digest: ${id}`);
}
if (state.tracks.hasOwnProperty(id)) {
console.log('Track had already been imported');
} else {
state.tracks[id] = {
...action.payload,
};
}
},
},
});
export const tracksActions = tracksSlice.actions;
export default tracksSlice.reducer;