Skip to content

Commit e3dbca5

Browse files
Vinnlunknown
authored andcommitted
Refactor view params to object
This makes it easier to later add additional params, which I expect to happen.
1 parent 2ad003c commit e3dbca5

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

scratchpad/pane.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { RevampPaneDefinition } from '../types'
22
import { isPad, getTitle } from './data'
3-
import { view as scratchpadView } from './view';
3+
import { view as scratchpadView } from './view'
44

55
export const pane: RevampPaneDefinition = {
66
canHandle: (subject, store) => isPad(subject, store),
77
label: (subject, store) => getTitle(store, subject),
8-
attach: scratchpadView
8+
view: scratchpadView
99
}

scratchpad/paneWrapper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ const paneWrapper: PaneDefinition = {
3737

3838
render: function (subject, _dom) {
3939
const container = document.createElement('div')
40-
const user = UI.authn.currentUser()
41-
pane.attach(container, subject, UI.store, user)
40+
pane.view({
41+
container: container,
42+
subject: subject,
43+
store: UI.store,
44+
user: UI.authn.currentUser()
45+
})
4246
return container
4347
}
4448
}

scratchpad/view.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import { NamedNode, IndexedFormula } from 'rdflib';
2-
import { getContents, getSetContentsStatements } from './data';
3-
4-
export function view(
5-
container: HTMLElement,
6-
subject: NamedNode,
7-
store: IndexedFormula,
8-
user?: NamedNode
9-
) {
1+
import { getContents, getSetContentsStatements } from './data'
2+
import { ViewParams } from '../types'
3+
4+
export function view ({ container, subject, store, user }: ViewParams) {
105
toViewMode()
116

12-
function toViewMode() {
7+
function toViewMode () {
138
const content = getContents(store, subject)
14-
container.innerHTML = '';
9+
container.innerHTML = ''
1510

1611
const lines = content.split('\n')
1712
lines.forEach((line) => {
@@ -30,13 +25,13 @@ export function view(
3025
}
3126
}
3227

33-
function toEditMode() {
28+
function toEditMode () {
3429
if (!user) {
3530
return
3631
}
3732

3833
const content = getContents(store, subject)
39-
container.innerHTML = '<form><textarea></textarea><button type="submit">Save</button></form>';
34+
container.innerHTML = '<form><textarea></textarea><button type="submit">Save</button></form>'
4035

4136
const textArea = container.getElementsByTagName('textarea')[0]
4237
textArea.textContent = content

types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ interface NewPaneOptions {
2626
refreshTarget: HTMLTableElement;
2727
}
2828

29+
export interface ViewParams {
30+
container: HTMLElement;
31+
subject: NamedNode;
32+
store: IndexedFormula;
33+
user?: NamedNode;
34+
};
35+
2936
export interface RevampPaneDefinition {
3037
canHandle: (subject: NamedNode, store: IndexedFormula) => boolean;
31-
attach: (container: HTMLElement, subject: NamedNode, store: IndexedFormula, user?: NamedNode) => void;
38+
view: (params: ViewParams) => void;
3239
label: (subject: NamedNode, store: IndexedFormula) => string | null;
3340
};
3441
interface NewPaneOptions {

0 commit comments

Comments
 (0)