Skip to content

Commit

Permalink
Updating hover and navigation stores.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike12345567 committed Dec 20, 2024
1 parent 8c0c765 commit fbeb15d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ import { get } from "svelte/store"
import { previewStore } from "stores/builder"
import { BudiStore } from "../BudiStore"

interface BuilderHoverStore {
hoverTimeout?: NodeJS.Timeout
componentId: string | null
}

export const INITIAL_HOVER_STATE = {
componentId: null,
}

export class HoverStore extends BudiStore {
hoverTimeout
export class HoverStore extends BudiStore<BuilderHoverStore> {
hoverTimeout?: NodeJS.Timeout

constructor() {
super({ ...INITIAL_HOVER_STATE })
this.hover = this.hover.bind(this)
}

hover(componentId, notifyClient = true) {
hover(componentId: string, notifyClient = true) {
clearTimeout(this.hoverTimeout)
if (componentId) {
this.processHover(componentId, notifyClient)
Expand All @@ -25,7 +30,7 @@ export class HoverStore extends BudiStore {
}
}

processHover(componentId, notifyClient) {
processHover(componentId: string, notifyClient?: boolean) {
if (componentId === get(this.store).componentId) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@ import { get } from "svelte/store"
import { API } from "api"
import { appStore } from "stores/builder"
import { BudiStore } from "../BudiStore"
import { AppNavigation, AppNavigationLink, UIObject } from "@budibase/types"

interface BuilderNavigationStore extends AppNavigation {}

export const INITIAL_NAVIGATION_STATE = {
navigation: "Top",
links: [],
title: null,
sticky: null,
hideLogo: null,
logoUrl: null,
hideTitle: null,
textAlign: "Left",
navBackground: null,
navWidth: null,
navTextColor: null,
}

export class NavigationStore extends BudiStore {
export class NavigationStore extends BudiStore<BuilderNavigationStore> {
constructor() {
super(INITIAL_NAVIGATION_STATE)
}

syncAppNavigation(nav) {
syncAppNavigation(nav: AppNavigation) {
this.update(state => ({
...state,
...nav,
Expand All @@ -33,15 +28,17 @@ export class NavigationStore extends BudiStore {
this.store.set({ ...INITIAL_NAVIGATION_STATE })
}

async save(navigation) {
async save(navigation: AppNavigation) {
const appId = get(appStore).appId
const app = await API.saveAppMetadata(appId, { navigation })
this.syncAppNavigation(app.navigation)
if (app.navigation) {
this.syncAppNavigation(app.navigation)
}
}

async saveLink(url, title, roleId) {
async saveLink(url: string, title: string, roleId: string) {
const navigation = get(this.store)
let links = [...(navigation?.links ?? [])]
let links: AppNavigationLink[] = [...(navigation?.links ?? [])]

// Skip if we have an identical link
if (links.find(link => link.url === url && link.text === title)) {
Expand All @@ -60,7 +57,7 @@ export class NavigationStore extends BudiStore {
})
}

async deleteLink(urls) {
async deleteLink(urls: string[] | string) {
const navigation = get(this.store)
let links = navigation?.links
if (!links?.length) {
Expand All @@ -86,7 +83,7 @@ export class NavigationStore extends BudiStore {
})
}

syncMetadata(metadata) {
syncMetadata(metadata: UIObject) {
const { navigation } = metadata
this.syncAppNavigation(navigation)
}
Expand Down
8 changes: 6 additions & 2 deletions packages/types/src/documents/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { User, Document, Plugin, Snippet } from "../"
import { SocketSession } from "../../sdk"
import { NavLink } from "../../ui"

Check failure on line 3 in packages/types/src/documents/app/app.ts

View workflow job for this annotation

GitHub Actions / lint

'NavLink' is defined but never used. Allowed unused vars must match /^_/u

export type AppMetadataErrors = { [key: string]: string[] }

Expand Down Expand Up @@ -37,22 +38,25 @@ export interface AppInstance {

export interface AppNavigation {
navigation: string
title: string
navWidth: string
title?: string
navWidth?: string
sticky?: boolean
hideLogo?: boolean
logoUrl?: string
hideTitle?: boolean
navBackground?: string
navTextColor?: string
links?: AppNavigationLink[]
textAlign?: string
}

export interface AppNavigationLink {
text: string
url: string
id?: string
roleId?: string
type?: string
subLinks?: AppNavigationLink[]
}

export interface AppCustomTheme {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/ui/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./integration"
export * from "./misc"
2 changes: 2 additions & 0 deletions packages/types/src/ui/stores/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// type purely to capture structures that the type is unknown, but maybe known later
export type UIObject = Record<string, any>

0 comments on commit fbeb15d

Please sign in to comment.