mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-03-11 04:49:49 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
4af8950602
|
|||
|
3fb0f7166b
|
|||
|
0ffd1e52ae
|
|||
|
f177d6448d
|
23
README.md
23
README.md
@@ -181,3 +181,26 @@ This project is licensed under the GNU Affero General Public License v3.0 - see
|
||||
## Support
|
||||
|
||||
If you encounter any issues or have questions, please file an issue on the GitHub repository.
|
||||
|
||||
## Issues
|
||||
|
||||
### Missing Permissions
|
||||
|
||||
Especially when updating from older versions, it may be that the permissions used in the newer versions have never been set. This causes numerous `missing permissions` errors to appear. The solution is to update the `auth.json` in the `data` directory for each user to include the following json:
|
||||
|
||||
```json
|
||||
"permissions": [{
|
||||
"habit": {
|
||||
"write": true,
|
||||
"interact": true
|
||||
},
|
||||
"wishlist": {
|
||||
"write": true,
|
||||
"interact": true
|
||||
},
|
||||
"coins": {
|
||||
"write": true,
|
||||
"interact": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -10,6 +10,7 @@ import LoadingSpinner from './LoadingSpinner';
|
||||
import PomodoroTimer from './PomodoroTimer';
|
||||
import RefreshBanner from './RefreshBanner';
|
||||
import UserSelectModal from './UserSelectModal';
|
||||
import { DATA_FRESHNESS_INTERVAL } from '@/lib/constants';
|
||||
|
||||
function ClientWrapperContent({ children }: { children: ReactNode }) {
|
||||
const [pomo] = useAtom(pomodoroAtom)
|
||||
@@ -52,9 +53,7 @@ function ClientWrapperContent({ children }: { children: ReactNode }) {
|
||||
useEffect(() => {
|
||||
// Interval for polling data freshness
|
||||
if (clientToken && !showRefreshBanner && status === 'authenticated') {
|
||||
const intervalId = setInterval(() => {
|
||||
performFreshnessCheck();
|
||||
}, 30000); // Check every 30 seconds
|
||||
const intervalId = setInterval(performFreshnessCheck, DATA_FRESHNESS_INTERVAL);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { settingsAtom } from '@/lib/atoms'
|
||||
import { useAtom } from 'jotai'
|
||||
import { Coins } from 'lucide-react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import dynamic from 'next/dynamic'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Coins } from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import TodayEarnedCoins from './TodayEarnedCoins';
|
||||
|
||||
const TodayEarnedCoins = dynamic(() => import('./TodayEarnedCoins'), { ssr: false })
|
||||
|
||||
export default function CoinBalance({ coinBalance }: { coinBalance: number }) {
|
||||
export default function CoinBalance({ coinBalance }: { coinBalance: number | undefined }) {
|
||||
const t = useTranslations('CoinBalance');
|
||||
const [settings] = useAtom(settingsAtom)
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -20,7 +16,7 @@ export default function CoinBalance({ coinBalance }: { coinBalance: number }) {
|
||||
<Coins className="h-12 w-12 text-yellow-400 mr-4" />
|
||||
<div className="flex flex-col">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-4xl font-bold">{coinBalance}</span>
|
||||
<span className="text-4xl font-bold">{coinBalance ? coinBalance : "…"}</span>
|
||||
<div className="flex items-center gap-1">
|
||||
<TodayEarnedCoins longFormat={true} />
|
||||
</div>
|
||||
|
||||
@@ -357,12 +357,8 @@ export default function DailyOverview({
|
||||
coinBalance,
|
||||
}: UpcomingItemsProps) {
|
||||
const t = useTranslations('DailyOverview');
|
||||
const { completeHabit, undoComplete } = useHabits()
|
||||
const [settings] = useAtom(settingsAtom)
|
||||
const [completedHabitsMap] = useAtom(completedHabitsMapAtom)
|
||||
const [browserSettings, setBrowserSettings] = useAtom(browserSettingsAtom)
|
||||
const today = getTodayInTimezone(settings.system.timezone)
|
||||
const todayCompletions = completedHabitsMap.get(today) || []
|
||||
const { saveHabit } = useHabits()
|
||||
|
||||
const timezone = settings.system.timezone
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useCoins } from '@/hooks/useCoins'
|
||||
import { habitsAtom, wishlistAtom } from '@/lib/atoms'
|
||||
import { coinsAtom, currentUserIdAtom, habitsAtom, wishlistAtom } from '@/lib/atoms'
|
||||
import { useAtom } from 'jotai'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import CoinBalance from './CoinBalance'
|
||||
@@ -10,11 +9,12 @@ import HabitStreak from './HabitStreak'
|
||||
|
||||
export default function Dashboard() {
|
||||
const t = useTranslations('Dashboard');
|
||||
const [habitsData] = useAtom(habitsAtom)
|
||||
const habits = habitsData.habits
|
||||
const { balance } = useCoins()
|
||||
const [wishlist] = useAtom(wishlistAtom)
|
||||
const wishlistItems = wishlist.items
|
||||
const [{ habits }] = useAtom(habitsAtom);
|
||||
const [loggedInUserId] = useAtom(currentUserIdAtom);
|
||||
const [{ transactions }] = useAtom(coinsAtom);
|
||||
const [{ items }] = useAtom(wishlistAtom);
|
||||
|
||||
const loggedInUserBalance = loggedInUserId ? transactions.filter(transaction => transaction.userId === loggedInUserId).reduce((sum, transaction) => sum + transaction.amount, 0) : 0;
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -22,15 +22,13 @@ export default function Dashboard() {
|
||||
<h1 className="text-xl xs:text-3xl font-bold">{t('title')}</h1>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<CoinBalance coinBalance={balance} />
|
||||
<CoinBalance coinBalance={loggedInUserId ? loggedInUserBalance : undefined} />
|
||||
<HabitStreak habits={habits} />
|
||||
<DailyOverview
|
||||
wishlistItems={wishlistItems}
|
||||
wishlistItems={items}
|
||||
habits={habits}
|
||||
coinBalance={balance}
|
||||
coinBalance={loggedInUserBalance}
|
||||
/>
|
||||
|
||||
{/* <HabitHeatmap habits={habits} /> */}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -135,6 +135,7 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
|
||||
<span className={`text-sm font-medium ${habit.archived ? 'text-gray-400 dark:text-gray-500' : ''}`}>{t('coinsPerCompletion', { count: habit.coinReward })}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='mt-2 text-sm font-medium'>{t("completionCount", { completions: habit.completions.length })}</div>
|
||||
</CardContent>
|
||||
<CardFooter className="flex-shrink-0 flex justify-between gap-2">
|
||||
<div className="flex gap-2">
|
||||
|
||||
@@ -128,7 +128,7 @@ export default function UserSelectModal({ onClose }: { onClose: () => void }) {
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [usersData, setUsersData] = useAtom(usersAtom);
|
||||
const [usersData] = useAtom(usersAtom);
|
||||
const users = usersData.users;
|
||||
const [currentUser] = useAtom(currentUserAtom);
|
||||
|
||||
|
||||
10
lib/atoms.ts
10
lib/atoms.ts
@@ -22,6 +22,7 @@ import {
|
||||
getDefaultWishlistData,
|
||||
Habit,
|
||||
PomodoroAtom,
|
||||
User,
|
||||
UserId
|
||||
} from "./types";
|
||||
|
||||
@@ -77,6 +78,10 @@ export const currentUserAtom = atom((get) => {
|
||||
return users.users.find(user => user.id === currentUserId);
|
||||
})
|
||||
|
||||
function removeHasPassword(users: Omit<User, 'password'>[]): Omit<User, 'password'>[] {
|
||||
return users.map(user => { delete user.hasPassword; return user });
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronous atom that calculates a freshness token (hash) based on the current client-side data.
|
||||
* This token can be compared with a server-generated token to detect data discrepancies.
|
||||
@@ -86,9 +91,10 @@ export const clientFreshnessTokenAtom = atom(async (get) => {
|
||||
const habits = get(habitsAtom);
|
||||
const coins = get(coinsAtom);
|
||||
const wishlist = get(wishlistAtom);
|
||||
const users = get(usersAtom);
|
||||
const users = structuredClone(get(usersAtom));
|
||||
const usersWithoutHasPassword = removeHasPassword(users.users);
|
||||
|
||||
const dataString = prepareDataForHashing(settings, habits, coins, wishlist, users);
|
||||
const dataString = prepareDataForHashing(settings, habits, coins, wishlist, { users: usersWithoutHasPassword });
|
||||
const hash = await generateCryptoHash(dataString);
|
||||
return hash;
|
||||
});
|
||||
|
||||
@@ -33,4 +33,6 @@ export const QUICK_DATES = [
|
||||
|
||||
export const MAX_COIN_LIMIT = 9999
|
||||
|
||||
export const DESKTOP_DISPLAY_ITEM_COUNT = 4
|
||||
export const DESKTOP_DISPLAY_ITEM_COUNT = 4
|
||||
|
||||
export const DATA_FRESHNESS_INTERVAL = 30000;
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "Completa ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "Desfés",
|
||||
"editButton": "Edita"
|
||||
"editButton": "Edita",
|
||||
"completionCount": "completat {completions} vegades"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "Nota massa llarga",
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "Abschließen ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "Rückgängig",
|
||||
"editButton": "Bearbeiten"
|
||||
"editButton": "Bearbeiten",
|
||||
"completionCount": "{completions} mal abgeschlossen"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "Notiz zu lang",
|
||||
@@ -434,8 +435,6 @@
|
||||
"invalidAmountDescription": "Bitte geben Sie eine gültige positive Zahl ein",
|
||||
"successTitle": "Erfolg",
|
||||
"transactionNotFoundDescription": "Transaktion nicht gefunden",
|
||||
"maxAmountExceededDescription": "Der Betrag darf {max} nicht überschreiten.",
|
||||
"transactionNotFoundDescription": "Transaktion nicht gefunden",
|
||||
"maxAmountExceededDescription": "Der Betrag darf {max} nicht überschreiten."
|
||||
},
|
||||
"DrawingModal": {
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "Complete ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "Undo",
|
||||
"editButton": "Edit"
|
||||
"editButton": "Edit",
|
||||
"completionCount": "Completed {completions} times"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "Note too long",
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "Completar ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "Deshacer",
|
||||
"editButton": "Editar"
|
||||
"editButton": "Editar",
|
||||
"completionCount": "{completions} veces completadas"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "Nota demasiado larga",
|
||||
@@ -442,8 +443,6 @@
|
||||
"invalidAmountDescription": "Por favor ingresa un número positivo válido",
|
||||
"successTitle": "Éxito",
|
||||
"transactionNotFoundDescription": "Transacción no encontrada",
|
||||
"maxAmountExceededDescription": "La cantidad no puede exceder {max}.",
|
||||
"transactionNotFoundDescription": "Transacción no encontrada",
|
||||
"maxAmountExceededDescription": "La cantidad no puede exceder {max}."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "Compléter ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "Annuler",
|
||||
"editButton": "Modifier"
|
||||
"editButton": "Modifier",
|
||||
"completionCount": "complété {completions} fois"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "Note trop longue",
|
||||
@@ -434,8 +435,6 @@
|
||||
"invalidAmountDescription": "Veuillez entrer un nombre positif valide",
|
||||
"successTitle": "Succès",
|
||||
"transactionNotFoundDescription": "Transaction non trouvée",
|
||||
"maxAmountExceededDescription": "Le montant ne peut pas dépasser {max}.",
|
||||
"transactionNotFoundDescription": "Transaction non trouvée",
|
||||
"maxAmountExceededDescription": "Le montant ne peut pas dépasser {max}."
|
||||
},
|
||||
"DrawingModal": {
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "完了({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "取り消し",
|
||||
"editButton": "編集"
|
||||
"editButton": "編集",
|
||||
"completionCount": "{completions} 回完了しました"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "メモが長すぎます",
|
||||
@@ -434,8 +435,6 @@
|
||||
"invalidAmountDescription": "有効な正の数を入力してください",
|
||||
"successTitle": "成功しました",
|
||||
"transactionNotFoundDescription": "取引が見つかりません",
|
||||
"maxAmountExceededDescription": "金額は{max}を超えることはできません。",
|
||||
"transactionNotFoundDescription": "取引が見つかりません",
|
||||
"maxAmountExceededDescription": "金額は{max}を超えることはできません。"
|
||||
},
|
||||
"DrawingModal": {
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "완료 ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "실행 취소",
|
||||
"editButton": "수정"
|
||||
"editButton": "수정",
|
||||
"completionCount": "{completions}번 완료됨"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "메모가 너무 깁니다",
|
||||
@@ -430,8 +431,6 @@
|
||||
"invalidAmountDescription": "유효한 양의 숫자를 입력하세요",
|
||||
"successTitle": "성공",
|
||||
"transactionNotFoundDescription": "거래를 찾을 수 없습니다",
|
||||
"maxAmountExceededDescription": "금액은 {max}을(를) 초과할 수 없습니다.",
|
||||
"transactionNotFoundDescription": "거래를 찾을 수 없습니다",
|
||||
"maxAmountExceededDescription": "금액은 {max}을(를) 초과할 수 없습니다."
|
||||
},
|
||||
"Warning": {
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "Выполнить ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "Отменить",
|
||||
"editButton": "Редактировать"
|
||||
"editButton": "Редактировать",
|
||||
"completionCount": "завершено {completions} раз"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "Слишком длинная заметка",
|
||||
@@ -434,8 +435,6 @@
|
||||
"invalidAmountDescription": "Пожалуйста, введите положительное число",
|
||||
"successTitle": "Успех",
|
||||
"transactionNotFoundDescription": "Транзакция не найдена",
|
||||
"maxAmountExceededDescription": "Сумма не может превышать {max}.",
|
||||
"transactionNotFoundDescription": "Транзакция не найдена",
|
||||
"maxAmountExceededDescription": "Сумма не может превышать {max}."
|
||||
},
|
||||
"DrawingModal": {
|
||||
|
||||
@@ -322,7 +322,8 @@
|
||||
"completeButtonCount": "完成 ({completed}/{target})",
|
||||
"completeButtonCountMobile": "{completed}/{target}",
|
||||
"undoButton": "撤销",
|
||||
"editButton": "编辑"
|
||||
"editButton": "编辑",
|
||||
"completionCount": "完成 {completions} 次"
|
||||
},
|
||||
"TransactionNoteEditor": {
|
||||
"noteTooLongTitle": "备注太长",
|
||||
@@ -434,8 +435,6 @@
|
||||
"invalidAmountDescription": "请输入有效的正数",
|
||||
"successTitle": "成功",
|
||||
"transactionNotFoundDescription": "未找到交易记录",
|
||||
"maxAmountExceededDescription": "金额不能超过 {max}。",
|
||||
"transactionNotFoundDescription": "未找到交易记录",
|
||||
"maxAmountExceededDescription": "金额不能超过 {max}。"
|
||||
},
|
||||
"DrawingModal": {
|
||||
|
||||
Reference in New Issue
Block a user