Skip to content

Commit

Permalink
Merge pull request #458 from range-of-motion/create-page-in-spa-proto…
Browse files Browse the repository at this point in the history
…type-that-shows-activities

Create page in SPA prototype that shows activities
  • Loading branch information
range-of-motion authored Dec 9, 2023
2 parents 6e1b25a + 109b891 commit ce52f61
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
21 changes: 21 additions & 0 deletions app/Http/Controllers/Api/ActivitiesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\ActivityResource;
use App\Models\Activity;
use Illuminate\Http\Request;

class ActivitiesController extends Controller
{
public function __invoke(Request $request)
{
/** @var ApiKey $apiKey */
$apiKey = $request->get('apiKey');

$activities = Activity::ofSpace($apiKey->user->spaces()->first()->id)->get();

return ActivityResource::collection($activities);
}
}
22 changes: 22 additions & 0 deletions app/Http/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ActivityResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'user' => $this->user
? ['id' => $this->user->id, 'name' => $this->user->name]
: null,
'entity_id' => $this->entity_id,
'entity_type' => $this->entity_type,
'action' => $this->action,
'occurred_at' => $this->created_at,
];
}
}
5 changes: 5 additions & 0 deletions resources/assets/js/prototype/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Login from './screens/Login.vue';
import Dashboard from './screens/Dashboard.vue';
import TransactionsIndex from './screens/Transactions/Index.vue';
import TransactionsCreate from './screens/Transactions/Create.vue';
import Activities from './screens/Activities.vue';
import SettingsPreferences from './screens/Settings/Preferences.vue';

Vue.prototype.versionNumber = window.versionNumber;
Expand All @@ -30,6 +31,10 @@ const routes = [
path: '/prototype/transactions/create',
name: 'transactions.create',
component: TransactionsCreate,
}, {
path: '/prototype/activities',
name: 'activities',
component: Activities,
}, {
path: '/prototype/settings/preferences',
name: 'settings.preferences',
Expand Down
5 changes: 4 additions & 1 deletion resources/assets/js/prototype/components/Navigation.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ArrowRightLeft, Home, LogOut, PlusCircle, Settings2 } from 'lucide-vue';
import { ArrowRightLeft, Home, LogOut, PlusCircle, RotateCcw, Settings2 } from 'lucide-vue';
import { getCurrentInstance } from 'vue';
const router = getCurrentInstance().proxy.$router;
Expand Down Expand Up @@ -28,6 +28,9 @@ const logOut = () => {
<router-link class="flex py-1 px-3 text-gray-500 dark:text-gray-400 hover:text-black dark:hover:text-white" :to="{ name: 'transactions.create' }">
<PlusCircle :size="20" :strokeWidth="1.6" />
</router-link>
<router-link class="flex py-1 px-3 text-gray-500 dark:text-gray-400 hover:text-black dark:hover:text-white" :to="{ name: 'activities' }">
<RotateCcw :size="16" />
</router-link>
<router-link class="flex py-1 px-3 text-gray-500 dark:text-gray-400 hover:text-black dark:hover:text-white" :to="{ name: 'settings.preferences' }">
<Settings2 :size="16" />
</router-link>
Expand Down
42 changes: 42 additions & 0 deletions resources/assets/js/prototype/screens/Activities.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup>
import { ref } from 'vue';
import Navigation from '../components/Navigation.vue';
const activities = ref([]);
const fetchActivities = () => {
fetch('/api/activities', { headers: { 'api-key': localStorage.getItem('api_key') } })
.then(response => response.json())
.then(data => {
activities.value = data.sort((a, b) => new Date(b.occurred_at) - new Date(a.occurred_at));
});
};
fetchActivities();
</script>

<template>
<div>
<Navigation />
<div class="my-10 mx-auto max-w-3xl">
<div class="p-5 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg">
<div class="relative ml-2.5 space-y-5 border-l border-gray-300">
<div v-for="(activity, i) in activities" :key="i">
<div class="flex items-start">
<div class="absolute -left-2.5 w-5 h-5 bg-gray-100 border border-gray-300 ring-8 ring-white rounded-full"></div>
<div class="pl-5">
<div class="-mt-px text-sm">
<span>{{ activity.user ? activity.user.name : 'Budget' }} {{ activity.action.split('.')[1] }} {{ activity.action.split('.')[0] }} #{{ activity.entity_id }}</span>
</div>
<div class="mt-1 text-xs text-gray-500">{{ new Date(activity.occurred_at).toJSON().split('T')[0] }}</div>
</div>
</div>
</div>
<!-- Patch (yes, it's ugly) -->
<div class="absolute bottom-0 -left-2 w-4 h-4 bg-white"></div>
</div>
</div>
</div>
</div>
</template>
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\Api\ActivitiesController;
use App\Http\Controllers\Api\LogInController;
use App\Http\Controllers\Api\RecurringController;
use App\Http\Controllers\Api\SettingsController;
Expand All @@ -20,6 +21,8 @@
Route::resource('tags', TagController::class)
->only(['index']);

Route::get('/activities', ActivitiesController::class);

Route::resource('settings', SettingsController::class)
->only(['index', 'store']);
});

0 comments on commit ce52f61

Please sign in to comment.