Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .annotaterb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
:position: before
:position_in_additional_file_patterns: before
:position_in_class: before
:position_in_factory: before
:position_in_fixture: before
:position_in_routes: before
:position_in_serializer: before
:position_in_test: before
:classified_sort: true
:exclude_controllers: true
:exclude_factories: false
:exclude_fixtures: false
:exclude_helpers: true
:exclude_scaffolds: true
:exclude_serializers: false
:exclude_sti_subclasses: false
:exclude_tests: false
:force: false
:format_markdown: false
:format_rdoc: false
:format_yard: false
:frozen: false
:grouped_polymorphic: false
:ignore_model_sub_dir: false
:ignore_unknown_models: false
:include_version: false
:show_check_constraints: false
:show_complete_foreign_keys: false
:show_foreign_keys: true
:show_indexes: true
:show_indexes_include: false
:simple_indexes: false
:sort: false
:timestamp: false
:trace: false
:with_comment: true
:with_column_comments: true
:with_table_comments: true
:position_of_column_comment: :with_name
:active_admin: false
:command:
:debug: false
:hide_default_column_types: ''
:hide_limit_column_types: ''
:timestamp_columns:
- created_at
- updated_at
:ignore_columns:
:ignore_routes:
:models: true
:routes: false
:skip_on_db_migrate: false
:target_action: :do_annotations
:wrapper:
:wrapper_close:
:wrapper_open:
:classes_default_to_s: []
:additional_file_patterns: []
:model_dir:
- app/models
:require: []
:root_dir:
- ''
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ group :development, :test do
end

group :development do
gem 'annotate' # Annotate models with schema
gem 'annotaterb' # Annotate models with schema (Rails 8 compatible fork)
gem 'brakeman' # Static analysis security vulnerability scanner for Ruby on Rails applications
gem 'letter_opener' # Preview emails in the browser instead of sending them
gem 'web-console' # Rails console for the browser
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ GEM
uri (>= 0.13.1)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
annotate (2.6.5)
activerecord (>= 2.3.0)
rake (>= 0.8.7)
annotaterb (4.20.0)
activerecord (>= 6.0.0)
activesupport (>= 6.0.0)
ast (2.4.2)
autoprefixer-rails (10.4.16.0)
execjs (~> 2)
Expand Down Expand Up @@ -451,7 +451,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
annotate
annotaterb
autoprefixer-rails
bootsnap
bootstrap (~> 5.2)
Expand Down
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: bin/rails server -p 3000
ngrok: ngrok http 3000 --log=stdout
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ These instructions will get you a copy of the project up and running on your loc

Ensure that you have the following installed on your local machine:

* [Ruby](https://www.ruby-lang.org/en/documentation/installation/) - 3.1.2
* [Rails](https://guides.rubyonrails.org/v5.0/getting_started.html) - 7.0.6
* [Ruby](https://www.ruby-lang.org/en/documentation/installation/) - 3.4.4
* [Rails](https://guides.rubyonrails.org/v5.0/getting_started.html) - 8.0.3
* PostgreSQL

### Installation
Expand Down Expand Up @@ -62,6 +62,36 @@ rspec # run all tests
rspec spec/requests/users_spec.rb # run a specific test
```

### Development Server

**Option 1: Using Foreman (recommended for production-like environment)**

Start both Rails server and ngrok simultaneously:

```bash
bin/dev
```

This will start:
- Rails server on `http://localhost:3000`
- ngrok tunnel (URL will be shown in the logs)

**Option 2: Manual setup (recommended for debugging with binding.pry)**

Start Rails server and ngrok separately:

**Terminal 1 - Rails Server:**
```bash
rails s
```

**Terminal 2 - ngrok (for mobile testing):**
```bash
ngrok http 3000
```

The ngrok URL will be displayed in Terminal 2 under "Forwarding" (e.g., `https://abc123.ngrok-free.app`). Use this URL to test the app on your mobile device.

### Services

- Poetry Service: Fetches a random poem to display on the page.
Expand Down
18 changes: 4 additions & 14 deletions app/assets/stylesheets/components/_map.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
.rounded-map {
border-radius: 15px; /* Or use a SASS variable $border-radius if it's defined in your environment */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Example shadow, adjust as needed */
border-radius: $border-radius;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
margin: 5px auto;
padding: 10px; /* Example padding, adjust using $space-xs if needed */

/* Default to smaller size */
width: 340px !important;
height: 300px;

/* Larger devices */
@media (min-width: 768px) {
width: 100% !important;
height: 90vh;
}
width: 100%;
height: 600px;
}
3 changes: 2 additions & 1 deletion app/assets/stylesheets/components/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
}

.navbar .navbar-brand img {
width: 40px;
height: 50px;
width: auto;
}

.offcanvas {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_turbo_progress_bar.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.turbo-progress-bar {
background: linear-gradient(to right, $color-primary, $color-primary-rotate);
background: linear-gradient(to right, $soft-purple, $pink);
}
9 changes: 9 additions & 0 deletions app/assets/stylesheets/config/_reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@

html {
overflow-y: scroll;
overflow-x: hidden;
height: 100%;
height: 100dvh; /* Modern dynamic viewport height */
height: -webkit-fill-available; /* Fallback for older Safari */
background-color: $off-white;
}

body {
display: flex;
flex-direction: column;
min-height: 100%;
min-height: 100vh; /* Fallback for older browsers */
min-height: 100dvh; /* Modern dynamic viewport height */
min-height: -webkit-fill-available; /* Fallback for older Safari */
overflow-x: hidden;
width: 100%;

background-color: $color-background;
color: $color-text-body;
Expand Down
18 changes: 9 additions & 9 deletions app/controllers/friendships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ def index
def create
@friendship = current_user.friendships.build(friend_id: params[:friend_id])
flash[:notice] = if @friendship.save
'Friend request sent. 👻'
t('friendships.created')
else
'Unable to send friend request. 🤔'
t('friendships.create_failed')
end
redirect_to users_path
redirect_to friends_path
end

def update
flash[:notice] = if @friendship.update(accepted: true)
'Friend request accepted. 🫱🏻‍🫲🏾'
t('friendships.accepted')
else
'Unable to accept friend request. 🙈'
t('friendships.accept_failed')
end
redirect_to users_path
redirect_to friends_path
end

def destroy
@friendship.destroy
flash[:notice] = 'Friendship removed. 😭'
redirect_to users_path
flash[:notice] = t('friendships.destroyed')
redirect_to friends_path
end

private
Expand All @@ -41,7 +41,7 @@ def destroy
# which could otherwise happen via ID guessing (e.g. /friendships/42)
def set_friendship
@friendship = Friendship.where(id: params[:id])
.where('user_id = ? OR friend_id = ?', current_user.id, current_user.id)
.where('user_id = :user_id OR friend_id = :user_id', user_id: current_user.id)
.first
end
end
2 changes: 1 addition & 1 deletion app/controllers/happy_things_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def fetch_words_for_wordcloud
end

def fetch_visited_places
@visited_places_count = @visited_places_count = HappyThing.where(user_id: current_user.id).distinct.count(:place)
@visited_places_count = HappyThing.where(user_id: current_user.id).distinct.count(:place)
end

def fetch_label_count
Expand Down
31 changes: 24 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,45 @@ class UsersController < ApplicationController
helper FriendshipsHelper
include WordAggregator

attr_reader :user

def index
@users = fetch_users
end

def friends
@friends = fetch_users
@friends = current_user.friends
@pending_requests = current_user.pending_friends
@friend_requests = fetch_incoming_friend_requests
@users = fetch_users
end

def show
@user = User.find(params[:id])
@happy_count = happy_count(@user)
@words_for_wordcloud = words_for_wordcloud(@user)
@visited_places_count = visited_places_count(@user)
@markers = markers(@user)
@happy_count = happy_count(user)
@words_for_wordcloud = words_for_wordcloud(user)
@visited_places_count = visited_places_count(user)
@markers = markers(user)
end

def profile
fetch_happy_count
fetch_words_for_wordcloud
fetch_visited_places
fetch_label_count
@markers = current_user.happy_things.geocoded.map { |ht| { lat: ht.latitude, lng: ht.longitude } }
@markers = fetch_markers_for_map
end

private

def fetch_incoming_friend_requests
User.joins(:friendships).where(friendships:
{
friend_id: current_user.id,
accepted: false
})
end

def fetch_users
if params[:query].present?
User.search(params[:query]).all_except(current_user)
Expand Down Expand Up @@ -67,12 +80,16 @@ def fetch_words_for_wordcloud
end

def fetch_visited_places
@visited_places_count = @visited_places_count = HappyThing.where(user_id: current_user.id).distinct.count(:place)
@visited_places_count = current_user.happy_things.distinct.count(:place)
end

def fetch_label_count
return @label_counts = @happy_things.group(:category).count if @happy_things.present?

@label_counts = {}
end

def fetch_markers_for_map
current_user.happy_things.geocoded.pluck(:latitude, :longitude).map { |lat, lng| { lat:, lng: } }
end
end
20 changes: 16 additions & 4 deletions app/helpers/friendships_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

module FriendshipsHelper
def can_add_as_friend?(current_user, potential_friend)
return false if current_user.friends.include?(potential_friend)
!current_user.friends.include?(potential_friend) &&
!current_user.friendships.exists?(friend_id: potential_friend.id)
end

def filter_users_by_query(users, query)
return users if query.blank?

users.select { |user| matches_query?(user, query.downcase) }
end

sent_request = current_user.friendships.find_by(friend_id: potential_friend.id)
received_request = current_user.received_friend_requests.find_by(user_id: potential_friend.id)
private

!(sent_request || received_request)
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Check failure on line 17 in app/helpers/friendships_helper.rb

View workflow job for this annotation

GitHub Actions / lint

Lint/RedundantCopDisableDirective: Unnecessary disabling of `Metrics/CyclomaticComplexity`, `Metrics/PerceivedComplexity`.
def matches_query?(user, query_downcase)
[user.first_name, user.last_name, user.username, user.email]
.compact
.any? { |field| field.downcase.include?(query_downcase) }
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
end
14 changes: 12 additions & 2 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
# Table name: comments
#
# id :bigint not null, primary key
# user_id :bigint not null
# happy_thing_id :bigint not null
# content :text
# created_at :datetime not null
# updated_at :datetime not null
# happy_thing_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_comments_on_happy_thing_id (happy_thing_id)
# index_comments_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (happy_thing_id => happy_things.id)
# fk_rails_... (user_id => users.id)
#
class Comment < ApplicationRecord
belongs_to :user
Expand Down
Loading