Skip to content

Commit

Permalink
Fix post sharing link & Remove unused share count & Remove ts-path `@…
Browse files Browse the repository at this point in the history
…config` (#303)
  • Loading branch information
Samuel-Therrien-Beslogic authored Nov 26, 2024
1 parent 24c8754 commit c735c7b
Show file tree
Hide file tree
Showing 17 changed files with 6,943 additions and 6,936 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ def create_posts_for_site(site):
num_posts = random.randint(4, 8)
for _ in range(num_posts):
# Generate a random share_count between 0 and 10
share_count = random.randint(0, 10)
# share_count = random.randint(0, 10)

# Create a post for the site
post = Post.objects.create(
site=site,
body=f"{site.name} has planted {random.randint(100, 1000)} new trees today. "
+ "Let's continue to grow our forest!",
share_count=share_count,
# share_count=share_count,
)
# Change created_at date since it is auto-generated on create
# Generate a random created_at time within the last 2 months
Expand Down Expand Up @@ -536,7 +536,7 @@ def create_sites(self):
site=site1,
body="The season is officially started; "
+ "new plants are starting to grow and our volunteers are very dedicated!",
share_count=5,
# share_count=5,
)
post.media.add(*Asset.objects.filter(asset__contains="canopeum_post_img"))
create_posts_for_site(site1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1 on 2024-11-26 18:33

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("canopeum_backend", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="post",
name="share_count",
),
]
3 changes: 2 additions & 1 deletion canopeum_backend/canopeum_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ def delete(self, using=None, keep_parents=False):
class Post(models.Model):
site = models.ForeignKey(Site, models.CASCADE, blank=False, null=False)
body = models.TextField(blank=False, null=False)
share_count = models.IntegerField(default=0)
# Feature currently unused, maybe eventually we'll want to track social media shares
# share_count = models.IntegerField(default=0)
created_at = models.DateTimeField(auto_now_add=True, blank=False, null=False)
# TODO(NicolasDontigny): Add created by user?
# created_by = models.ForeignKey(User, models.DO_NOTHING, blank=True, null=True)
Expand Down
2 changes: 1 addition & 1 deletion canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ class Meta:
"created_at",
"body",
"like_count",
"share_count",
# "share_count",
"comment_count",
"has_liked",
"media",
Expand Down
6 changes: 5 additions & 1 deletion canopeum_backend/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def test_no_pending_migrations(self):
stderr=StringIO(),
)
except SystemExit:
raise AssertionError("Pending migrations:\n" + out.getvalue()) from None
raise AssertionError(
"Pending migrations:\n"
+ out.getvalue()
+ "\nPlease run `uv run manage.py makemigrations`"
) from None
3 changes: 1 addition & 2 deletions canopeum_frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
projectService: {
allowDefaultProject: ['*/*/*.js', '.eslintrc.cjs'],
allowDefaultProject: ['*/*/*.js', '.eslintrc.cjs', 'apiSchemaGenerator.js'],
},
// Still needed for plugins that haven't updated to typescript-eslint@8 yet
// Namely: eslint-plugin-sonarjs
Expand Down Expand Up @@ -55,7 +55,6 @@ module.exports = {
+ '|src/'
+ '|@assets'
+ '|@components'
+ '|@config'
+ '|@constants'
+ '|@hooks'
+ '|@models'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as url from 'node:url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const schemaUrl = 'http://127.0.0.1:8000/api/schema/'
const outputPath = path.join(__dirname, 'openapi.yaml')
const nswagPath = path.join(__dirname, '../../..', 'docs/canopeum.nswag')
const nswagPath = path.join(__dirname, '..', 'docs', 'canopeum.nswag')

const response = await fetch(schemaUrl)
if (!response.ok) {
Expand Down
8 changes: 4 additions & 4 deletions canopeum_frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions canopeum_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "cd .. && dprint check && cd canopeum_frontend && npm run eslint",
"lint:fix": "npm run eslint -- --fix && cd .. && dprint fmt",
"preview": "vite preview",
"generate-api-client": "node ./src/config/apiSchemaGenerator.js"
"generate-api-client": "node ./apiSchemaGenerator.js"
},
"// @mui/x-charts": "https://github.com/mui/mui-x/pull/14392/files#r1764019386",
"dependencies": {
Expand Down Expand Up @@ -47,7 +47,7 @@
"@types/react-transition-group": "^4.4.10",
"@vitejs/plugin-react": "^4.2.1",
"dprint": "^0.47.2",
"eslint-config-beslogic": "^3.1.1",
"eslint-config-beslogic": "^3.1.2",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next'

import { SnackbarContext } from '@components/context/SnackbarContext'
import MultipleSelectChip, { type SelectionItem } from '@components/inputs/MultipleSelectChip'
import { APP_CONFIG } from '@config/config'
import useApiClient from '@hooks/ApiClientHook'
import useErrorHandling from '@hooks/ErrorHandlingHook'
import { CreateUserInvitation } from '@services/api'
Expand Down Expand Up @@ -72,7 +71,7 @@ const AdminInvitationDialog = ({ open, handleClose }: Props) => {
})
const response = await getApiClient().userInvitationClient.create(createUserInvitation)

setInvitationLink(`${APP_CONFIG.appBaseUrl}/register?code=${response.code}`)
setInvitationLink(`${globalThis.location.host}register?code=${response.code}`)
} catch (error: unknown) {
const errorMessage = getErrorMessage(
error,
Expand Down
1 change: 0 additions & 1 deletion canopeum_frontend/src/components/social/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ const PostCard = ({ post, deletePost }: Props) => {
type='button'
>
<span className='material-symbols-outlined text-primary'>share</span>
<div>{post.shareCount}</div>
</button>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions canopeum_frontend/src/components/social/SharePostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'

import { SnackbarContext } from '@components/context/SnackbarContext'
import { APP_CONFIG } from '@config/config'
import { appRoutes } from '@constants/routes.constant'
import type { Post } from '@services/api'

Expand All @@ -20,7 +19,7 @@ const SharePostDialog = ({ onClose, open, post }: Props) => {
const [shareUrl, setShareUrl] = useState('')

useEffect(
() => setShareUrl(`${APP_CONFIG.appBaseUrl}${appRoutes.postDetail(post.id)}`),
() => setShareUrl(`${globalThis.location.host}${appRoutes.postDetail(post.id)}`),
[post],
)

Expand Down
3 changes: 0 additions & 3 deletions canopeum_frontend/src/config/config.ts

This file was deleted.

Loading

0 comments on commit c735c7b

Please sign in to comment.