Skip to content

Commit

Permalink
feat: começa usar actions e selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Aug 17, 2024
1 parent 9ec0af4 commit 3859c39
Show file tree
Hide file tree
Showing 28 changed files with 491 additions and 265 deletions.
210 changes: 210 additions & 0 deletions public/images/graph-paper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 22 additions & 30 deletions src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import {EventHandler, FormControl, LayerSchema, Schema} from '@interfaces'
import {Form, Canvas, Sidenav, Accordion, DownloadButton} from '@elements'
import {selectSponsor, submitPresentation, updateForm} from '@store'
import {FormControl, LayerSchema, Schema} from '@interfaces'
import {PresentationForm} from '@components/presentation'
import {ThemeToggle} from '@components/theme'
import {TitleBar} from '@elements/title-bar'
import {onFormChange} from '@events'
import {dispatch, h} from '@utils'
import {use} from '@websqnl/di'
import {login} from '@store'
import {
onSponsorAdded,
onSponsorCreated,
onSponsorSelected,
} from '@events/sponsor'
import {
onPresentationAdded,
onPresentationCreated,
onPresentationHandled,
onPresentationSubmitted,
} from '@events/presentation'

dispatch(login({username: 'user', password: 'pass'}))

// dispatch(login({username: 'user', password: 'pass'}))

export const loadApp = (container: HTMLElement) => {
const canvas = use(Canvas)
Expand All @@ -29,8 +17,6 @@ export const loadApp = (container: HTMLElement) => {
const layer = use(LayerSchema)
const control = use(FormControl)

const handler = use(EventHandler)

const accordion = new Accordion()

const theme = use(ThemeToggle)
Expand Down Expand Up @@ -61,16 +47,17 @@ export const loadApp = (container: HTMLElement) => {
form.onsubmit = (ev) => {
ev.preventDefault()

handler.emit('presentation.submitted', form.value)
dispatch(submitPresentation(form.value))
// handler.emit('presentation.submitted', form.value)

accordion.closeAll()
}
}

handler.on('presentation.submitted', onPresentationSubmitted)
handler.on('presentation.handled', onPresentationHandled)
handler.on('presentation.created', onPresentationCreated)
handler.on('presentation.added', onPresentationAdded)
// handler.on('presentation.submitted', onPresentationSubmitted)
// handler.on('presentation.handled', onPresentationHandled)
// handler.on('presentation.created', onPresentationCreated)
// handler.on('presentation.added', onPresentationAdded)

/**
* ___ _ __ ___ _ __ ___ ___ _ __
Expand All @@ -81,27 +68,31 @@ export const loadApp = (container: HTMLElement) => {
*/
control.sponsor.input.onchange = () => {
const [file] = control.sponsor.input.files ?? []
handler.emit('sponsor.selected', file)
dispatch(selectSponsor(file))
// handler.emit('sponsor.selected', file)
}

handler.on('sponsor.selected', onSponsorSelected)
handler.on('sponsor.created', onSponsorCreated)
handler.on('sponsor.added', onSponsorAdded)
// handler.on('sponsor.selected', onSponsorSelected)
// handler.on('sponsor.created', onSponsorCreated)
// handler.on('sponsor.added', onSponsorAdded)

control.sponsor.button.onclick = () => {
control.sponsor.input.click()
}

const form = new Form<Schema>(() => {
handler.emit('form.updated', form.value)
dispatch(updateForm(form.value))
// handler.emit('form.updated', form.value)
})

handler.on('form.updated', onFormChange)
// handler.on('form.updated', onFormChange)

layer.background.setDraggable(false).setSrc(form.value.logo).render()

layer.logo.setOrder(4).setSrc('logos/dev-parana.svg').render()

layer.devParana.setSrc('dev-parana.svg').setOrder(19).render()

layer.title
.setText(control.title.value)
.setSize(78)
Expand All @@ -119,7 +110,8 @@ export const loadApp = (container: HTMLElement) => {
layer.logo,
layer.background,
layer.title,
layer.details
layer.details,
layer.devParana
)

const dateTime = h(
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/presentation/presentation-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export class PresentationForm extends Form<SubmittedPresentation> {
this.append(...values(this.controls), ...values(this.actions))
this.controls.photoUrl.element.readOnly = true

this.addEventListener('submit', () => {
this.controls.title.element.readOnly = true
this.controls.github.element.readOnly = true
this.controls.speaker.element.readOnly = true
this.controls.role.element.readOnly = true
this.controls.photo.element.readOnly = true
})

this.controls.github.onchange = async () => {
if (this.github.value) {
const user = await this.getFromGithub(this.github.value)
Expand Down
1 change: 1 addition & 0 deletions src/app/core/base/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export abstract class Layer extends OffscreenCanvas {
dragTo(point: Vector2) {
if (this.dragging) {
console.log(point)
console.log(this.offset)

this.position.copy(point).sub(this.offset)
}
Expand Down
14 changes: 11 additions & 3 deletions src/app/core/image-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ export class ImageLayer extends Layer {

async render() {
if (!this.#hasNoImage(this.#image.src)) {
return this.#image.decode().then(() => {
if (this.#normalizeSrc(this.#image.src)) {
return this.#image.decode().then(() => {
this.context.clearRect(0, 0, this.width, this.height)
this.context.drawImage(this.#image, 0, 0, this.width, this.height)
})
} else {
this.context.clearRect(0, 0, this.width, this.height)
this.context.drawImage(this.#image, 0, 0, this.width, this.height)
})
}
}
}

#normalizeSrc(src = '') {
return src.replace(`${location.origin}/`, '')
}

#hasNoImage(src?: string) {
return src === location.origin + '/undefined'
}
Expand Down
33 changes: 26 additions & 7 deletions src/app/elements/title-bar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from '@utils/debounce'
import {debounce} from '@utils/debounce'
import {builtIn} from '@utils/decorators'

@builtIn('div', 'cw-title-bar')
Expand All @@ -12,16 +12,35 @@ export class TitleBar extends HTMLDivElement {
}

connectedCallback() {
this.style.display = 'none'

if ('windowControlsOverlay' in navigator) {
navigator.windowControlsOverlay.addEventListener(
"geometrychange",
'geometrychange',
debounce((event) => {
const { visible } = navigator.windowControlsOverlay;
const { width } = event.titlebarAreaRect;
const is = visible ? "visible" : "hidden";
console.log(`Overlay is ${is} with ${width}px`);
if (this.style.display === 'none') this.#setstyles()

const {visible} = navigator.windowControlsOverlay
const {width} = event.titlebarAreaRect
const is = visible ? 'visible' : 'hidden'
console.log(`Overlay is ${is} with ${width}px`)
})
);
)
}
}

#setstyles() {
this.style.position = 'fixed'
this.style.left = `env(titlebar-area-x, 0)`
this.style.top = `env(titlebar-area-y, 0)`
this.style.height = `env(titlebar-area-height, 50px)`
this.style.width = `env(titlebar-area-width, 100%)`
this.style.color = `rgb(var(--cw-surface-rgb))`
this.style.display = `flex`
this.style.alignContent = `center`
this.style.justifyContent = `center`
this.style.fontWeight = `bold`
this.style.fontSize = `1.2em`
this.style.margin = `0`
}
}
1 change: 0 additions & 1 deletion src/app/events/form/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/events/index.ts

This file was deleted.

65 changes: 0 additions & 65 deletions src/app/events/presentation/presentation.handled.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/app/events/presentation/presentation.submitted.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/app/events/sponsor/sponsor.selected.ts

This file was deleted.

39 changes: 29 additions & 10 deletions src/app/store/actions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import {Presentation, SubmittedPresentation} from '@interfaces/presentation'
import {ImageLayer, PresentationLayer} from '../core'
import {Schema} from '@interfaces/schema'
import {action} from '@utils/state'

export interface Login {
username: string
password: string
}
/**
* Form
*/
export const updateForm = action<Schema>('form.updated')

export interface Logged {
accressToken: string
}
/**
* Presentation
*/
export const submitPresentation = action<SubmittedPresentation>(
'presentation.submitted'
)

export const login = action<Login>('Login')
export const loginSuccess = action<Logged>('Login Success')
export const loginError = action<DOMException>('Login Error')
export const handlePresentation = action<Presentation>('presentation.handled')

export const createPresentation = action<PresentationLayer>(
'presentation.created'
)

export const addPresentation = action<PresentationLayer>('presentation.added')

/**
* Sponsor
*/
export const selectSponsor = action<File>('sponsor.selected')

export const createSponsor = action<ImageLayer>('sponsor.created')

export const addSponsor = action<ImageLayer>('sponsor.added')
Loading

0 comments on commit 3859c39

Please sign in to comment.