Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize utility functions #50

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-mails-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gov4git-desktop-app': patch
---

Centralize utility functions
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"files.watcherExclude": {
"**/target": true
},
}
}
48 changes: 47 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"tsup": "^8.0.1",
"tsx": "^4.6.0",
"typescript": "^5.3.2",
"vite": "^5.0.3"
"vite": "^5.0.3",
"vite-tsconfig-paths": "^4.2.1"
},
"dependencies": {
"@fluentui/react-components": "^9.41.0",
Expand All @@ -109,4 +110,4 @@
"type": "git",
"url": "https://github.com/gov4git/desktop-application.git"
}
}
}
2 changes: 1 addition & 1 deletion src/electron/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { integer, real, sqliteTable, text } from 'drizzle-orm/sqlite-core'

import { type Ballot as BallotType, Config } from '~/shared'
import { type Ballot as BallotType } from '~/shared'

export const ballots = sqliteTable('ballots', {
identifier: text('identifier').primaryKey(),
Expand Down
5 changes: 0 additions & 5 deletions src/electron/lib/error.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/electron/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './paths.js'
export * from './records.js'
export * from './error.js'
export * from './stdout.js'
53 changes: 0 additions & 53 deletions src/electron/lib/records.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/electron/services/AppUpdaterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AppUpdaterService extends AbstractAppUpdaterService {
const updateInfo = await autoUpdater.checkForUpdates()
if (updateInfo == null) return null
if (updateInfo.downloadPromise != null) {
this.updating = updateInfo.downloadPromise.then((r) => {
this.updating = updateInfo.downloadPromise.then(() => {
return {
ready: true,
version: updateInfo.updateInfo.version,
Expand Down
5 changes: 3 additions & 2 deletions src/electron/services/BallotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AbstractBallotService,
Ballot,
CreateBallotOptions,
serialAsync,
VoteOption,
} from '~/shared'

Expand Down Expand Up @@ -294,7 +295,7 @@ export class BallotService extends AbstractBallotService {
return this.loadBallot(user.username, community.url, ballotId)
}

public loadBallots = async () => {
public loadBallots = serialAsync(async () => {
const [userRows, communityRows] = await Promise.all([
this.db.select().from(users).limit(1),
this.db
Expand Down Expand Up @@ -328,7 +329,7 @@ export class BallotService extends AbstractBallotService {
}

await Promise.all(ballotPromises)
}
})

public getBallots = async () => {
const selectedCommunity = (
Expand Down
2 changes: 1 addition & 1 deletion src/electron/services/LogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { dirname, resolve } from 'node:path'
import fastRedact from 'fast-redact'

import { AbstractLogService } from '~/shared'
import { isRecord } from '~/shared'

import { toResolvedPath } from '../lib/paths.js'
import { isRecord } from '../lib/records.js'

export type Redacter = (...args: any[]) => string

Expand Down
3 changes: 1 addition & 2 deletions src/electron/services/Services.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { InvokeServiceProps, ServiceId } from '~/shared'

import { isRecord } from '../lib/records.js'
import { isRecord } from '~/shared'

export class Services {
protected declare services: Record<string, unknown>
Expand Down
6 changes: 3 additions & 3 deletions src/electron/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { and, eq } from 'drizzle-orm'

import { AbstractUserService } from '~/shared'
import { AbstractUserService, serialAsync } from '~/shared'

import { DB } from '../db/db.js'
import {
Expand Down Expand Up @@ -209,7 +209,7 @@ export class UserService extends AbstractUserService {
return []
}

public loadUser = async () => {
public loadUser = serialAsync(async () => {
const [allUsers, selectedCommunities] = await Promise.all([
this.db.select().from(users),
this.db.select().from(communities).where(eq(communities.selected, true)),
Expand Down Expand Up @@ -271,7 +271,7 @@ export class UserService extends AbstractUserService {
communities: community,
userCommunities: userCommunity,
}
}
})

public getUser = async () => {
const userInfos = (
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/components/BubbleSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
useState,
} from 'react'

import { formatDecimal } from '../lib/numbers.js'
import { formatDecimal } from '~/shared'

import { useBubbleSliderStyles } from './BubbleSlider.styles.js'

export type BubbleSliderProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/components/CreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
import { FormEvent, useCallback, useState } from 'react'
import { useNavigate } from 'react-router-dom'

import { createNestedRecord, mergeDeep } from '~/shared'

import { routes } from '../App/index.js'
import { useCatchError } from '../hooks/useCatchError.js'
import { createNestedRecord, mergeDeep } from '../lib/index.js'
import { ballotService } from '../services/BallotService.js'
import { useButtonStyles } from '../styles/index.js'
import { useSettingsFormsStyles } from './SettingsForm.styles.js'
Expand Down
Loading