Skip to content

Commit 3f3f6ab

Browse files
committed
various small improvements concerning unification
1 parent 9e76a77 commit 3f3f6ab

6 files changed

Lines changed: 23 additions & 27 deletions

File tree

databases/catdat/scripts/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export const PLURALS = {
55
functor: 'functors',
66
} as const
77

8+
export const STRUCTURES: StructureType[] = ['category', 'functor']
9+
810
export const STRUCTURES_WITH_DUALS: StructureType[] = ['category']

databases/catdat/scripts/deduce-implications.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const db = get_client()
88
* Clears all deduced implications. This is done before the deduction starts.
99
*/
1010
export function clear_deduced_implications(type: StructureType) {
11+
console.info(`\n--- Deduce ${type} implications ---`)
1112
db.prepare(`DELETE FROM implications WHERE is_deduced = TRUE AND type = ?`).run(type)
1213
}
1314

databases/catdat/scripts/seed.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
PropertyYaml,
1212
} from './utils/seed.types'
1313
import { create_schema_hash, get_saved_schema_hash } from './utils/schema'
14-
import { PLURALS, type StructureType } from './config'
14+
import { PLURALS, STRUCTURES, type StructureType } from './config'
1515

1616
const db = get_client()
1717

@@ -115,17 +115,14 @@ function seed_config() {
115115
)
116116

117117
function insert_config(config: ConfigYaml) {
118-
for (const tag of config.shared_tags) {
119-
tag_insert.run(tag, 'category')
120-
tag_insert.run(tag, 'functor')
121-
}
122-
123-
for (const tag of config.category_tags) {
124-
tag_insert.run(tag, 'category')
125-
}
118+
for (const type of STRUCTURES) {
119+
for (const tag of config.shared_tags) {
120+
tag_insert.run(tag, type)
121+
}
126122

127-
for (const tag of config.functor_tags) {
128-
tag_insert.run(tag, 'functor')
123+
for (const tag of config[`${type}_tags`]) {
124+
tag_insert.run(tag, type)
125+
}
129126
}
130127

131128
for (const { relation, conditional } of config.relations) {

databases/catdat/scripts/utils/structures.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { StructureType } from '../config'
33
import { parse_json_set } from './helpers'
44

55
/**
6-
* A structure is a category or a functor.
6+
* Type for various types of categorical structures (category, functor, ...)
77
*/
88
export type StructureMeta = {
99
id: string
1010
name: string
1111
dual?: string | null
12-
// used for source and target properties of a functor
1312
associated_satisfied_properties?: Record<string, Set<string>>
1413
}
1514

src/lib/commons/structures.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ export const PLURALS = {
66
category: 'categories',
77
functor: 'functors',
88
}
9+
10+
export function get_selected_type(pathname: string): StructureType {
11+
for (const type of STRUCTURES) {
12+
const matches =
13+
pathname.startsWith(`/${type}`) || pathname.startsWith(`/${PLURALS[type]}`)
14+
if (matches) return type
15+
}
16+
return 'category'
17+
}

src/routes/+layout.svelte

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import NavMobile from '$components/NavMobile.svelte'
88
import Popup from '$components/Popup.svelte'
99
import { track_visit } from '$lib/client/track'
10+
import { get_selected_type } from '$lib/commons/structures'
1011
import type { StructureType } from '$lib/commons/types'
1112
import { tracking } from '$lib/states/tracking.svelte'
1213
import './app.css'
@@ -31,20 +32,7 @@
3132
3233
let nav_dialog = $state<HTMLDialogElement | null>(null)
3334
34-
let selected_type = $state<StructureType>(
35-
page.url.pathname.startsWith('/functor') ? 'functor' : 'category',
36-
)
37-
38-
$effect(() => {
39-
if (page.url.pathname.startsWith('/functor')) {
40-
selected_type = 'functor'
41-
} else if (
42-
page.url.pathname.startsWith('/category') ||
43-
page.url.pathname.startsWith('/categories')
44-
) {
45-
selected_type = 'category'
46-
}
47-
})
35+
let selected_type = $derived<StructureType>(get_selected_type(page.url.pathname))
4836
</script>
4937

5038
<svelte:head>

0 commit comments

Comments
 (0)