Skip to content

Commit 9318b1c

Browse files
committed
update services, fix json and ui drag
1 parent c6439c5 commit 9318b1c

File tree

6 files changed

+67
-89
lines changed

6 files changed

+67
-89
lines changed

dist/styles/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ body.darwin .btn-group .seperator {
237237
height: var(--navHeight);
238238
line-height: var(--navHeight);
239239
}
240-
body.darwin.not-fullscreen #root > nav .btn-group .btn:first-of-type {
240+
body.darwin.not-fullscreen #root > nav .btn-group:first-of-type {
241241
margin-left: 72px;
242242
}
243243
#root > nav .btn-group .btn.system {

src/components/settings/services/miniflux.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from "@fluentui/react"
1818
import DangerButton from "../../utils/danger-button"
1919
import { urlTest } from "../../../scripts/utils"
20-
import LiteExporter from "./lite-exporter"
2120
import { MinifluxConfigs } from "../../../scripts/models/services/miniflux"
2221

2322
type MinifluxConfigsTabState = {

src/components/settings/services/nextcloud.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from "@fluentui/react"
1919
import DangerButton from "../../utils/danger-button"
2020
import { urlTest } from "../../../scripts/utils"
21-
import LiteExporter from "./lite-exporter"
2221

2322
type NextcloudConfigsTabState = {
2423
existing: boolean
@@ -129,17 +128,14 @@ class NextcloudConfigsTab extends React.Component<
129128
</MessageBar>
130129
)}
131130
<Stack horizontalAlign="center" style={{ marginTop: 48 }}>
132-
<svg
131+
<Icon
132+
iconName="AlignLeft"
133133
style={{
134-
fill: "var(--black)",
135-
width: 32,
134+
color: "var(--black)",
135+
fontSize: 32,
136136
userSelect: "none",
137-
strokeWidth:4.15602
138137
}}
139-
viewBox="0 0 120 120">
140-
<path
141-
d="M 6.1560215,2 C 3.8535856,2 2,3.8535856 2,6.1560215 v 8.3120425 c 0,2.302436 1.8535856,4.156022 4.1560215,4.156022 H 114.21258 c 2.30244,0 4.15602,-1.853586 4.15602,-4.156022 V 6.1560215 C 118.3686,3.8535856 116.51502,2 114.21258,2 Z m 0,33.248172 C 3.8535856,35.248172 2,37.101757 2,39.404193 v 8.312043 c 0,2.302436 1.8535856,4.156022 4.1560215,4.156022 H 80.964408 c 2.302436,0 4.156021,-1.853586 4.156021,-4.156022 v -8.312043 c 0,-2.302436 -1.853585,-4.156021 -4.156021,-4.156021 z m 0,33.248172 C 3.8535856,68.496344 2,70.349929 2,72.652365 v 8.312043 c 0,2.302436 1.8535856,4.156021 4.1560215,4.156021 H 105.90054 c 2.30243,0 4.15602,-1.853585 4.15602,-4.156021 v -8.312043 c 0,-2.302436 -1.85359,-4.156021 -4.15602,-4.156021 z m 0,33.248176 C 3.8535856,101.74452 2,103.5981 2,105.90054 v 8.31204 c 0,2.30244 1.8535856,4.15602 4.1560215,4.15602 H 56.028279 c 2.302436,0 4.156022,-1.85358 4.156022,-4.15602 v -8.31204 c 0,-2.30244 -1.853586,-4.15602 -4.156022,-4.15602 z"/>
142-
</svg>
138+
/>
143139
<Label style={{ margin: "8px 0 36px" }}>Nextcloud</Label>
144140
<Stack className="login-form" horizontal>
145141
<Stack.Item>
@@ -161,7 +157,7 @@ class NextcloudConfigsTab extends React.Component<
161157
</Stack>
162158
<Stack className="login-form" horizontal>
163159
<Stack.Item>
164-
<Label>User</Label>
160+
<Label>{intl.get("service.username")}</Label>
165161
</Stack.Item>
166162
<Stack.Item grow>
167163
<TextField
@@ -241,9 +237,6 @@ class NextcloudConfigsTab extends React.Component<
241237
)}
242238
</Stack.Item>
243239
</Stack>
244-
{this.state.existing && (
245-
<LiteExporter serviceConfigs={this.props.configs} />
246-
)}
247240
</Stack>
248241
</>
249242
)

src/scripts/i18n/cs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"refresh": "Načíst znovu",
4242
"markAllRead": "Označit vše jako přečtené",
4343
"notifications": "Notifikace",
44-
"view": "Zobrazit"
45-
"settings": "Nastavení"
44+
"view": "Zobrazit",
45+
"settings": "Nastavení",
4646
"minimize": "Maximalizovat",
4747
"maximize": "Minimalizovat"
4848
},

src/scripts/models/services/miniflux.ts

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -128,56 +128,47 @@ export const minifluxServiceHooks: ServiceHooks = {
128128
// fetch entries from after the last fetched id (if exists)
129129
// limit by quantity and maximum safe integer (id)
130130
// NOTE: miniflux endpoint /entries default order with "published at", and does not offer "created_at"
131-
// but does offer id sort, directly correlated with "created". some feeds give strange published_at.
131+
// but does offer id sort, directly correlated with "created". some feeds give strange published_at.
132132

133133
fetchItems: () => async (_, getState) => {
134134
const state = getState()
135135
const configs = state.service as MinifluxConfigs
136-
let items: Entry[] = new Array()
136+
const items: Entry[] = new Array()
137137
let entriesResponse: Entries
138138

139139
// parameters
140140
configs.lastId = configs.lastId ?? 0
141141
// intermediate
142-
const quantity = 100
142+
const quantity = 125
143143
let continueId: number
144144

145145
do {
146146
try {
147147
if (continueId) {
148148
entriesResponse = await fetchAPI(
149149
configs,
150-
`entries?
151-
order=id
152-
&direction=desc
153-
&after_entry_id=${configs.lastId}
154-
&before_entry_id=${continueId}
155-
&limit=${quantity}`
150+
`entries?order=id&direction=desc&after_entry_id=${configs.lastId}&before_entry_id=${continueId}&limit=${quantity}`
156151
).then(response => response.json())
157152
} else {
158153
entriesResponse = await fetchAPI(
159154
configs,
160-
`entries?
161-
order=id
162-
&direction=desc
163-
&after_entry_id=${configs.lastId}
164-
&limit=${quantity}`
155+
`entries?order=id&direction=desc&after_entry_id=${configs.lastId}&limit=${quantity}`
165156
).then(response => response.json())
166157
}
167158

168-
items = entriesResponse.entries.concat(items)
159+
items.push(...entriesResponse.entries)
169160
continueId = items[items.length - 1].id
170161
} catch {
171162
break
172163
}
173164
} while (
174165
entriesResponse.entries &&
175-
entriesResponse.total === 100 &&
166+
entriesResponse.total >= quantity &&
176167
items.length < configs.fetchLimit
177168
)
178169

179170
// break/return nothing if no new items acquired
180-
if (items.length == 0) return [[], configs]
171+
if (items.length === 0) return [[], configs]
181172
configs.lastId = items[0].id
182173

183174
// get sources that possess ref/id given by service, associate new items
@@ -245,7 +236,10 @@ export const minifluxServiceHooks: ServiceHooks = {
245236
configs,
246237
"entries?starred=true"
247238
).then(response => response.json())
248-
const [unread, starred] = await Promise.all([unreadPromise, starredPromise])
239+
const [unread, starred] = await Promise.all([
240+
unreadPromise,
241+
starredPromise,
242+
])
249243

250244
return [
251245
new Set(unread.entries.map((entry: Entry) => String(entry.id))),
@@ -257,9 +251,9 @@ export const minifluxServiceHooks: ServiceHooks = {
257251
if (!item.serviceRef) return
258252

259253
const body = `{
260-
"entry_ids": [${item.serviceRef}],
261-
"status": "read"
262-
}`
254+
"entry_ids": [${item.serviceRef}],
255+
"status": "read"
256+
}`
263257

264258
const response = await fetchAPI(
265259
getState().service as MinifluxConfigs,
@@ -275,9 +269,9 @@ export const minifluxServiceHooks: ServiceHooks = {
275269
if (!item.serviceRef) return
276270

277271
const body = `{
278-
"entry_ids": [${item.serviceRef}],
279-
"status": "unread"
280-
}`
272+
"entry_ids": [${item.serviceRef}],
273+
"status": "unread"
274+
}`
281275
await fetchAPI(
282276
getState().service as MinifluxConfigs,
283277
"entries",
@@ -296,7 +290,8 @@ export const minifluxServiceHooks: ServiceHooks = {
296290
// if null, state consulted for context sids
297291

298292
markAllRead: (sids, date, before) => async (_, getState) => {
299-
let refs: string[]
293+
const state = getState()
294+
const configs = state.service as MinifluxConfigs
300295

301296
if (date) {
302297
const predicates: lf.Predicate[] = [
@@ -311,26 +306,24 @@ export const minifluxServiceHooks: ServiceHooks = {
311306
.from(db.items)
312307
.where(query)
313308
.exec()
314-
refs = rows.map(row => row["serviceRef"])
309+
const refs = rows.map(row => row["serviceRef"])
310+
const body = `{
311+
"entry_ids": [${refs}],
312+
"status": "read"
313+
}`
314+
await fetchAPI(configs, "entries", "PUT", body)
315315
} else {
316-
const state = getState()
317-
const items = state.feeds[state.page.feedId].iids
318-
.map(iid => state.items[iid])
319-
.filter(item => item.serviceRef && !item.hasRead)
320-
refs = items.map(item => item.serviceRef)
316+
const sources = state.sources
317+
await Promise.all(
318+
sids.map(sid =>
319+
fetchAPI(
320+
configs,
321+
`feeds/${sources[sid]?.serviceRef}/mark-all-as-read`,
322+
"PUT"
323+
)
324+
)
325+
)
321326
}
322-
323-
const body = `{
324-
"entry_ids": [${refs}],
325-
"status": "read"
326-
}`
327-
328-
await fetchAPI(
329-
getState().service as MinifluxConfigs,
330-
"entries",
331-
"PUT",
332-
body
333-
)
334327
},
335328

336329
star: (item: RSSItem) => async (_, getState) => {

src/scripts/models/services/nextcloud.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export const nextcloudServiceHooks: ServiceHooks = {
9898
source.iconurl = s.faviconLink
9999
source.serviceRef = String(s.id)
100100
if (s.folderId && groupsByTagId.has(String(s.folderId))) {
101-
groupsMap.set(String(s.id), groupsByTagId.get(String(s.folderId)))
101+
groupsMap.set(
102+
String(s.id),
103+
groupsByTagId.get(String(s.folderId))
104+
)
102105
}
103106
return source
104107
})
@@ -107,7 +110,7 @@ export const nextcloudServiceHooks: ServiceHooks = {
107110

108111
syncItems: () => async (_, getState) => {
109112
const configs = getState().service as NextcloudConfigs
110-
const [unreadResponse, starredResponse]= await Promise.all([
113+
const [unreadResponse, starredResponse] = await Promise.all([
111114
fetchAPI(configs, "/items?getRead=false&type=3&batchSize=-1"),
112115
fetchAPI(configs, "/items?getRead=true&type=2&batchSize=-1"),
113116
])
@@ -133,19 +136,14 @@ export const nextcloudServiceHooks: ServiceHooks = {
133136
//first sync
134137
let min = Number.MAX_SAFE_INTEGER
135138
do {
136-
try {
137-
const response = await fetchAPI(
138-
configs,
139-
"/items?getRead=true&type=3&batchSize=125&offset=" + min
140-
)
141-
if (response.status !== 200) throw APIError()
142-
lastFetched = await response.json()
143-
items = [ ...items, ...lastFetched.items]
144-
min = lastFetched.items.reduce((m, n) => Math.min(m, n.id), min)
145-
} catch (error) {
146-
console.log(error)
147-
break
148-
}
139+
const response = await fetchAPI(
140+
configs,
141+
"/items?getRead=true&type=3&batchSize=125&offset=" + min
142+
)
143+
if (response.status !== 200) throw APIError()
144+
lastFetched = await response.json()
145+
items = [...items, ...lastFetched.items]
146+
min = lastFetched.items.reduce((m, n) => Math.min(m, n.id), min)
149147
} while (
150148
lastFetched.items &&
151149
lastFetched.items.length >= 125 &&
@@ -155,18 +153,14 @@ export const nextcloudServiceHooks: ServiceHooks = {
155153
//incremental sync
156154
const response = await fetchAPI(
157155
configs,
158-
"/items/updated?lastModified="+configs.lastModified+"&type=3"
156+
"/items/updated?lastModified=" +
157+
configs.lastModified +
158+
"&type=3"
159159
)
160160
if (response.status !== 200) throw APIError()
161161
lastFetched = (await response.json()).items
162-
items.push(
163-
...lastFetched.filter(
164-
i => i.id > configs.lastId
165-
)
166-
)
167-
162+
items.push(...lastFetched.filter(i => i.id > configs.lastId))
168163
}
169-
const previousLastModified = configs.lastModified
170164
configs.lastModified = items.reduce(
171165
(m, n) => Math.max(m, n.lastModified),
172166
configs.lastModified
@@ -175,7 +169,6 @@ export const nextcloudServiceHooks: ServiceHooks = {
175169
(m, n) => Math.max(m, n.id),
176170
configs.lastId
177171
)
178-
console.log("last modified from "+ previousLastModified + " to " + configs.lastModified)
179172
configs.lastModified++ //+1 to avoid fetching articles with same lastModified next time
180173
if (items.length > 0) {
181174
const fidMap = new Map<string, RSSSource>()
@@ -184,7 +177,7 @@ export const nextcloudServiceHooks: ServiceHooks = {
184177
fidMap.set(source.serviceRef, source)
185178
}
186179
}
187-
180+
188181
const parsedItems = new Array<RSSItem>()
189182
items.forEach(i => {
190183
if (i.body === null || i.url === null) return
@@ -196,8 +189,8 @@ export const nextcloudServiceHooks: ServiceHooks = {
196189
source: source.sid,
197190
title: i.title,
198191
link: i.url,
199-
date: new Date(i.pubDate*1000),
200-
fetchedDate: new Date(i.pubDate*1000),
192+
date: new Date(i.pubDate * 1000),
193+
fetchedDate: new Date(),
201194
content: i.body,
202195
snippet: dom.documentElement.textContent.trim(),
203196
creator: i.author,
@@ -207,7 +200,7 @@ export const nextcloudServiceHooks: ServiceHooks = {
207200
notify: false,
208201
serviceRef: String(i.id),
209202
} as RSSItem
210-
if (i.enclosureLink ) {
203+
if (i.enclosureLink) {
211204
item.thumb = i.enclosureLink
212205
} else {
213206
let baseEl = dom.createElement("base")
@@ -235,7 +228,7 @@ export const nextcloudServiceHooks: ServiceHooks = {
235228
"POST",
236229
[i.id]
237230
)
238-
231+
239232
parsedItems.push(item)
240233
})
241234
return [parsedItems, configs]

0 commit comments

Comments
 (0)