|
@@ -10,7 +10,7 @@ import NewButton, { NewButtonType } from "@/_health/base/new_button";
|
|
|
import { MainColorType } from "@/context/themes/color";
|
|
import { MainColorType } from "@/context/themes/color";
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
|
|
-export default function Calendar(props: { year: number, month: number }) {
|
|
|
|
|
|
|
+export default function Calendar(props: { year: number, month: number,mode:string }) {
|
|
|
const weeks = ['日', '一', '二', '三', '四', '五', '六']
|
|
const weeks = ['日', '一', '二', '三', '四', '五', '六']
|
|
|
const indexBeginWeek = 0;
|
|
const indexBeginWeek = 0;
|
|
|
const [spaces, setSpaces] = useState<any>([])
|
|
const [spaces, setSpaces] = useState<any>([])
|
|
@@ -23,8 +23,16 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ console.log('------------------')
|
|
|
|
|
+ console.log(props.mode)
|
|
|
loadData()
|
|
loadData()
|
|
|
- }, [month])
|
|
|
|
|
|
|
+ }, [month,props.mode])
|
|
|
|
|
+
|
|
|
|
|
+ // useEffect(()=>{
|
|
|
|
|
+ // setYear(props.year)
|
|
|
|
|
+ // setMonth(props.month)
|
|
|
|
|
+ // // loadData(props.year,props.mo)
|
|
|
|
|
+ // },[props.year,props.month,props.mode])
|
|
|
|
|
|
|
|
function loadData() {
|
|
function loadData() {
|
|
|
|
|
|
|
@@ -62,7 +70,7 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
|
|
|
|
|
|
|
|
|
|
streaks({
|
|
streaks({
|
|
|
- window: health.mode,
|
|
|
|
|
|
|
+ window: props.mode,
|
|
|
month: year + (month + '').padStart(2, '0')
|
|
month: year + (month + '').padStart(2, '0')
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
const array = (res as any).streaks
|
|
const array = (res as any).streaks
|
|
@@ -178,7 +186,7 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
|
|
|
|
|
// return '#000'
|
|
// return '#000'
|
|
|
// }
|
|
// }
|
|
|
- return getThemeColor(health.mode) + '33'
|
|
|
|
|
|
|
+ return getThemeColor(props.mode) + '33'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function textColor(item) {
|
|
function textColor(item) {
|
|
@@ -192,7 +200,7 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
return '#ffffff'
|
|
return '#ffffff'
|
|
|
}
|
|
}
|
|
|
return '#000000'
|
|
return '#000000'
|
|
|
- // return getThemeColor(health.mode)
|
|
|
|
|
|
|
+ // return getThemeColor(props.mode)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function leftSpace(days) {
|
|
function leftSpace(days) {
|
|
@@ -207,9 +215,9 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getYearMonth(){
|
|
|
|
|
|
|
+ function getYearMonth() {
|
|
|
const date = new Date(year, month - 1);
|
|
const date = new Date(year, month - 1);
|
|
|
- if (global.language == 'en'){
|
|
|
|
|
|
|
+ if (global.language == 'en') {
|
|
|
return dayjs(date.getTime()).format('MMMM YYYY')
|
|
return dayjs(date.getTime()).format('MMMM YYYY')
|
|
|
}
|
|
}
|
|
|
return dayjs(date.getTime()).format('YYYY年MMM')
|
|
return dayjs(date.getTime()).format('YYYY年MMM')
|
|
@@ -254,12 +262,21 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
days.map((item, index) => {
|
|
days.map((item, index) => {
|
|
|
|
|
+ if (item.isToday && item.right) {
|
|
|
|
|
+ return <View key={index} className="calendar_item" style={{ width: rpxToPx(94), position: 'relative' }}>
|
|
|
|
|
+ <View className="full_right_today" style={{backgroundColor: getThemeColor(props.mode) + '33'}}/>
|
|
|
|
|
+ <View className="fullToday">
|
|
|
|
|
+ <View className="today3"/>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ <Text >{item.day}</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
return <View className={itemClass(item)} style={{ width: rpxToPx(94), backgroundColor: bgColor(item), position: 'relative' }} key={index}>
|
|
return <View className={itemClass(item)} style={{ width: rpxToPx(94), backgroundColor: bgColor(item), position: 'relative' }} key={index}>
|
|
|
{
|
|
{
|
|
|
!item.full && item.isToday && <View className="today2" />
|
|
!item.full && item.isToday && <View className="today2" />
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- item.full && item.isToday && <View className="fullToday" style={{ backgroundColor: getThemeColor(health.mode) + '33' }}>
|
|
|
|
|
|
|
+ item.full && item.isToday && <View className="fullToday" style={{ backgroundColor: getThemeColor(props.mode) + '33' }}>
|
|
|
<View className="today3" />
|
|
<View className="today3" />
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
@@ -276,7 +293,7 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function logTitle() {
|
|
function logTitle() {
|
|
|
- switch (health.mode) {
|
|
|
|
|
|
|
+ switch (props.mode) {
|
|
|
case 'FAST':
|
|
case 'FAST':
|
|
|
return t('health.log_fast_streak')
|
|
return t('health.log_fast_streak')
|
|
|
case 'EAT':
|
|
case 'EAT':
|
|
@@ -289,19 +306,66 @@ export default function Calendar(props: { year: number, month: number }) {
|
|
|
return ''
|
|
return ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function streakTitle() {
|
|
|
|
|
+ var year = parseInt((current.start_date + '').substring(0, 4))
|
|
|
|
|
+ var month = parseInt((current.start_date + '').substring(4, 6)) - 1
|
|
|
|
|
+ var date = parseInt((current.start_date + '').substring(6, 8))
|
|
|
|
|
+ var dt = new Date(year, month, date)
|
|
|
|
|
+ var format = global.language == 'en' ? 'MMM D' : 'M月D日'
|
|
|
|
|
+ return t('health.since_date', { date: dayjs(dt.getTime()).format(format) })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function todayExpire() {
|
|
|
|
|
+ if (!current.reset) return false
|
|
|
|
|
+ var date = new Date(current.reset)
|
|
|
|
|
+ if (date.getDate() == new Date().getDate()) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function streakDesc() {
|
|
|
|
|
+ var format = global.language == 'en' ? 'MMM D' : 'M月D日'
|
|
|
|
|
+ if (current.days == 0) {
|
|
|
|
|
+ if (current.prev_reset) {
|
|
|
|
|
+
|
|
|
|
|
+ return t('health.last_expire_date_time', {
|
|
|
|
|
+ date: dayjs(current.prev_reset).format(format),
|
|
|
|
|
+ time: dayjs(current.prev_reset).format('HH:mm'),
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ if (todayExpire()) {
|
|
|
|
|
+ return t('health.expire_date_time', {
|
|
|
|
|
+ date: dayjs(current.reset).format(format),
|
|
|
|
|
+ time: dayjs(current.reset).format('HH:mm'),
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return t('health.until_date_time', {
|
|
|
|
|
+ date: dayjs(current.reset).format(format),
|
|
|
|
|
+ time: dayjs(current.reset).format('HH:mm'),
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ''
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function currentContent() {
|
|
function currentContent() {
|
|
|
- return <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', height: rpxToPx(208) }}>
|
|
|
|
|
|
|
+ return <View style={{ display: 'flex', flexDirection: 'row', height: rpxToPx(208) }}>
|
|
|
{
|
|
{
|
|
|
- loaded && <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', height: rpxToPx(208) }}>
|
|
|
|
|
|
|
+ loaded && <View style={{ display: 'flex', flexDirection: 'row' }}>
|
|
|
<View className="streak_days" style={{
|
|
<View className="streak_days" style={{
|
|
|
- color: getThemeColor(health.mode),
|
|
|
|
|
|
|
+ color: getThemeColor(props.mode),
|
|
|
marginLeft: leftSpace(current ? current.days : 0),
|
|
marginLeft: leftSpace(current ? current.days : 0),
|
|
|
- marginRight: rpxToPx(36)
|
|
|
|
|
|
|
+ marginRight: rpxToPx(36),
|
|
|
|
|
+ marginTop: rpxToPx(24)
|
|
|
}}>{current ? current.days : '0'}</View>
|
|
}}>{current ? current.days : '0'}</View>
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column', }}>
|
|
|
|
|
- <View className="h44 bold" style={{ color: getThemeColor(health.mode) }}>{current.days == 1 ? t('health.day') : t('health.days')}</View>
|
|
|
|
|
- <View className="h24">{current.days == 0 ? logTitle() : 'Log your xxx daily to build a streak'}</View>
|
|
|
|
|
- <View className="h20" style={{ color: MainColorType.g02, marginTop: rpxToPx(12) }}>Log your xxx daily to build a streak</View>
|
|
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', marginTop: rpxToPx(36) }}>
|
|
|
|
|
+ <View className="h44 bold" style={{ color: getThemeColor(props.mode) }}>{current.days == 1 ? t('health.day') : t('health.days')}</View>
|
|
|
|
|
+ <View className="h24">{current.days == 0 ? logTitle() : streakTitle()}</View>
|
|
|
|
|
+ <View className="h20" style={{ color: todayExpire() ? MainColorType.error : MainColorType.g02, marginTop: rpxToPx(12) }}>{streakDesc()}</View>
|
|
|
</View>
|
|
</View>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|