Skip to content

Commit

Permalink
adds profile timeline and follows
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Beutel committed Dec 14, 2024
1 parent e315c4d commit b0d136c
Show file tree
Hide file tree
Showing 27 changed files with 635 additions and 36 deletions.
80 changes: 80 additions & 0 deletions db/migrations/1734196620_created_follows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models"
)

func init() {
m.Register(func(db dbx.Builder) error {
jsonData := `{
"id": "8obn1ukumze565i",
"created": "2024-12-14 17:17:00.381Z",
"updated": "2024-12-14 17:17:00.381Z",
"name": "follows",
"type": "base",
"system": false,
"schema": [
{
"system": false,
"id": "in1traur",
"name": "follower",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "_pb_users_auth_",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
},
{
"system": false,
"id": "wxwomfd5",
"name": "followee",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "_pb_users_auth_",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}
],
"indexes": [],
"listRule": "@request.auth.id = follower.id || @request.auth.id = followee.id",
"viewRule": "@request.auth.id = follower.id || @request.auth.id = followee.id",
"createRule": "@request.auth.id = follower.id",
"updateRule": "@request.auth.id = follower.id",
"deleteRule": "@request.auth.id = follower.id",
"options": {}
}`

collection := &models.Collection{}
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
return err
}

return daos.New(db).SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("8obn1ukumze565i")
if err != nil {
return err
}

return dao.DeleteCollection(collection)
})
}
74 changes: 74 additions & 0 deletions db/migrations/1734200418_created_follow_counts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models"
)

func init() {
m.Register(func(db dbx.Builder) error {
jsonData := `{
"id": "j6w72f0kb5ivd7x",
"created": "2024-12-14 18:20:18.920Z",
"updated": "2024-12-14 18:20:18.920Z",
"name": "follow_counts",
"type": "view",
"system": false,
"schema": [
{
"system": false,
"id": "w81n64il",
"name": "followers",
"type": "json",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 1
}
},
{
"system": false,
"id": "rfnejpto",
"name": "following",
"type": "json",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 1
}
}
],
"indexes": [],
"listRule": "",
"viewRule": "",
"createRule": null,
"updateRule": null,
"deleteRule": null,
"options": {
"query": "SELECT \n users.id,\n COALESCE(followers.count, 0) AS followers,\n COALESCE(following.count, 0) AS following\nFROM users\nLEFT JOIN (\n SELECT followee AS user_id, COUNT(*) AS count\n FROM follows\n GROUP BY followee\n) AS followers ON users.id = followers.user_id\nLEFT JOIN (\n SELECT follower AS user_id, COUNT(*) AS count\n FROM follows\n GROUP BY follower\n) AS following ON users.id = following.user_id;"
}
}`

collection := &models.Collection{}
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
return err
}

return daos.New(db).SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("j6w72f0kb5ivd7x")
if err != nil {
return err
}

return dao.DeleteCollection(collection)
})
}
4 changes: 2 additions & 2 deletions web/src/css/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
width: 32px;
height: 32px;
border-radius: 50%;
border: 6px solid #fff;
border-color: #fff transparent #fff transparent;
border: 6px solid rgba(var(--content));
border-color: rgba(var(--content)) transparent rgba(var(--content)) transparent;
animation: spinner 1.2s linear infinite;
}

Expand Down
7 changes: 4 additions & 3 deletions web/src/lib/components/base/button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
on:click
{type}
>
{#if !loading}
<div class:invisible={loading}>
{#if icon}
<i class="fa fa-{icon} mr-2"></i>
{/if}
<slot />
{:else}
<div class="spinner"></div>
</div>
{#if loading}
<div class="absolute aspect-square spinner"></div>
{/if}
</button>
3 changes: 1 addition & 2 deletions web/src/lib/components/profile/activity_card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
/>
<div>
<a class="underline" href="/profile/{user.id}"> {user.username} </a>
{activity.type === "trail" ? "planned" : "completed"}
a trail
{activity.type === "trail" ? $_("planned-a-trail") : $_("completed-a-trail")}
<p class="text-xs text-gray-500 mb-3">
{new Date(activity.date).toLocaleDateString(undefined, {
month: "long",
Expand Down
8 changes: 6 additions & 2 deletions web/src/lib/components/trail/trail_card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { pb } from "$lib/pocketbase";
export let trail: Trail;
export let fullWidth: boolean = false;
$: thumbnail = trail.photos.length
? getFileURL(trail, trail.photos[trail.thumbnail])
Expand All @@ -20,7 +21,9 @@
</script>

<div
class="trail-card relative rounded-2xl border border-input-border min-w-72 cursor-pointer"
class="trail-card relative rounded-2xl border border-input-border {fullWidth
? 'min-w-72'
: 'w-72'} cursor-pointer"
on:mouseenter
on:mouseleave
role="listitem"
Expand Down Expand Up @@ -65,7 +68,8 @@
{/if}
{#if trail.expand.author}
<p class="text-xs text-gray-500 mb-3">
{$_("by")} <img
{$_("by")}
<img
class="rounded-full w-5 aspect-square mx-1 inline"
src={getFileURL(
trail.expand.author,
Expand Down
4 changes: 2 additions & 2 deletions web/src/lib/components/trail/trail_list.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
page: 1,
totalPages: 1,
};
export let loading: boolean = false;
export let fullWidthCards: boolean = false;
const displayOptions: SelectItem[] = [
{ text: $_("card", { values: { n: 2 } }), value: "cards" },
Expand Down Expand Up @@ -180,7 +180,7 @@
data-sveltekit-preload-data="off"
>
{#if selectedDisplayOption === "cards"}
<TrailCard {trail}></TrailCard>
<TrailCard fullWidth={fullWidthCards} {trail}></TrailCard>
{:else}
<TrailListItem {trail}></TrailListItem>
{/if}
Expand Down
17 changes: 14 additions & 3 deletions web/src/lib/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"about": "Über",
"account-delete-confirm": "Du bist dabei, dein Konto zu löschen. Alle deine Routen werden ebenfalls gelöscht. Möchtest du fortfahren?",
"activity": "{n, plural, =1 {Aktivität} other {Aktivitäten}}",
"add-bio": "Bio hinzufügen",
"add-entry": "Eintrag hinzufügen",
"add-to-list": "Zu Liste hinzufügen",
"add-waypoint": "Wegpunkt hinzufügen",
Expand Down Expand Up @@ -39,10 +40,11 @@
"close": "Schließen",
"comment": "{n, plural, =1 {Kommentar} other {Kommentare}}",
"completed": "Abgeschlossen",
"completed-a-trail": "hat eine Route abgeschlossen",
"completion-status": "Abschlussstatus",
"confirm": "Bestätigen",
"confirm-deletion": "Löschen bestätigen",
"confirm-publish": "",
"confirm-publish": "Veröffentlichen bestätigen",
"confirm-share": "Teilen bestätigen",
"contribute": "Mitwirken",
"copy-link": "Link kopieren",
Expand Down Expand Up @@ -80,6 +82,9 @@
"elevation-gain": "Höhenunterschied (aufw.)",
"elevation-loss": "Höhenunterschied (abw.)",
"email": "Email",
"empty-activities": "{username} hat noch keine Aktivitäten",
"empty-bio": "{username} hat noch keine Biographie hinzugefügt",
"empty-lists": "{username} hat keine öffentlichen Listen",
"english": "Englisch",
"entry": "Eintrag",
"error-creating-user": "Fehler beim Erstellen des Nutzers",
Expand All @@ -96,13 +101,16 @@
"explore-some-trails": "Erkunden Sie einige Routen",
"export": "Exportieren",
"export-all-trails": "Alle Routen exportieren",
"favourite-sport": "",
"favourite-sport": "Lieblingssportart",
"features": "Features",
"file-format": "Dateiformat",
"file-too-big": "Datei {file} ist zu groß (max. {size})",
"filter-categories": "Kategorien filtern",
"filter-difficulty": "Schwierigkeit filtern",
"focus-map-on": "Karte fokussieren auf",
"follow": "Folgen",
"followers": "Folgen dir",
"following": "Du folgst",
"forgot-your-password": "Passwort vergessen?",
"french": "Französisch",
"german": "Deutsch",
Expand All @@ -124,13 +132,14 @@
"invalid-date": "Ungültiges Datum",
"invalid-username": "Ungültiger Nutzername",
"italian": "Italienisch",
"joined": "Beigetreten",
"language": "Sprache",
"latitude": "Breitengrad",
"license": "Lizenz",
"link-copied": "Link kopiert",
"list": "{n, plural, =1 {Liste} other {Listen}}",
"list-not-shared": "Mit niemandem geteilt",
"list-public-warning": "",
"list-public-warning": "Alle routen in dieser liste werden veröffentlicht.",
"list-saved-successfully": "Liste gespeichert",
"list-share-warning": "Durch das Teilen einer Liste werden automatisch alle darin enthaltenen Routen freigegeben.",
"list-share-warning-update": "Hinzugefügte Routen werden mit allen geteilt, die Zugriff auf diese Liste haben.",
Expand Down Expand Up @@ -179,6 +188,7 @@
"passwords-must-match": "Passwörter müssen übereinstimmen",
"photos": "Fotos",
"pick-a-trail": "Route auswählen",
"planned-a-trail": "hat eine Route geplant",
"polish": "Polnisch",
"portuguese": "Portugiesisch",
"print": "Drucken",
Expand Down Expand Up @@ -211,6 +221,7 @@
"slope": "Steigung",
"sort": "Sortieren",
"speed": "Geschwindigkeit",
"statistics": "Statistiken",
"stop-drawing": "Zeichnen beenden",
"summit-book": "Gipfelbuch",
"table": "Tabelle",
Expand Down
11 changes: 11 additions & 0 deletions web/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"about": "About",
"account-delete-confirm": "You are about to delete your account. All your trails will also be deleted. Do you want to proceed?",
"activity": "{n, plural, =1 {Activity} other {Activities}}",
"add-bio": "Add Bio",
"add-entry": "Add Entry",
"add-to-list": "Add to list",
"add-waypoint": "Add Waypoint",
Expand Down Expand Up @@ -39,6 +40,7 @@
"close": "Close",
"comment": "{n, plural, =1 {Comment} other {Comments}}",
"completed": "Completed",
"completed-a-trail": "completed a trail",
"completion-status": "Completion Status",
"confirm": "Confirm",
"confirm-deletion": "Confirm Deletion",
Expand Down Expand Up @@ -80,6 +82,9 @@
"elevation-gain": "Elevation Gain",
"elevation-loss": "Elevation Loss",
"email": "Email",
"empty-activities": "{username} has no activity yet",
"empty-bio": "{username} has not added a bio yet",
"empty-lists": "{username} has no public lists",
"english": "English",
"entry": "Entry",
"error-creating-user": "Error creating user",
Expand All @@ -103,6 +108,9 @@
"filter-categories": "Filter categories",
"filter-difficulty": "Filter difficulty",
"focus-map-on": "Focus map on",
"follow": "Follow",
"followers": "Followers",
"following": "Following",
"forgot-your-password": "Forgot your password?",
"french": "French",
"german": "German",
Expand All @@ -124,6 +132,7 @@
"invalid-date": "Invalid Date",
"invalid-username": "Invalid username",
"italian": "Italian",
"joined": "Joined",
"language": "Language",
"latitude": "Latitude",
"license": "License",
Expand Down Expand Up @@ -179,6 +188,7 @@
"passwords-must-match": "Passwords must match",
"photos": "Photos",
"pick-a-trail": "Pick a trail",
"planned-a-trail": "planned a trail",
"polish": "Polish",
"portuguese": "Portuguese",
"print": "Print",
Expand Down Expand Up @@ -211,6 +221,7 @@
"slope": "Slope",
"sort": "Sort",
"speed": "Speed",
"statistics": "Statistics",
"stop-drawing": "Stop drawing",
"summit-book": "Summit Book",
"table": "Table",
Expand Down
Loading

0 comments on commit b0d136c

Please sign in to comment.