Skip to content

Commit b003499

Browse files
authored
Merge pull request #380 from widgetify-app/improve/ui
Improve/UI
2 parents 373e50b + d76c0ec commit b003499

62 files changed

Lines changed: 1745 additions & 1196 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

background/cache.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { ExpirationPlugin } from 'workbox-expiration'
33
import { registerRoute } from 'workbox-routing'
44
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
55
import { NavigationRoute } from 'workbox-routing'
6+
const allowedPaths = [
7+
'/extension/wigi-pad-data',
8+
'/date/events',
9+
'/news/rss',
10+
'/currencies',
11+
'/wallpapers',
12+
'/contents',
13+
]
614

715
export function setupCaching() {
816
if (typeof self !== 'undefined' && '__WB_MANIFEST' in self) {
@@ -11,6 +19,29 @@ export function setupCaching() {
1119
})
1220
}
1321

22+
registerRoute(
23+
({ url, request }) => {
24+
if (request.method !== 'GET') return false
25+
if (url.origin !== 'https://api.widgetify.ir') return false
26+
27+
return allowedPaths.some((path) => url.pathname.startsWith(path))
28+
},
29+
30+
new StaleWhileRevalidate({
31+
cacheName: 'widgetify-public-api',
32+
plugins: [
33+
new CacheableResponsePlugin({
34+
statuses: [200],
35+
}),
36+
new ExpirationPlugin({
37+
maxEntries: 150,
38+
maxAgeSeconds: 60 * 60 * 5,
39+
purgeOnQuotaError: true,
40+
}),
41+
],
42+
})
43+
)
44+
1445
const isDev = import.meta.env.DEV
1546

1647
if (!isDev) {

src/assets/images/no-internet.png

2.27 KB
Loading

src/common/constant/moods.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ export const moodOptions = [
66
colorClass: 'error',
77
borderClass: 'border-error/50',
88
},
9+
{
10+
value: 'normal',
11+
emoji: '😴',
12+
label: '',
13+
colorClass: 'warning',
14+
borderClass: 'border-yellow-400/50',
15+
},
916
{
1017
value: 'tired',
1118
emoji: '😴',

src/common/constant/store.key.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { CurrencyColorMode } from '@/context/currency.context'
22
import type { Theme } from '@/context/theme.context'
3-
import type { TodoOptions } from '@/context/todo.context'
43
import type { WidgetItem } from '@/context/widget-visibility.context'
54
import type { Bookmark } from '@/layouts/bookmark/types/bookmark.types'
65
import type { PetSettings } from '@/layouts/widgetify-card/pets/pet.context'
@@ -63,7 +62,6 @@ export interface StorageKV {
6362
}[]
6463
calendarDrawerState: boolean
6564
pets: PetSettings
66-
todoOptions: TodoOptions
6765
youtubeSettings: {
6866
username: string | null
6967
subscriptionStyle: 'short' | 'long'
@@ -89,5 +87,7 @@ export interface StorageKV {
8987
petState: boolean
9088
showNewBadgeForReOrderWidgets: boolean
9189
navbarVisible: boolean
90+
todoFilter: string
91+
todoSort: string
9292
[key: `removed_notification_${string}`]: string
9393
}

src/common/storage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export async function setWithExpiry<K extends keyof StorageKV>(
6363
value: StorageKV[K],
6464
minutes: number
6565
) {
66-
const expiry = Date.now() + minutes * 60000
66+
const safeMinutes = Math.max(1, minutes)
67+
const expiry = Date.now() + safeMinutes * 60_000
6768
const data = { value, expiry }
6869

6970
await setToStorage(key, data as any)

src/common/toast.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type React from 'react'
1+
import React from 'react'
22
import toast from 'react-hot-toast'
33
import { playAlarm } from './playAlarm'
44

@@ -165,17 +165,18 @@ export function showToast(
165165
)
166166
}
167167
} else {
168-
toast.custom((t) => (
169-
<div
170-
className={`${t.visible ? 'animate-enter' : 'animate-leave'} max-w-md w-full bg-white shadow-lg rounded-lg pointer-events-auto flex ring-1 ring-black ring-opacity-5`}
171-
>
172-
<div className="flex-1 w-0 p-4">
173-
<div className="flex items-start">
174-
<div className="flex-1 ml-3">{message}</div>
168+
if (React.isValidElement(message))
169+
toast.custom((t) => (
170+
<div
171+
className={`${t.visible ? 'animate-enter' : 'animate-leave'} max-w-md w-full bg-white shadow-lg rounded-lg pointer-events-auto flex ring-1 ring-black ring-opacity-5`}
172+
>
173+
<div className="flex-1 w-0 p-4">
174+
<div className="flex items-start">
175+
<div className="flex-1 ml-3">{message}</div>
176+
</div>
175177
</div>
176178
</div>
177-
</div>
178-
))
179+
))
179180
}
180181

181182
if (options?.alarmSound) {

src/common/utils/icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getFaviconFromUrl = (url: string): string => {
2424
}
2525

2626
const urlObj = new URL(processedUrl)
27-
return `https://www.google.com/s2/favicons?domain=${urlObj.hostname}&sz=64`
27+
return `https://www.google.com/s2/favicons?domain=${urlObj.hostname}&sz=64&fallback_opts=404`
2828
} catch {
2929
return ''
3030
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface Prop {
2+
className: string
3+
}
4+
export function NewBadge({ className }: Prop) {
5+
return (
6+
<span
7+
className={`absolute w-2 h-2 rounded-full ${className} bg-error animate-pulse`}
8+
></span>
9+
)
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useGeneralSetting } from '@/context/general-setting.context'
2+
import Tooltip from '../toolTip'
3+
import { Button } from '../button/button'
4+
import { FaEye, FaEyeSlash } from 'react-icons/fa'
5+
6+
export function BlurModeButton() {
7+
const { blurMode, updateSetting } = useGeneralSetting()
8+
9+
const handleBlurModeToggle = () => {
10+
const newBlurMode = !blurMode
11+
updateSetting('blurMode', newBlurMode)
12+
}
13+
14+
return (
15+
<Tooltip content={blurMode ? 'نمایش' : 'حالت مخفی'}>
16+
<Button
17+
size="sm"
18+
onClick={handleBlurModeToggle}
19+
className={`px-2 py-0! border-none! rounded-xl text-base-content/40 shrink-0 active:scale-95 h-7!`}
20+
>
21+
{blurMode ? <FaEye /> : <FaEyeSlash />}
22+
</Button>
23+
</Tooltip>
24+
)
25+
}

src/components/button/button.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface ButtonProps {
1515
children?: React.ReactNode
1616
isPrimary?: boolean
1717
size: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
18+
ref?: any
1819
}
1920
export function Button(prop: ButtonProps) {
2021
const sizes: Record<string, string> = {
@@ -32,6 +33,7 @@ export function Button(prop: ButtonProps) {
3233
disabled={prop.disabled}
3334
className={`btn cursor-pointer ${prop.fullWidth ? 'full-width' : ''} ${prop.className} ${prop.rounded ? `rounded-${prop.rounded}` : ''} ${prop.isPrimary ? 'btn-primary text-white' : ''} ${sizes[prop.size] || 'btn-md'} active:!translate-y-0`}
3435
style={prop.style}
36+
ref={prop.ref}
3537
>
3638
{prop.loading
3739
? prop.loadingText || (

0 commit comments

Comments
 (0)