Skip to content

Commit

Permalink
add notes model and store
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Feb 23, 2022
1 parent 904962b commit 4dba705
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { configureStore } from "@reduxjs/toolkit";
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import counterReducer from "./counter";
import notesReducer from "./notes";

const store = configureStore({
reducer: {
counter: counterReducer,
notes: notesReducer,
},
});

export type AppState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
type AppState = ReturnType<typeof store.getState>;
type AppDispatch = typeof store.dispatch;

export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<AppState> = useSelector;
export const useAppDispatch = () => useDispatch<AppDispatch>();

export default store;
24 changes: 24 additions & 0 deletions src/store/notes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";

interface NotesState {
notes: Note[];
}

const initialState: NotesState = {
notes: [],
};

export const notesSlice = createSlice({
name: "notes",
initialState,
reducers: {
// add note to notes
addNote: (state, action: PayloadAction<Note>) => {
state.notes = [...state.notes, action.payload];
},
},
});

export const { addNote } = notesSlice.actions;

export default notesSlice.reducer;
3 changes: 3 additions & 0 deletions src/types/basic.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Timestamp = number;

type UUID = string;
22 changes: 22 additions & 0 deletions src/types/model.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
interface Position {
x: number;
y: number;
}

interface Bounding {
width: number;
height: number;
}

// Sticky note card data model
interface Note {
id: UUID;
// text content could be markdown or raw text.
content: string;
// card bounding.
bounding: Bounding;
// card relative position.
position: Position;
createdTs: Timestamp;
updatedTs: Timestamp;
}

0 comments on commit 4dba705

Please sign in to comment.