Skip to content

Commit b16550b

Browse files
authored
refactor (#1)
* fix: core tsconfig path and left logo position * refactor: event flow
1 parent de73ad4 commit b16550b

18 files changed

+228
-187
lines changed

src/app/app.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export const loadApp = (container: HTMLElement) => {
8080
control.sponsor.input.click()
8181
}
8282

83+
control.logo.onchange = (ev) => {
84+
console.log(ev.target);
85+
86+
}
87+
8388
const form = new Form<Schema>(() => {
8489
dispatch(updateForm(form.value))
8590
// handler.emit('form.updated', form.value)
@@ -101,7 +106,7 @@ export const loadApp = (container: HTMLElement) => {
101106

102107
sidenav.onOpen = () => {
103108
queueMicrotask(() => {
104-
control.title.element.focus()
109+
// control.title.element.focus()
105110
})
106111
}
107112

@@ -122,13 +127,13 @@ export const loadApp = (container: HTMLElement) => {
122127
)
123128

124129
form.append(
130+
control.logo,
125131
control.title,
126132
dateTime,
127133
control.location,
128-
control.logo,
134+
control.background,
129135
control.presentation.add,
130136
accordion,
131-
control.background,
132137
control.sponsor.button,
133138
control.grid
134139
)

src/app/config/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './positions';

src/app/config/positions.ts

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
export const getPositions = (size: number, tiles = 6) => {
2+
const base = size / 6
3+
4+
const width = size
5+
const height = size
6+
7+
const grid = {
8+
x: 0,
9+
y: 0,
10+
w: size,
11+
h: size,
12+
tiles,
13+
active: false,
14+
}
15+
16+
const background = {
17+
x: 0,
18+
y: 0,
19+
w: size,
20+
h: size,
21+
}
22+
23+
const logo = {
24+
x: base / 4.5,
25+
y: base / 4.5,
26+
w: base + base / 4.5,
27+
h: base + base / 4.5,
28+
}
29+
30+
const title = {
31+
x: logo.x + logo.w,
32+
y: base / 3,
33+
w: size - base,
34+
h: base,
35+
}
36+
37+
const presentation = {
38+
x: 0,
39+
y: base,
40+
w: size,
41+
h: base * 3,
42+
}
43+
44+
const date = {
45+
x: 0,
46+
y: size - base * 2,
47+
w: base * 1.5,
48+
h: base,
49+
}
50+
51+
const time = {
52+
x: date.x + date.w,
53+
y: date.y,
54+
w: base,
55+
h: date.h,
56+
}
57+
58+
const location = {
59+
x: time.x + time.w,
60+
y: time.y,
61+
w: size - time.x - time.w,
62+
h: time.h,
63+
}
64+
65+
const details = {
66+
x: base / 4.5,
67+
y: size - base * 2,
68+
w: size,
69+
h: base,
70+
}
71+
72+
const sponsor = {
73+
x: base / 4.5,
74+
y: size - base,
75+
w: base * 2,
76+
h: base,
77+
}
78+
79+
const devParana = {
80+
x: size - 250,
81+
y: size - 90,
82+
w: 200,
83+
h: 50,
84+
}
85+
86+
return {
87+
width,
88+
height,
89+
base,
90+
grid,
91+
background,
92+
logo,
93+
title,
94+
presentation,
95+
date,
96+
time,
97+
location,
98+
details,
99+
sponsor,
100+
devParana,
101+
}
102+
}

src/app/core/details-layer.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,34 @@ import {Layer} from './base'
55
import {dateTime} from '@utils/date-time'
66

77
export class DetailsLayer extends Layer implements DetailsSchema {
8-
calendar = new ImageLayer(this.position.x, 0, 180, 180)
9-
.setSize(48, 48)
8+
calendar = new ImageLayer(this.position.x, 0, this.height, this.height)
9+
.setSize(this.height / 4, this.height / 4)
1010
.setSrc('icons/calendar.svg')
1111

12-
clock = new ImageLayer(this.position.x, 0, 180, 180)
13-
.setSize(48, 48)
12+
clock = new ImageLayer(this.position.x, 0, this.height, this.height)
13+
.setSize(this.height / 4, this.height / 4)
1414
.setSrc('icons/clock.svg')
1515

16-
pin = new ImageLayer(this.position.x, 0, 1080, 180)
17-
.setSize(48, 48)
16+
pin = new ImageLayer(this.position.x, 0, 1080, this.height)
17+
.setSize(this.height / 4, this.height / 4)
1818
.setSrc('icons/pin.svg')
1919

20-
date = new WordLayer(0, 0, this.width - this.calendar.width, 180)
21-
.setSize(48)
20+
date = new WordLayer(0, 0, this.width - this.calendar.width, this.height)
21+
.setSize(this.height / 4)
2222
.setWeight('normal')
2323
.setColor('#f9f9f9')
2424

25-
time = new WordLayer(0, 0, this.width - this.clock.width, 180)
26-
.setSize(48)
25+
time = new WordLayer(0, 0, this.width - this.clock.width, this.height)
26+
.setSize(this.height / 4)
2727
.setWeight('normal')
2828
.setColor('#f9f9f9')
2929

30-
location = new WordLayer(0, 0, this.width - this.pin.width, 180)
31-
.setSize(48)
30+
location = new WordLayer(0, 0, this.width - this.pin.width, this.height)
31+
.setSize(this.height / 4)
3232
.setWeight('normal')
3333
.setColor('#f9f9f9')
3434

3535
async render() {
36-
37-
3836
let y = this.height / 4 - 12
3937

4038
let x = 20
@@ -53,7 +51,7 @@ export class DetailsLayer extends Layer implements DetailsSchema {
5351

5452
async renderDate(x: number, y: number) {
5553
this.context.clearRect(0, 0, this.width, this.height)
56-
54+
5755
if (!this.date.isEmpty) {
5856
await this.calendar.render()
5957
this.context.drawImage(this.calendar, x, y)

src/app/elements/canvas.ts

-16
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,6 @@ export class Canvas extends HTMLCanvasElement {
6161
return () => this.#onContextMenu.delete(fn)
6262
}
6363

64-
onMouseDown = ({offsetX, offsetY}: MouseEvent) => {
65-
const position = new Vector2(offsetX, offsetY)
66-
67-
const layer = this.#layers
68-
.filter((layer) => layer.draggable)
69-
.find((layer) => {
70-
return layer.detectCollision(position)
71-
})
72-
73-
if (layer) {
74-
// this.#dragLayer(layer, position)
75-
this.#dragging = layer
76-
layer.dragStart(position)
77-
}
78-
}
79-
8064
#onMouseDown = ({offsetX, offsetY}: MouseEvent) => {
8165
const position = new Vector2(offsetX, offsetY)
8266

src/app/elements/field-set.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import {h} from '@utils/h'
55
export class FieldSet extends HTMLFieldSetElement {
66
legend
77

8+
#controls = new Map()
9+
10+
get controls() {
11+
return Object.fromEntries(this.#controls.entries())
12+
}
13+
814
constructor(text: string) {
915
super()
1016
this.legend = this.#createLegend(text)
@@ -16,9 +22,12 @@ export class FieldSet extends HTMLFieldSetElement {
1622

1723
connectedCallback() {
1824
this.append(this.legend)
19-
}
2025

26+
console.log(this.elements)
27+
}
28+
2129
add(...children: Element[]) {
2230
this.append(...children)
31+
console.log(this.elements)
2332
}
2433
}

src/app/interfaces/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface RectConfig {
66
}
77

88
interface GridConfig extends RectConfig {
9-
tile: number
9+
tiles: number
1010
active: boolean
1111
}
1212

src/app/interfaces/event-map.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export interface EventMap {
1414
'presentation.added': PresentationLayer
1515

1616
'form.updated': Schema
17+
'form.logo-updated': HTMLOptionElement
1718
}

src/app/store/actions.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
1-
import {Presentation, SubmittedPresentation} from '@interfaces/presentation'
2-
import {ImageLayer, PresentationLayer} from '../core'
3-
import {Schema} from '@interfaces/schema'
4-
import {action} from '@utils/state'
1+
import {EventMap} from '@interfaces/event-map'
2+
import {store} from './store'
3+
4+
export const state = store<EventMap>()
55

66
/**
77
* Form
88
*/
9-
export const updateForm = action<Schema>('form.updated')
9+
export const updateForm = state.action('form.updated')
10+
export const updateLogo = state.action('form.logo-updated')
11+
// export const updateForm = action<Schema>('form.updated')
12+
// export const updateLogo = action<HTMLOptionElement>('form.logo-updated')
1013

1114
/**
1215
* Presentation
1316
*/
14-
export const submitPresentation = action<SubmittedPresentation>(
15-
'presentation.submitted'
16-
)
17+
export const submitPresentation = state.action('presentation.submitted')
18+
// export const submitPresentation = action<SubmittedPresentation>(
19+
// 'presentation.submitted'
20+
// )
1721

18-
export const handlePresentation = action<Presentation>('presentation.handled')
22+
export const handlePresentation = state.action('presentation.handled')
23+
// export const handlePresentation = action<Presentation>('presentation.handled')
1924

20-
export const createPresentation = action<PresentationLayer>(
21-
'presentation.created'
22-
)
25+
export const createPresentation = state.action('presentation.created')
26+
// export const createPresentation = action<PresentationLayer>(
27+
// 'presentation.created'
28+
// )
2329

24-
export const addPresentation = action<PresentationLayer>('presentation.added')
30+
export const addPresentation = state.action('presentation.added')
31+
// export const addPresentation = action<PresentationLayer>('presentation.added')
2532

2633
/**
2734
* Sponsor
2835
*/
29-
export const selectSponsor = action<File>('sponsor.selected')
36+
export const selectSponsor = state.action('sponsor.selected')
37+
38+
export const createSponsor = state.action('sponsor.created')
39+
40+
export const addSponsor = state.action('sponsor.added')
41+
// export const selectSponsor = action<File>('sponsor.selected')
3042

31-
export const createSponsor = action<ImageLayer>('sponsor.created')
43+
// export const createSponsor = action<ImageLayer>('sponsor.created')
3244

33-
export const addSponsor = action<ImageLayer>('sponsor.added')
45+
// export const addSponsor = action<ImageLayer>('sponsor.added')
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {onLogoUpdated} from '@store/selectors'
2+
3+
onLogoUpdated(({text, value}) => {
4+
console.log(text, value)
5+
})

src/app/store/form/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './form.logo-change';
12
export * from './form.updated';

src/app/store/presentation/presentation.handled.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ onPresentationHandled((value) => {
1111
const layer = use(LayerSchema)
1212

1313
const width = config.width
14-
const height = config.height / config.grid.tile
14+
const height = config.height / config.grid.tiles
1515

1616
const y = height * (layer.presentations.length + 1) + 90
1717

src/app/store/selectors.ts

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
1-
import {Presentation, SubmittedPresentation} from '@interfaces/presentation'
2-
import {ImageLayer, PresentationLayer} from '../core'
3-
import {Schema} from '@interfaces/schema'
4-
import {select} from '@utils/state'
5-
1+
import {state} from './actions'
62

73
/**
84
* Form
95
*/
10-
export const onFormUpdated = select<Schema>('form.updated')
6+
export const onFormUpdated = state.select('form.updated')
7+
export const onLogoUpdated = state.select('form.logo-updated')
118

129
/**
1310
* Presentation
1411
*/
15-
export const onPresentationSubmitted = select<SubmittedPresentation>(
16-
'presentation.submitted'
17-
)
12+
export const onPresentationSubmitted = state.select('presentation.submitted')
1813

19-
export const onPresentationHandled = select<Presentation>(
20-
'presentation.handled'
21-
)
14+
export const onPresentationHandled = state.select('presentation.handled')
2215

23-
export const onPresentationCreated = select<PresentationLayer>(
24-
'presentation.created'
25-
)
16+
export const onPresentationCreated = state.select('presentation.created')
2617

27-
export const onPresentationAdded =
28-
select<PresentationLayer>('presentation.added')
18+
export const onPresentationAdded = state.select('presentation.added')
2919

3020
/**
3121
* Sponsor
3222
*/
33-
export const onSponsorSelected = select<File>('sponsor.selected')
34-
export const onSponsorCreated = select<ImageLayer>('sponsor.created')
35-
export const onSponsorAdded = select<ImageLayer>('sponsor.added')
23+
export const onSponsorSelected = state.select('sponsor.selected')
24+
export const onSponsorCreated = state.select('sponsor.created')
25+
export const onSponsorAdded = state.select('sponsor.added')

0 commit comments

Comments
 (0)