Compare commits

..

1 Commits

Author SHA1 Message Date
6934432fb5 fix: resolved linting problems 2025-05-14 11:02:12 +02:00
11 changed files with 164 additions and 78 deletions

94
.github/workflows/docker-publish.yml vendored Normal file
View File

@@ -0,0 +1,94 @@
name: Docker Build and Publish
on:
push:
branches:
- main
- github-actions
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
EXISTS: ${{ steps.check-version.outputs.EXISTS }}
VERSION: ${{ steps.package-version.outputs.VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Get version from package.json
id: package-version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if version exists
id: check-version
run: |
if docker pull dohsimpson/habittrove:v${{ steps.package-version.outputs.VERSION }} 2>/dev/null; then
echo "EXISTS=true" >> $GITHUB_OUTPUT
else
echo "EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.check-version.outputs.EXISTS == 'false' && format('dohsimpson/habittrove:v{0}', steps.package-version.outputs.VERSION) || '' }}
dohsimpson/habittrove:demo
deploy-demo:
runs-on: ubuntu-latest
needs: build-and-push
# demo tracks the demo tag
if: needs.build-and-push.outputs.EXISTS == 'false'
steps:
- uses: actions/checkout@v4
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout restart -n ${{ secrets.KUBE_NAMESPACE }} deploy/${{ secrets.KUBE_DEPLOYMENT }}
create-release:
runs-on: ubuntu-latest
needs: build-and-push
if: needs.build-and-push.outputs.EXISTS == 'false'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
VERSION: ${{ needs.build-and-push.outputs.VERSION }}
run: |
# Extract release notes from CHANGELOG.md
notes=$(awk -v version="$VERSION" '
$0 ~ "## Version " version {flag=1;next}
$0 ~ "## Version " && flag {exit}
flag' CHANGELOG.md)
gh release create "v$VERSION" \
--repo="$GITHUB_REPOSITORY" \
--title="v$VERSION" \
--notes="$notes"

View File

@@ -1,40 +0,0 @@
name: Create and publish a Docker image to Github Container Registry
on:
push:
tags:
- v*
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
create-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

28
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Unit Tests
on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run lint
run: bun run lint
- name: Run unit tests
run: bun test

View File

@@ -22,8 +22,11 @@ Want to try HabitTrove before installing? Visit the public [demo instance](https
## Usage ## Usage
1. **Creating Habits**: Click the "Add Habit" button to create a new habit. Set a name, description, and coin reward. 1. **Creating Habits**: Click the "Add Habit" button to create a new habit. Set a name, description, and coin reward.
2. **Tracking Habits**: Mark habits as complete on your dashboard. Each completion earns you the specified coins. 2. **Tracking Habits**: Mark habits as complete on your dashboard. Each completion earns you the specified coins.
3. **Wishlist**: Add rewards to your wishlist that you can redeem with earned coins. 3. **Wishlist**: Add rewards to your wishlist that you can redeem with earned coins.
4. **Statistics**: View your progress through the heatmap and streak counters. 4. **Statistics**: View your progress through the heatmap and streak counters.
## Docker Deployment ## Docker Deployment
@@ -60,7 +63,7 @@ docker run -d \
-v ./data:/app/data \ -v ./data:/app/data \
-v ./backups:/app/backups \ # Add this line to map the backups directory -v ./backups:/app/backups \ # Add this line to map the backups directory
-e AUTH_SECRET=$AUTH_SECRET \ -e AUTH_SECRET=$AUTH_SECRET \
ghcr.io/manindark/habittrove dohsimpson/habittrove
``` ```
Available image tags: Available image tags:
@@ -107,7 +110,7 @@ To contribute to HabitTrove, you'll need to set up a development environment. He
1. Clone the repository and navigate to the project directory: 1. Clone the repository and navigate to the project directory:
```bash ```bash
git clone https://github.com/ManInDark/HabitTrove.git git clone https://github.com/dohsimpson/habittrove.git
cd habittrove cd habittrove
``` ```
@@ -160,7 +163,7 @@ Run these commands regularly during development to catch issues early.
## Contributing ## Contributing
We welcome feature requests and bug reports! Please [open an issue](https://github.com/ManInDark/habittrove/issues/new). We welcome feature requests and bug reports! Please [open an issue](https://github.com/dohsimpson/habittrove/issues/new). We do not accept pull request at the moment.
## License ## License

View File

@@ -56,13 +56,11 @@ export default function AboutModal({ isOpen, onClose }: AboutModalProps) {
> >
@dohsimpson @dohsimpson
</a> </a>
<br/>
Fork by <a href="https://github.com/ManInDark" target="_blank" rel="noopener noreferrer" className="font-medium hover:underline">@ManInDark</a>
</div> </div>
<div className="flex justify-center"> <div className="flex justify-center">
<a <a
href="https://github.com/ManInDark/HabitTrove" href="https://github.com/dohsimpson/habittrove"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
> >

View File

@@ -43,6 +43,7 @@ export default function AddEditHabitModal({ onClose, onSave, habit, isTask }: Ad
const [ruleText, setRuleText] = useState<string>(initialRuleText) const [ruleText, setRuleText] = useState<string>(initialRuleText)
const { currentUser } = useHelpers() const { currentUser } = useHelpers()
const [isQuickDatesOpen, setIsQuickDatesOpen] = useState(false) const [isQuickDatesOpen, setIsQuickDatesOpen] = useState(false)
const [ruleError, setRuleError] = useState<string | null>(null); // State for validation message
const [selectedUserIds, setSelectedUserIds] = useState<string[]>((habit?.userIds || []).filter(id => id !== currentUser?.id)) const [selectedUserIds, setSelectedUserIds] = useState<string[]>((habit?.userIds || []).filter(id => id !== currentUser?.id))
const [usersData] = useAtom(usersAtom) const [usersData] = useAtom(usersAtom)
const users = usersData.users const users = usersData.users
@@ -84,8 +85,6 @@ export default function AddEditHabitModal({ onClose, onSave, habit, isTask }: Ad
}) })
} }
const { result, message: errorMessage } = convertHumanReadableFrequencyToMachineReadable({ text: ruleText, timezone: settings.system.timezone, isRecurring: isRecurRule });
return ( return (
<Dialog open={true} onOpenChange={onClose}> <Dialog open={true} onOpenChange={onClose}>
<DialogContent> <DialogContent>
@@ -195,9 +194,24 @@ export default function AddEditHabitModal({ onClose, onSave, habit, isTask }: Ad
</div> </div>
{/* rrule input (habit) */} {/* rrule input (habit) */}
<div className="col-start-2 col-span-3 text-sm"> <div className="col-start-2 col-span-3 text-sm">
<span className={errorMessage ? 'text-destructive' : 'text-muted-foreground'}> {(() => {
{errorMessage ? errorMessage : convertMachineReadableFrequencyToHumanReadable({ frequency: result, isRecurRule, timezone: settings.system.timezone })} let displayText = '';
</span> let errorMessage: string | null = null;
const { result, message } = convertHumanReadableFrequencyToMachineReadable({ text: ruleText, timezone: settings.system.timezone, isRecurring: isRecurRule });
errorMessage = message;
displayText = convertMachineReadableFrequencyToHumanReadable({ frequency: result, isRecurRule, timezone: settings.system.timezone })
return (
<>
<span className={errorMessage ? 'text-destructive' : 'text-muted-foreground'}>
{displayText}
</span>
{errorMessage && (
<p className="text-destructive text-xs mt-1">{errorMessage}</p>
)}
</>
);
})()}
</div> </div>
</div> </div>
<div className="grid grid-cols-4 items-center gap-4"> <div className="grid grid-cols-4 items-center gap-4">
@@ -315,7 +329,7 @@ export default function AddEditHabitModal({ onClose, onSave, habit, isTask }: Ad
)} )}
</div> </div>
<DialogFooter> <DialogFooter>
<Button type="submit" disabled={errorMessage !== null}>{habit ? 'Save Changes' : `Add ${isTask ? 'Task' : 'Habit'}`}</Button> <Button type="submit">{habit ? 'Save Changes' : `Add ${isTask ? 'Task' : 'Habit'}`}</Button>
</DialogFooter> </DialogFooter>
</form> </form>
</DialogContent> </DialogContent>

View File

@@ -43,7 +43,6 @@ export default function CoinsManager() {
const highlightId = searchParams.get('highlight') const highlightId = searchParams.get('highlight')
const userIdFromQuery = searchParams.get('user') // Get user ID from query const userIdFromQuery = searchParams.get('user') // Get user ID from query
const transactionRefs = useRef<Record<string, HTMLDivElement | null>>({}); const transactionRefs = useRef<Record<string, HTMLDivElement | null>>({});
const PAGE_ENTRY_COUNTS = [10, 50, 100, 500];
// Effect to set selected user from query param if admin // Effect to set selected user from query param if admin
useEffect(() => { useEffect(() => {
@@ -238,7 +237,9 @@ export default function CoinsManager() {
setCurrentPage(1) // Reset to first page when changing page size setCurrentPage(1) // Reset to first page when changing page size
}} }}
> >
{PAGE_ENTRY_COUNTS.map(n => <option key={n} value={n}>{n}</option>)} <option value={50}>50</option>
<option value={100}>100</option>
<option value={500}>500</option>
</select> </select>
<span className="text-sm text-muted-foreground">entries</span> <span className="text-sm text-muted-foreground">entries</span>
</div> </div>
@@ -274,7 +275,6 @@ export default function CoinsManager() {
} }
const isHighlighted = transaction.id === highlightId; const isHighlighted = transaction.id === highlightId;
const transactionUser = usersData.users.find(u => u.id === transaction.userId);
return ( return (
<div <div
key={transaction.id} key={transaction.id}
@@ -304,12 +304,12 @@ export default function CoinsManager() {
{transaction.userId && currentUser?.isAdmin && ( {transaction.userId && currentUser?.isAdmin && (
<Avatar className="h-6 w-6"> <Avatar className="h-6 w-6">
<AvatarImage <AvatarImage
src={transactionUser?.avatarPath ? src={usersData.users.find(u => u.id === transaction.userId)?.avatarPath ?
`/api/avatars/${transactionUser?.avatarPath?.split('/').pop()}` : undefined} `/api/avatars/${usersData.users.find(u => u.id === transaction.userId)?.avatarPath?.split('/').pop()}` : undefined}
alt={transactionUser?.username} alt={usersData.users.find(u => u.id === transaction.userId)?.username}
/> />
<AvatarFallback> <AvatarFallback>
{transactionUser?.username?.[0] || '?'} {usersData.users.find(u => u.id === transaction.userId)?.username?.[0] || '?'}
</AvatarFallback> </AvatarFallback>
</Avatar> </Avatar>
)} )}

View File

@@ -8,7 +8,6 @@ import { Calendar, Coins, Gift, Home } from 'lucide-react'
import Link from 'next/link' import Link from 'next/link'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import AboutModal from './AboutModal' import AboutModal from './AboutModal'
import { usePathname } from 'next/navigation'
type ViewPort = 'main' | 'mobile' type ViewPort = 'main' | 'mobile'
@@ -36,8 +35,6 @@ export default function Navigation({ className, viewPort }: NavigationProps) {
const [browserSettings] = useAtom(browserSettingsAtom) const [browserSettings] = useAtom(browserSettingsAtom)
const isTasksView = browserSettings.viewType === 'tasks' const isTasksView = browserSettings.viewType === 'tasks'
const { isIOS } = useHelpers() const { isIOS } = useHelpers()
const pathname = usePathname();
console.log(pathname, pathname === navItems(false)[1].href)
useEffect(() => { useEffect(() => {
const handleResize = () => { const handleResize = () => {
@@ -64,11 +61,7 @@ export default function Navigation({ className, viewPort }: NavigationProps) {
<Link <Link
key={item.label} key={item.label}
href={item.href} href={item.href}
className={"flex flex-col items-center py-2 hover:text-blue-600 dark:hover:text-blue-300 " + className="flex flex-col items-center justify-center py-2 text-gray-600 dark:text-gray-300 hover:text-blue-500 dark:hover:text-blue-400"
(pathname === (item.href) ?
"text-blue-500 dark:text-blue-500" :
"text-gray-300 dark:text-gray-300")
}
> >
<item.icon className="h-6 w-6" /> <item.icon className="h-6 w-6" />
<span className="text-xs mt-1">{item.label}</span> <span className="text-xs mt-1">{item.label}</span>
@@ -92,12 +85,9 @@ export default function Navigation({ className, viewPort }: NavigationProps) {
<Link <Link
key={item.label} key={item.label}
href={item.href} href={item.href}
className={"flex items-center px-2 py-2 font-medium rounded-md " + className="group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md text-gray-300 hover:text-white hover:bg-gray-700"
(pathname === (item.href) ?
"text-blue-500 hover:text-blue-600 hover:bg-gray-700" :
"text-gray-300 hover:text-white hover:bg-gray-700")}
> >
<item.icon className="mr-4 flex-shrink-0 h-6 w-6" aria-hidden="true" /> <item.icon className="mr-4 flex-shrink-0 h-6 w-6 text-gray-400" aria-hidden="true" />
{item.label} {item.label}
</Link> </Link>
))} ))}

View File

@@ -1,11 +1,10 @@
services: services:
habittrove: habittrove:
image: ghcr.io/manindark/habittrove
container_name: habittrove
ports: ports:
- "3000:3000" - "3000:3000"
volumes: volumes:
- "./data:/app/data" - "./data:/app/data"
- "./backups:/app/backups" - "./backups:/app/backups"
image: dohsimpson/habittrove
environment: environment:
- AUTH_SECRET=your-secret-key-here # Replace with your actual secret - AUTH_SECRET=your-secret-key-here # Replace with your actual secret

View File

@@ -1,8 +1,9 @@
// client helpers // client helpers
'use-client' 'use-client'
import { useAtom } from 'jotai'
import { useSession } from "next-auth/react" import { useSession } from "next-auth/react"
import { User, UserId } from './types'
import { useAtom } from 'jotai'
import { usersAtom } from './atoms' import { usersAtom } from './atoms'
import { checkPermission } from './utils' import { checkPermission } from './utils'
@@ -13,7 +14,7 @@ export function useHelpers() {
const currentUser = usersData.users.find((u) => u.id === currentUserId) const currentUser = usersData.users.find((u) => u.id === currentUserId)
// detect iOS: https://stackoverflow.com/a/9039885 // detect iOS: https://stackoverflow.com/a/9039885
function iOS() { function iOS() {
return typeof navigator !== "undefined" && ([ return [
'iPad Simulator', 'iPad Simulator',
'iPhone Simulator', 'iPhone Simulator',
'iPod Simulator', 'iPod Simulator',
@@ -22,7 +23,7 @@ export function useHelpers() {
'iPod', 'iPod',
].includes(navigator.platform) ].includes(navigator.platform)
// iPad on iOS 13 detection // iPad on iOS 13 detection
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)) || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
} }
return { return {

View File

@@ -44,7 +44,6 @@
"js-confetti": "^0.12.0", "js-confetti": "^0.12.0",
"linkify": "^0.2.1", "linkify": "^0.2.1",
"linkify-react": "^4.2.0", "linkify-react": "^4.2.0",
"lodash": "^4.17.21",
"lucide-react": "^0.469.0", "lucide-react": "^0.469.0",
"luxon": "^3.5.0", "luxon": "^3.5.0",
"next": "15.2.3", "next": "15.2.3",