Skip to content

Commit bd90716

Browse files
Merge pull request #69 from HusniAbdillah/action-pages
Last
2 parents c370975 + bfa669d commit bd90716

File tree

7 files changed

+4
-32
lines changed

7 files changed

+4
-32
lines changed

public/sw.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// public/sw.js
21
const CACHE_NAME = 'greenactify-v2';
32
const STATIC_CACHE = 'static-v2';
43
const API_CACHE = 'api-v2';
@@ -17,7 +16,6 @@ const API_ENDPOINTS = [
1716
'/api/stats',
1817
];
1918

20-
// Install event
2119
self.addEventListener('install', (event) => {
2220
event.waitUntil(
2321
Promise.all([
@@ -28,7 +26,6 @@ self.addEventListener('install', (event) => {
2826
self.skipWaiting();
2927
});
3028

31-
// Activate event
3229
self.addEventListener('activate', (event) => {
3330
event.waitUntil(
3431
caches.keys().then(cacheNames => {
@@ -44,26 +41,22 @@ self.addEventListener('activate', (event) => {
4441
self.clients.claim();
4542
});
4643

47-
// Fetch event
4844
self.addEventListener('fetch', (event) => {
4945
const { request } = event;
5046
const url = new URL(request.url);
5147

52-
// Handle API requests
5348
if (url.pathname.startsWith('/api/')) {
5449
event.respondWith(
5550
caches.open(API_CACHE).then(cache => {
5651
return cache.match(request).then(cachedResponse => {
5752
if (cachedResponse) {
58-
// Return cached response and update in background
5953
fetch(request).then(response => {
6054
if (response.ok) {
6155
cache.put(request, response.clone());
6256
}
6357
});
6458
return cachedResponse;
6559
}
66-
// Fetch and cache new response
6760
return fetch(request).then(response => {
6861
if (response.ok) {
6962
cache.put(request, response.clone());
@@ -76,7 +69,6 @@ self.addEventListener('fetch', (event) => {
7669
return;
7770
}
7871

79-
// Handle static assets
8072
event.respondWith(
8173
caches.match(request).then(response => {
8274
return response || fetch(request);

src/app/(authenticated)/peringkat/page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import React, { useState, useEffect } from 'react'
44
import { Search, Users, MapPin, Trophy, Medal, Award } from 'lucide-react'
55
import { useRouter } from 'next/navigation'
66
import { useUser } from '@clerk/nextjs'
7-
import { useUsers, useProvinceStats } from '@/hooks/useSWRData' // Import SWR hooks
7+
import { useUsers, useProvinceStats } from '@/hooks/useSWRData'
88

9-
// Update interface User dengan properti yang lengkap
109
interface User {
1110
id?: string;
1211
clerk_id?: string;
@@ -35,14 +34,12 @@ const PeringkatPage = () => {
3534
const router = useRouter()
3635
const { isLoaded, isSignedIn } = useUser()
3736

38-
// SWR hooks - instant loading dari cache!
3937
const { data: usersResponse, isLoading: usersLoading, error: usersError } = useUsers()
4038
const { data: provincesResponse, isLoading: provincesLoading, error: provincesError } = useProvinceStats()
4139

4240
const usersData = usersResponse?.data || []
4341
const provincesData = provincesResponse?.data || []
4442

45-
// Check authentication
4643
useEffect(() => {
4744
if (isLoaded && !isSignedIn) {
4845
router.push('/')

src/app/(authenticated)/persebaran/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const UnifiedActivitiesPage = () => {
7474
loading: true
7575
})
7676

77-
// Check authentication
7877
useEffect(() => {
7978
if (isLoaded && !isSignedIn) {
8079
router.push('/')

src/app/api/activities/getById/[id]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function GET(
66
request: Request,
77
{ params }: { params: { id: string } }
88
) {
9-
const profileId = params.id; // UUID user
9+
const profileId = params.id;
1010

1111
if (!profileId) {
1212
return NextResponse.json(

src/app/api/daily-challenge/route.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export async function GET(request: NextRequest) {
5050
const indonesianTime = new Date(now.getTime() + (7 * 60 * 60 * 1000));
5151
const today = indonesianTime.toISOString().split('T')[0];
5252

53-
// Check if there are already challenges for today
5453
const { data: existingChallenges, error } = await supabase
5554
.from('daily_challenges')
5655
.select('*')
@@ -59,11 +58,9 @@ export async function GET(request: NextRequest) {
5958
if (!error && existingChallenges && existingChallenges.length > 0) {
6059
dbChallenges = existingChallenges;
6160
} else {
62-
// Get 3 random challenges that don't have today's date
6361
const randomChallenges = await getRandomChallenges(3);
6462

6563
if (randomChallenges.length > 0) {
66-
// Update all challenges to today's date
6764
const updatePromises = randomChallenges.map(async (challenge: any) => {
6865
const updateSuccess = await updateChallengeDate(challenge.id, today);
6966

@@ -83,7 +80,6 @@ export async function GET(request: NextRequest) {
8380
}
8481

8582
if (dbChallenges.length === 0) {
86-
// Return a default challenge if no challenge found and no random challenges available
8783
const defaultChallenge = {
8884
id: 0,
8985
title: '🌱 Kurangi Sampah Plastik',
@@ -117,7 +113,6 @@ export async function GET(request: NextRequest) {
117113
});
118114
}
119115

120-
// Transform all challenges
121116
const transformedChallenges = dbChallenges
122117
.map((challenge: any) => transformChallenge(challenge))
123118
.filter((challenge): challenge is NonNullable<typeof challenge> => challenge !== null);

src/components/aksi/2-SelectActivityStep.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export default function SelectActivityStep({
6868
setCategories(categoriesData);
6969
});
7070

71-
// Set selectedGroup setelah data dimuat
7271
if (challengeFilter) {
7372
setSelectedGroup(challengeFilter);
7473
} else {
@@ -83,13 +82,11 @@ export default function SelectActivityStep({
8382
console.log('categories count:', categories.length);
8483
console.log('groups count:', groups.length);
8584

86-
// If challenge filter is active, prioritize challenge filtering
8785
if (challengeFilter && groups.length > 0) {
8886
const targetGroup = groups.find(g => g.id === challengeFilter);
8987
console.log('Target group:', targetGroup);
9088

9189
const challengeFiltered = categories.filter((cat) => {
92-
// Try both UUID and name matching
9390
const matchById = cat.group_category === challengeFilter;
9491
const matchByName = targetGroup && cat.group_category === targetGroup.name;
9592

@@ -107,7 +104,6 @@ export default function SelectActivityStep({
107104

108105
console.log('Challenge filtered result:', challengeFiltered.length, 'items');
109106

110-
// Apply search filter to challenge results
111107
const searchFiltered = challengeFiltered.filter((cat) => {
112108
if (!search) return true;
113109
const searchLower = search.toLowerCase();
@@ -119,14 +115,11 @@ export default function SelectActivityStep({
119115
return searchFiltered;
120116
}
121117

122-
// Normal filtering (non-challenge mode)
123118
const filtered = categories.filter((cat) => {
124-
// Search dalam nama dan deskripsi
125119
const searchLower = search.toLowerCase();
126120
const matchSearch = cat.name.toLowerCase().includes(searchLower) ||
127121
(cat.description && cat.description.toLowerCase().includes(searchLower));
128122

129-
// Filter berdasarkan grup
130123
let matchGroup = true;
131124
if (selectedGroup !== 'all') {
132125
const group = groups.find(g => g.id === selectedGroup);
@@ -137,7 +130,6 @@ export default function SelectActivityStep({
137130
return matchSearch && matchGroup;
138131
});
139132

140-
// Shuffle for 'all' group in normal mode
141133
if (selectedGroup === 'all') {
142134
const shuffled = [...filtered];
143135
for (let i = shuffled.length - 1; i > 0; i--) {
@@ -160,7 +152,6 @@ export default function SelectActivityStep({
160152
return (
161153
<div className="w-full max-w-4xl mx-auto flex flex-col">
162154

163-
{/* Show challenge info if in challenge mode */}
164155
{challengeFilter && (
165156
<div className="bg-yellowGold/10 border border-yellowGold/30 rounded-lg p-4 mb-4">
166157
<div className="flex items-center gap-2 mb-2">
@@ -196,7 +187,6 @@ export default function SelectActivityStep({
196187
)}
197188
</div>
198189

199-
{/* Group filters - disable in challenge mode */}
200190
{!challengeFilter && (
201191
<div className="flex gap-3 mb-4 overflow-x-auto pb-2 md:flex-wrap md:overflow-x-visible">
202192
<button
@@ -206,7 +196,7 @@ export default function SelectActivityStep({
206196
: 'bg-whiteMint text-greenDark border-gray-200 hover:border-tealLight hover:bg-mintPastel'
207197
}`}
208198
onClick={() => setSelectedGroup('all')}
209-
disabled={!!challengeFilter} // Convert to boolean using !!
199+
disabled={!!challengeFilter}
210200
>
211201
<IconRenderer iconName="layers" className="w-5 h-5" />
212202
Semua
@@ -302,7 +292,6 @@ export default function SelectActivityStep({
302292
</button>
303293
))}
304294

305-
{/* Info jumlah aktivitas */}
306295
{filteredCategories.length > 0 && (
307296
<div className="text-center text-gray-500 text-sm mt-4">
308297
Menampilkan {filteredCategories.length} aktivitas

src/components/homepage/AuthenticatedHomepage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const AuthenticatedHomepage: React.FC<AuthenticatedHomepageProps> = ({
253253
<div className="bg-white/20 border border-white/30 px-2 py-1 rounded-full flex items-center gap-1">
254254
<Clock className="w-3 h-3 text-white" />
255255
<span className="text-xs font-medium">
256-
{currentChallenge.hoursRemaining}j
256+
{currentChallenge.hoursRemaining} jam
257257
tersisa
258258
</span>
259259
</div>

0 commit comments

Comments
 (0)