Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jan 19, 2024
1 parent e92f1ab commit 43a5ca1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
12 changes: 11 additions & 1 deletion core/router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom, type ReadableAtom } from 'nanostores'

import { onEnvironment } from './environment.js'
import { getEnvironment, onEnvironment } from './environment.js'
import { fastCategories } from './fast.js'
import { hasFeeds } from './feed.js'
import { userId } from './settings.js'
Expand Down Expand Up @@ -153,3 +153,13 @@ export function isSettingsRoute(route: Route): boolean {
export function isOrganizeRoute(route: Route): boolean {
return ORGANIZE.has(route.route)
}

export function removeFeedFromRoute(): void {
let page = router.get()
if (page.route === 'categories') {
getEnvironment().openRoute({
params: {},
route: page.route
})
}
}
14 changes: 14 additions & 0 deletions core/test/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isOrganizeRoute,
isSettingsRoute,
isSlowRoute,
removeFeedFromRoute,
router,
testFeed,
userId
Expand Down Expand Up @@ -232,3 +233,16 @@ test('checks that category exists', async () => {
route: 'fast'
})
})

test('has helper on feed removing', async () => {
userId.set('10')
let feed = await addFeed(testFeed())
setBaseRoute({ params: { feed }, route: 'categories' })

removeFeedFromRoute()

deepStrictEqual(router.get(), {
params: {},
route: 'categories'
})
})
9 changes: 2 additions & 7 deletions web/pages/feeds/categories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
organizeMessages as t
} from '@slowreader/core'
import { getURL, openRoute } from '../../stores/router.js'
import { getURL } from '../../stores/router.js'
import Button from '../../ui/button.svelte'
import CardLink from '../../ui/card-link.svelte'
import CardLinks from '../../ui/card-links.svelte'
Expand Down Expand Up @@ -94,12 +94,7 @@
</div>
<div slot="two">
{#if feedId}
<FeedsEdit
{feedId}
on:delete={() => {
openRoute({ params: {}, route: 'categories' })
}}
/>
<FeedsEdit {feedId} />
{/if}
</div>
</TwoStepsPage>
Expand Down
5 changes: 2 additions & 3 deletions web/pages/feeds/edit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
moveFilterDown,
moveFilterUp,
type PostsPage,
removeFeedFromRoute,
sortFilters,
organizeMessages as t
} from '@slowreader/core'
import { createEventDispatcher } from 'svelte'
import Button from '../../ui/button.svelte'
import Card from '../../ui/card.svelte'
Expand All @@ -41,7 +41,6 @@
let loadedPosts: PostsPage | undefined = undefined
let categories = getCategories()
let dispatch = createEventDispatcher<{ delete: null }>()
let categoryOptions: [string, string][]
categories.subscribe(value => {
Expand Down Expand Up @@ -99,7 +98,7 @@
secondary
on:click={() => {
if (confirm($t.deleteConform)) {
dispatch('delete')
removeFeedFromRoute()
deleteFeed(feedId)
}
}}>{$t.deleteFeed}</Button
Expand Down

0 comments on commit 43a5ca1

Please sign in to comment.