-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(OPDS): migration PouchDB repository to main Redux state (PR #…
- Loading branch information
Showing
14 changed files
with
303 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// ==LICENSE-BEGIN== | ||
// Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
// Licensed to the Readium Foundation under one or more contributor license agreements. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
// ==LICENSE-END== | ||
|
||
import { nanoid } from "nanoid"; | ||
import { OpdsFeed } from "readium-desktop/common/models/opds"; | ||
import { Action } from "readium-desktop/common/models/redux"; | ||
import { OpdsFeedDocument } from "readium-desktop/main/db/document/opds"; | ||
|
||
export const ID = "OPDSFEED_ADD"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface Payload extends Array<OpdsFeedDocument> {} | ||
|
||
export function build(...feed: Array<OpdsFeedDocument | OpdsFeed>): | ||
Action<typeof ID, Payload> { | ||
|
||
const docs = feed.map<OpdsFeedDocument>((v) => ({ | ||
...v, | ||
createdAt: (v as OpdsFeedDocument).createdAt || (new Date()).getTime(), | ||
updatedAt: (new Date()).getTime(), | ||
identifier: v.identifier || nanoid(), | ||
})); | ||
|
||
return { | ||
type: ID, | ||
payload: docs, | ||
}; | ||
} | ||
build.toString = () => ID; // Redux StringableActionCreator | ||
export type TAction = ReturnType<typeof build>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// ==LICENSE-BEGIN== | ||
// Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
// Licensed to the Readium Foundation under one or more contributor license agreements. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
// ==LICENSE-END== | ||
|
||
import { Action } from "readium-desktop/common/models/redux"; | ||
|
||
export const ID = "OPDSFEED_DELETE"; | ||
|
||
interface Payload { | ||
identifier: string; | ||
} | ||
|
||
export function build(identifier: string): | ||
Action<typeof ID, Payload> { | ||
|
||
return { | ||
type: ID, | ||
payload: { | ||
identifier, | ||
}, | ||
}; | ||
} | ||
build.toString = () => ID; // Redux StringableActionCreator | ||
export type TAction = ReturnType<typeof build>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ==LICENSE-BEGIN== | ||
// Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
// Licensed to the Readium Foundation under one or more contributor license agreements. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
// ==LICENSE-END== | ||
|
||
import * as deleteOpdsFeed from "./deleteOpdsFeed"; | ||
import * as addOpdsFeed from "./addOpdsFeed"; | ||
|
||
export { | ||
deleteOpdsFeed, | ||
addOpdsFeed, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// ==LICENSE-BEGIN== | ||
// Copyright 2017 European Digital Reading Lab. All rights reserved. | ||
// Licensed to the Readium Foundation under one or more contributor license agreements. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file exposed on Github (readium) in the project repository. | ||
// ==LICENSE-END== | ||
|
||
import { clone } from "ramda"; | ||
import { OpdsFeedDocument } from "readium-desktop/main/db/document/opds"; | ||
import { opdsActions } from "readium-desktop/main/redux/actions"; | ||
|
||
const initialState: OpdsFeedDocument[] = []; | ||
|
||
export function opdsDbReducers( | ||
state: OpdsFeedDocument[] = initialState, | ||
action: opdsActions.addOpdsFeed.TAction | ||
| opdsActions.deleteOpdsFeed.TAction, | ||
): OpdsFeedDocument[] { | ||
switch (action.type) { | ||
|
||
case opdsActions.addOpdsFeed.ID: { | ||
|
||
let newState = state; | ||
for (const doc of action.payload) { | ||
|
||
const { identifier } = doc; | ||
const idx = newState.findIndex((v) => v.identifier === identifier); | ||
|
||
const newDoc = clone(doc); | ||
newDoc.doNotMigrateAnymore = true; | ||
|
||
if (newState[idx]) { | ||
newState = [ | ||
...newState.slice(0, idx), | ||
...[ | ||
newDoc, | ||
], | ||
...newState.slice(idx + 1), | ||
]; | ||
} else { | ||
newState = [ | ||
...newState, | ||
...[ | ||
newDoc, | ||
], | ||
]; | ||
} | ||
} | ||
return newState; | ||
} | ||
|
||
case opdsActions.deleteOpdsFeed.ID: { | ||
|
||
const identifier = action.payload.identifier; | ||
const idx = state.findIndex((v) => v.identifier === identifier); | ||
|
||
if (state[idx]) { | ||
return [ | ||
...state.slice(0, idx), | ||
...state.slice(idx + 1), | ||
]; | ||
} | ||
return state; | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.