Skip to content

Commit

Permalink
fix localstorage user first time visit api dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 17, 2024
1 parent 5816159 commit 292496e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
3 changes: 2 additions & 1 deletion uikit/src/button/styles.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.btn {
@apply inline-flex items-center justify-center whitespace-nowrap rounded-lg font-semibold transition-colors;
@apply cursor-pointer focus:outline-none focus-visible:outline-none focus-visible:ring-0;
@apply cursor-pointer;
@apply focus-within:outline-none focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-1;
@apply disabled:pointer-events-none disabled:bg-zinc-100 disabled:text-zinc-400;

&-primary {
Expand Down
2 changes: 1 addition & 1 deletion uikit/src/input/styles.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.input {
@apply border-border placeholder:text-muted-foreground flex h-9 w-full rounded-lg border bg-transparent px-3 py-1 transition-colors;
@apply disabled:cursor-not-allowed disabled:opacity-50;
@apply focus-visible:ring-secondary focus-visible:outline-none focus-visible:ring-1;
@apply focus-within:outline-none focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-1;
@apply file:border-0 file:bg-transparent file:font-medium;
}
1 change: 1 addition & 0 deletions uikit/src/select/styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.select {
@apply placeholder:text-muted-foreground border-border flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border bg-transparent px-3 py-2 text-sm shadow-sm disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1;
@apply focus-within:outline-none focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-1;

&-caret {
@apply h-4 w-4 opacity-50;
Expand Down
2 changes: 1 addition & 1 deletion uikit/src/textarea/styles.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.textarea-input {
@apply border-border placeholder:text-muted-foreground flex w-full rounded-md border bg-transparent px-3 py-2 transition-colors;
@apply disabled:cursor-not-allowed disabled:opacity-50;
@apply focus-visible:ring-secondary focus-visible:outline-none focus-visible:ring-1;
@apply focus-within:outline-none focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-1;
@apply file:border-0 file:bg-transparent file:font-medium;
}
35 changes: 19 additions & 16 deletions web/containers/DropdownListSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'

import { InferenceEngine, Model } from '@janhq/core'
import {
Expand Down Expand Up @@ -80,8 +81,6 @@ export default function DropdownListSidebar() {
return 4096
}

const selectedRef = useRef(null)

useEffect(() => {
setSelectedModel(recommendedModel)
setSelected(activeModel || recommendedModel)
Expand All @@ -106,6 +105,7 @@ export default function DropdownListSidebar() {
}
setThreadModelParams(activeThread.id, modelParams)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
recommendedModel,
activeThread,
Expand Down Expand Up @@ -184,22 +184,26 @@ export default function DropdownListSidebar() {
<div
className={twMerge(
'relative w-full overflow-hidden rounded-md',
stateModel.loading && 'bg-blue-100'
stateModel.loading && 'bg-blue-200 text-blue-600'
)}
>
{stateModel.loading && (
<div
className="absolute left-0 top-0 z-10 h-full w-full rounded-md bg-blue-50/80"
style={{ width: `${loader}%` }}
/>
)}
<Select value={selected?.id} onValueChange={onValueSelected}>
<SelectTrigger className="w-full">
<SelectValue
placeholder="Choose model to start"
className="relative z-50"
>
{selectedName}
<SelectTrigger className="relative w-full">
<SelectValue placeholder="Choose model to start">
{stateModel.loading && (
<div
className="z-5 absolute left-0 top-0 h-full w-full rounded-md bg-blue-100/80"
style={{ width: `${loader}%` }}
/>
)}
<span
className={twMerge(
'relative z-20',
stateModel.loading && 'font-medium'
)}
>
{selectedName}
</span>
</SelectValue>
</SelectTrigger>
<SelectPortal>
Expand Down Expand Up @@ -237,7 +241,6 @@ export default function DropdownListSidebar() {
{downloadedModels.map((x, i) => (
<SelectItem
key={i}
ref={selectedRef}
value={x.id}
className={twMerge(x.id === selected?.id && 'bg-secondary')}
onClick={() => {
Expand Down
9 changes: 6 additions & 3 deletions web/screens/LocalServer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ const LocalServerScreen = () => {
useState<boolean>(false)

useEffect(() => {
if (localStorage.getItem(FIRST_TIME_VISIT_API_SERVER) === null) {
if (
localStorage.getItem(FIRST_TIME_VISIT_API_SERVER) === null ||
localStorage.getItem(FIRST_TIME_VISIT_API_SERVER) === 'true'
) {
localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, 'true')
setFirstTimeVisitAPIServer(true)
}
}, [])
}, [firstTimeVisitAPIServer])

return (
<div className="flex h-full w-full">
Expand All @@ -97,7 +100,7 @@ const LocalServerScreen = () => {
<Button
block
themes={serverEnabled ? 'danger' : 'success'}
disabled={stateModel.loading}
disabled={stateModel.loading || firstTimeVisitAPIServer}
onClick={() => {
if (serverEnabled) {
window.core?.api?.stopServer()
Expand Down

0 comments on commit 292496e

Please sign in to comment.